@@ -766,7 +766,39 @@ pub trait LintContext: Sized {
766766 BuiltinLintDiagnostics :: NamedAsmLabel ( help) => {
767767 db. help ( & help) ;
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" ) ;
769- }
769+ } ,
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 {
776+ bug ! ( "it shouldn't be possible to have a diagnostic on a value whose name is not in values" ) ;
777+ } ;
778+ values. iter ( ) . map ( |& s| s) . collect ( )
779+ } else {
780+ 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" ) ;
782+ } ;
783+ names_valid. iter ( ) . map ( |s| * s) . collect ( )
784+ } ;
785+
786+ // Show the full list if all possible values for a given name, but don't do it
787+ // for names as the possibilities could be very long
788+ if value. is_some ( ) {
789+ // Sorting can take some time, so we only do it if required
790+ possibilities. sort ( ) ;
791+
792+ let possibilities = possibilities. iter ( ) . map ( Symbol :: as_str) . intersperse ( ", " ) . collect :: < String > ( ) ;
793+ db. note ( & format ! ( "possible values for `{name}` are: {possibilities}" ) ) ;
794+ }
795+
796+ // Suggest the most probable if we found one
797+ 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 ) ;
800+ }
801+ } ,
770802 }
771803 // Rewrap `db`, and pass control to the user.
772804 decorate ( LintDiagnosticBuilder :: new ( db) ) ;
0 commit comments