1
+ #![ deny( rustc:: untranslatable_diagnostic) ]
2
+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
1
3
use crate :: context:: { CheckLintNameResult , LintStore } ;
2
4
use crate :: late:: unerased_lint_store;
3
- use crate :: lints:: DeprecatedLintName ;
5
+ use crate :: lints:: {
6
+ DeprecatedLintName , IgnoredUnlessCrateSpecified , OverruledAtributeLint , RenamedOrRemovedLint ,
7
+ UnknownLint ,
8
+ } ;
4
9
use rustc_ast as ast;
5
10
use rustc_ast_pretty:: pprust;
6
11
use 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 } ;
10
13
use rustc_hir as hir;
11
14
use rustc_hir:: intravisit:: { self , Visitor } ;
12
15
use rustc_hir:: HirId ;
@@ -18,6 +21,7 @@ use rustc_middle::lint::{
18
21
} ;
19
22
use rustc_middle:: ty:: query:: Providers ;
20
23
use rustc_middle:: ty:: { RegisteredTools , TyCtxt } ;
24
+ use rustc_session:: lint:: builtin:: { RENAMED_AND_REMOVED_LINTS , UNKNOWN_LINTS , UNUSED_ATTRIBUTES } ;
21
25
use rustc_session:: lint:: {
22
26
builtin:: { self , FORBIDDEN_LINT_GROUPS , SINGLE_USE_LIFETIMES , UNFULFILLED_LINT_EXPECTATIONS } ,
23
27
Level , Lint , LintExpectationId , LintId ,
@@ -586,57 +590,32 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
586
590
old_src,
587
591
id_name
588
592
) ;
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 }
608
599
}
600
+ LintLevelSource :: CommandLine ( _, _) => OverruledAttributeSub :: CommandLineSource ,
609
601
} ;
610
602
if !fcw_warning {
611
603
self . sess . emit_err ( OverruledAttribute {
612
604
span : src. span ( ) ,
613
605
overruled : src. span ( ) ,
614
- lint_level : level. as_str ( ) . to_string ( ) ,
606
+ lint_level : level. as_str ( ) ,
615
607
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,
627
609
} ) ;
628
610
} else {
629
- self . struct_lint (
611
+ self . emit_spanned_lint (
630
612
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,
640
619
} ,
641
620
) ;
642
621
}
@@ -908,54 +887,22 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
908
887
_ if !self . warn_about_weird_lints => { }
909
888
910
889
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 } ,
931
894
) ;
932
895
}
933
896
CheckLintNameResult :: NoLint ( suggestion) => {
934
- let lint = builtin:: UNKNOWN_LINTS ;
935
- let ( level, src) = self . provider . get_lint_level ( lint, self . sess ) ;
936
897
let name = if let Some ( tool_ident) = tool_ident {
937
898
format ! ( "{}::{}" , tool_ident. name, name)
938
899
} else {
939
900
name. to_string ( )
940
901
} ;
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 } ,
959
906
) ;
960
907
}
961
908
}
@@ -1001,20 +948,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
1001
948
continue
1002
949
} ;
1003
950
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 } ,
1018
955
) ;
1019
956
// don't set a separate error for every lint in the group
1020
957
break ;
@@ -1038,11 +975,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
1038
975
level,
1039
976
src,
1040
977
Some ( span. into ( ) ) ,
1041
- format ! ( "unknown lint: `{}`" , lint_id . lint . name_lower ( ) ) ,
978
+ fluent :: lint_unknown_gated_lint ,
1042
979
|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) ;
1046
982
add_feature_diagnostics ( lint, & self . sess . parse_sess , feature) ;
1047
983
lint
1048
984
} ,
0 commit comments