@@ -768,35 +768,36 @@ pub trait LintContext: Sized {
768
768
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" ) ;
769
769
} ,
770
770
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 {
776
773
bug ! ( "it shouldn't be possible to have a diagnostic on a value whose name is not in values" ) ;
777
774
} ;
778
775
values. iter ( ) . map ( |& s| s) . collect ( )
779
776
} else {
780
777
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 " ) ;
782
779
} ;
783
780
names_valid. iter ( ) . map ( |s| * s) . collect ( )
784
781
} ;
785
782
786
783
// Show the full list if all possible values for a given name, but don't do it
787
784
// for names as the possibilities could be very long
788
785
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 ( ) ;
791
789
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
+ }
794
795
}
795
796
796
797
// Suggest the most probable if we found one
797
798
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 ) ;
800
801
}
801
802
} ,
802
803
}
0 commit comments