@@ -779,37 +779,43 @@ pub trait LintContext: Sized {
779
779
db. help ( & help) ;
780
780
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" ) ;
781
781
} ,
782
- BuiltinLintDiagnostics :: UnexpectedCfg ( span, name, value) => {
783
- let possibilities: Vec < Symbol > = if value. is_some ( ) {
784
- let Some ( values) = & sess. parse_sess . check_config . values_valid . get ( & name) else {
785
- bug ! ( "it shouldn't be possible to have a diagnostic on a value whose name is not in values" ) ;
786
- } ;
787
- values. iter ( ) . map ( |& s| s) . collect ( )
788
- } else {
789
- let Some ( names_valid) = & sess. parse_sess . check_config . names_valid else {
790
- bug ! ( "it shouldn't be possible to have a diagnostic on a name if name checking is not enabled" ) ;
791
- } ;
792
- names_valid. iter ( ) . map ( |s| * s) . collect ( )
782
+ BuiltinLintDiagnostics :: UnexpectedCfg ( ( name, name_span) , None ) => {
783
+ let Some ( names_valid) = & sess. parse_sess . check_config . names_valid else {
784
+ bug ! ( "it shouldn't be possible to have a diagnostic on a name if name checking is not enabled" ) ;
785
+ } ;
786
+ let possibilities: Vec < Symbol > = names_valid. iter ( ) . map ( |s| * s) . collect ( ) ;
787
+
788
+ // Suggest the most probable if we found one
789
+ if let Some ( best_match) = find_best_match_for_name ( & possibilities, name, None ) {
790
+ db. span_suggestion ( name_span, "did you mean" , format ! ( "{best_match}" ) , Applicability :: MaybeIncorrect ) ;
791
+ }
792
+ } ,
793
+ BuiltinLintDiagnostics :: UnexpectedCfg ( ( name, name_span) , Some ( ( value, value_span) ) ) => {
794
+ let Some ( values) = & sess. parse_sess . check_config . values_valid . get ( & name) else {
795
+ bug ! ( "it shouldn't be possible to have a diagnostic on a value whose name is not in values" ) ;
793
796
} ;
797
+ let possibilities: Vec < Symbol > = values. iter ( ) . map ( |& s| s) . collect ( ) ;
794
798
795
799
// Show the full list if all possible values for a given name, but don't do it
796
800
// for names as the possibilities could be very long
797
- if value . is_some ( ) {
798
- if !possibilities . is_empty ( ) {
801
+ if !possibilities . is_empty ( ) {
802
+ {
799
803
let mut possibilities = possibilities. iter ( ) . map ( Symbol :: as_str) . collect :: < Vec < _ > > ( ) ;
800
804
possibilities. sort ( ) ;
801
805
802
806
let possibilities = possibilities. join ( ", " ) ;
803
807
db. note ( & format ! ( "expected values for `{name}` are: {possibilities}" ) ) ;
804
- } else {
805
- db. note ( & format ! ( "no expected value for `{name}`" ) ) ;
806
808
}
807
- }
808
809
809
- // Suggest the most probable if we found one
810
- if let Some ( best_match) = find_best_match_for_name ( & possibilities, value. unwrap_or ( name) , None ) {
811
- let punctuation = if value. is_some ( ) { "\" " } else { "" } ;
812
- db. span_suggestion ( span, "did you mean" , format ! ( "{punctuation}{best_match}{punctuation}" ) , Applicability :: MaybeIncorrect ) ;
810
+ // Suggest the most probable if we found one
811
+ if let Some ( best_match) = find_best_match_for_name ( & possibilities, value, None ) {
812
+ db. span_suggestion ( value_span, "did you mean" , format ! ( "\" {best_match}\" " ) , Applicability :: MaybeIncorrect ) ;
813
+ }
814
+ } else {
815
+ db. note ( & format ! ( "no expected value for `{name}`" ) ) ;
816
+ if name != sym:: feature {
817
+ db. span_suggestion ( name_span. shrink_to_hi ( ) . to ( value_span) , "remove the value" , String :: new ( ) , Applicability :: MaybeIncorrect ) ;
818
+ }
813
819
}
814
820
} ,
815
821
}
0 commit comments