@@ -768,35 +768,36 @@ pub trait LintContext: Sized {
768768 db. note ( "see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information" ) ;
769769 } ,
770770 BuiltinLintDiagnostics :: UnexpectedCfg ( span, name, value) => {
771- let mut possibilities: Vec < Symbol > = if value. is_some ( ) {
772- let Some ( values_valid) = & sess. parse_sess . check_config . values_valid else {
773- bug ! ( "it shouldn't be possible to have a diagnostic on a value if values checking is not enable" ) ;
774- } ;
775- let Some ( values) = values_valid. get ( & name) else {
771+ let possibilities: Vec < Symbol > = if value. is_some ( ) {
772+ let Some ( values) = & sess. parse_sess . check_config . values_valid . get ( & name) else {
776773 bug ! ( "it shouldn't be possible to have a diagnostic on a value whose name is not in values" ) ;
777774 } ;
778775 values. iter ( ) . map ( |& s| s) . collect ( )
779776 } else {
780777 let Some ( names_valid) = & sess. parse_sess . check_config . names_valid else {
781- bug ! ( "it shouldn't be possible to have a diagnostic on a value if values checking is not enable " ) ;
778+ bug ! ( "it shouldn't be possible to have a diagnostic on a name if name checking is not enabled " ) ;
782779 } ;
783780 names_valid. iter ( ) . map ( |s| * s) . collect ( )
784781 } ;
785782
786783 // Show the full list if all possible values for a given name, but don't do it
787784 // for names as the possibilities could be very long
788785 if value. is_some ( ) {
789- // Sorting can take some time, so we only do it if required
790- possibilities. sort ( ) ;
786+ if !possibilities. is_empty ( ) {
787+ let mut possibilities = possibilities. iter ( ) . map ( Symbol :: as_str) . collect :: < Vec < _ > > ( ) ;
788+ possibilities. sort ( ) ;
791789
792- let possibilities = possibilities. iter ( ) . map ( Symbol :: as_str) . intersperse ( ", " ) . collect :: < String > ( ) ;
793- db. note ( & format ! ( "possible values for `{name}` are: {possibilities}" ) ) ;
790+ let possibilities = possibilities. join ( ", " ) ;
791+ db. note ( & format ! ( "expected values for `{name}` are: {possibilities}" ) ) ;
792+ } else {
793+ db. note ( & format ! ( "no expected value for `{name}`" ) ) ;
794+ }
794795 }
795796
796797 // Suggest the most probable if we found one
797798 if let Some ( best_match) = find_best_match_for_name ( & possibilities, value. unwrap_or ( name) , None ) {
798- let ponctuation = if value. is_some ( ) { "\" " } else { "" } ;
799- db. span_suggestion ( span, "did you mean" , format ! ( "{ponctuation }{best_match}{ponctuation }" ) , Applicability :: MaybeIncorrect ) ;
799+ let punctuation = if value. is_some ( ) { "\" " } else { "" } ;
800+ db. span_suggestion ( span, "did you mean" , format ! ( "{punctuation }{best_match}{punctuation }" ) , Applicability :: MaybeIncorrect ) ;
800801 }
801802 } ,
802803 }
0 commit comments