1+ #![ deny( rustc:: untranslatable_diagnostic) ]
2+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
13use crate :: context:: { CheckLintNameResult , LintStore } ;
24use crate :: late:: unerased_lint_store;
3- use crate :: lints:: DeprecatedLintName ;
5+ use crate :: lints:: {
6+ DeprecatedLintName , IgnoredUnlessCrateSpecified , OverruledAtributeLint , RenamedOrRemovedLint ,
7+ UnknownLint ,
8+ } ;
49use rustc_ast as ast;
510use rustc_ast_pretty:: pprust;
611use rustc_data_structures:: fx:: FxHashMap ;
7- use rustc_errors:: {
8- Applicability , DecorateLint , Diagnostic , DiagnosticBuilder , DiagnosticMessage , MultiSpan ,
9- } ;
12+ use rustc_errors:: { fluent, DecorateLint , DiagnosticBuilder , DiagnosticMessage , MultiSpan } ;
1013use rustc_hir as hir;
1114use rustc_hir:: intravisit:: { self , Visitor } ;
1215use rustc_hir:: HirId ;
@@ -18,6 +21,7 @@ use rustc_middle::lint::{
1821} ;
1922use rustc_middle:: ty:: query:: Providers ;
2023use rustc_middle:: ty:: { RegisteredTools , TyCtxt } ;
24+ use rustc_session:: lint:: builtin:: { RENAMED_AND_REMOVED_LINTS , UNKNOWN_LINTS , UNUSED_ATTRIBUTES } ;
2125use rustc_session:: lint:: {
2226 builtin:: { self , FORBIDDEN_LINT_GROUPS , SINGLE_USE_LIFETIMES , UNFULFILLED_LINT_EXPECTATIONS } ,
2327 Level , Lint , LintExpectationId , LintId ,
@@ -586,57 +590,32 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
586590 old_src,
587591 id_name
588592 ) ;
589-
590- let decorate_diag = |diag : & mut Diagnostic | {
591- diag. span_label ( src. span ( ) , "overruled by previous forbid" ) ;
592- match old_src {
593- LintLevelSource :: Default => {
594- diag. note ( & format ! (
595- "`forbid` lint level is the default for {}" ,
596- id. to_string( )
597- ) ) ;
598- }
599- LintLevelSource :: Node { span, reason, .. } => {
600- diag. span_label ( span, "`forbid` level set here" ) ;
601- if let Some ( rationale) = reason {
602- diag. note ( rationale. as_str ( ) ) ;
603- }
604- }
605- LintLevelSource :: CommandLine ( _, _) => {
606- diag. note ( "`forbid` lint level was set on command line" ) ;
607- }
593+ let sub = match old_src {
594+ LintLevelSource :: Default => {
595+ OverruledAttributeSub :: DefaultSource { id : id. to_string ( ) }
596+ }
597+ LintLevelSource :: Node { span, reason, .. } => {
598+ OverruledAttributeSub :: NodeSource { span, reason }
608599 }
600+ LintLevelSource :: CommandLine ( _, _) => OverruledAttributeSub :: CommandLineSource ,
609601 } ;
610602 if !fcw_warning {
611603 self . sess . emit_err ( OverruledAttribute {
612604 span : src. span ( ) ,
613605 overruled : src. span ( ) ,
614- lint_level : level. as_str ( ) . to_string ( ) ,
606+ lint_level : level. as_str ( ) ,
615607 lint_source : src. name ( ) ,
616- sub : match old_src {
617- LintLevelSource :: Default => {
618- OverruledAttributeSub :: DefaultSource { id : id. to_string ( ) }
619- }
620- LintLevelSource :: Node { span, reason, .. } => {
621- OverruledAttributeSub :: NodeSource { span, reason }
622- }
623- LintLevelSource :: CommandLine ( _, _) => {
624- OverruledAttributeSub :: CommandLineSource
625- }
626- } ,
608+ sub,
627609 } ) ;
628610 } else {
629- self . struct_lint (
611+ self . emit_spanned_lint (
630612 FORBIDDEN_LINT_GROUPS ,
631- Some ( src. span ( ) . into ( ) ) ,
632- format ! (
633- "{}({}) incompatible with previous forbid" ,
634- level. as_str( ) ,
635- src. name( ) ,
636- ) ,
637- |lint| {
638- decorate_diag ( lint) ;
639- lint
613+ src. span ( ) . into ( ) ,
614+ OverruledAtributeLint {
615+ overruled : src. span ( ) ,
616+ lint_level : level. as_str ( ) ,
617+ lint_source : src. name ( ) ,
618+ sub,
640619 } ,
641620 ) ;
642621 }
@@ -908,54 +887,22 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
908887 _ if !self . warn_about_weird_lints => { }
909888
910889 CheckLintNameResult :: Warning ( msg, renamed) => {
911- let lint = builtin:: RENAMED_AND_REMOVED_LINTS ;
912- let ( renamed_lint_level, src) = self . provider . get_lint_level ( lint, & sess) ;
913- struct_lint_level (
914- self . sess ,
915- lint,
916- renamed_lint_level,
917- src,
918- Some ( sp. into ( ) ) ,
919- msg,
920- |lint| {
921- if let Some ( new_name) = & renamed {
922- lint. span_suggestion (
923- sp,
924- "use the new name" ,
925- new_name,
926- Applicability :: MachineApplicable ,
927- ) ;
928- }
929- lint
930- } ,
890+ self . emit_spanned_lint (
891+ RENAMED_AND_REMOVED_LINTS ,
892+ sp. into ( ) ,
893+ RenamedOrRemovedLint { msg, suggestion : sp, renamed } ,
931894 ) ;
932895 }
933896 CheckLintNameResult :: NoLint ( suggestion) => {
934- let lint = builtin:: UNKNOWN_LINTS ;
935- let ( level, src) = self . provider . get_lint_level ( lint, self . sess ) ;
936897 let name = if let Some ( tool_ident) = tool_ident {
937898 format ! ( "{}::{}" , tool_ident. name, name)
938899 } else {
939900 name. to_string ( )
940901 } ;
941- struct_lint_level (
942- self . sess ,
943- lint,
944- level,
945- src,
946- Some ( sp. into ( ) ) ,
947- format ! ( "unknown lint: `{}`" , name) ,
948- |lint| {
949- if let Some ( suggestion) = suggestion {
950- lint. span_suggestion (
951- sp,
952- "did you mean" ,
953- suggestion,
954- Applicability :: MaybeIncorrect ,
955- ) ;
956- }
957- lint
958- } ,
902+ self . emit_spanned_lint (
903+ UNKNOWN_LINTS ,
904+ sp. into ( ) ,
905+ UnknownLint { name, suggestion : sp, replace : suggestion } ,
959906 ) ;
960907 }
961908 }
@@ -1001,20 +948,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
1001948 continue
1002949 } ;
1003950
1004- let lint = builtin:: UNUSED_ATTRIBUTES ;
1005- let ( lint_level, lint_src) = self . provider . get_lint_level ( lint, & self . sess ) ;
1006- struct_lint_level (
1007- self . sess ,
1008- lint,
1009- lint_level,
1010- lint_src,
1011- Some ( lint_attr_span. into ( ) ) ,
1012- format ! (
1013- "{}({}) is ignored unless specified at crate level" ,
1014- level. as_str( ) ,
1015- lint_attr_name
1016- ) ,
1017- |lint| lint,
951+ self . emit_spanned_lint (
952+ UNUSED_ATTRIBUTES ,
953+ lint_attr_span. into ( ) ,
954+ IgnoredUnlessCrateSpecified { level : level. as_str ( ) , name : lint_attr_name } ,
1018955 ) ;
1019956 // don't set a separate error for every lint in the group
1020957 break ;
@@ -1038,11 +975,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
1038975 level,
1039976 src,
1040977 Some ( span. into ( ) ) ,
1041- format ! ( "unknown lint: `{}`" , lint_id . lint . name_lower ( ) ) ,
978+ fluent :: lint_unknown_gated_lint ,
1042979 |lint| {
1043- lint. note (
1044- & format ! ( "the `{}` lint is unstable" , lint_id. lint. name_lower( ) , ) ,
1045- ) ;
980+ lint. set_arg ( "name" , lint_id. lint . name_lower ( ) ) ;
981+ lint. note ( fluent:: note) ;
1046982 add_feature_diagnostics ( lint, & self . sess . parse_sess , feature) ;
1047983 lint
1048984 } ,
0 commit comments