@@ -2,16 +2,16 @@ use rustc_ast::attr::AttributeExt;
22use rustc_ast_pretty:: pprust;
33use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
44use rustc_data_structures:: unord:: UnordSet ;
5- use rustc_errors:: { Diag , LintDiagnostic , MultiSpan , msg} ;
5+ use rustc_errors:: { Diag , Diagnostic , MultiSpan , msg} ;
66use rustc_feature:: { Features , GateIssue } ;
77use rustc_hir:: HirId ;
88use rustc_hir:: intravisit:: { self , Visitor } ;
99use rustc_index:: IndexVec ;
1010use rustc_middle:: bug;
1111use rustc_middle:: hir:: nested_filter;
1212use rustc_middle:: lint:: {
13- LevelAndSource , LintExpectation , LintLevelSource , ShallowLintLevelMap , lint_level ,
14- reveal_actual_level,
13+ LevelAndSource , LintExpectation , LintLevelSource , ShallowLintLevelMap , diag_lint_level ,
14+ lint_level , reveal_actual_level,
1515} ;
1616use rustc_middle:: query:: Providers ;
1717use rustc_middle:: ty:: { RegisteredTools , TyCtxt } ;
@@ -822,8 +822,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
822822 RenamedLintSuggestion :: WithSpan { suggestion : sp, replace } ;
823823 let name =
824824 tool_ident. map ( |tool| format ! ( "{tool}::{name}" ) ) . unwrap_or ( name) ;
825- let lint = RenamedLint { name : name. as_str ( ) , replace, suggestion } ;
826- self . emit_span_lint ( RENAMED_AND_REMOVED_LINTS , sp. into ( ) , lint) ;
825+ self . emit_span_lint (
826+ RENAMED_AND_REMOVED_LINTS ,
827+ sp. into ( ) ,
828+ RenamedLint { name : name. as_str ( ) , replace, suggestion } ,
829+ ) ;
827830 }
828831
829832 // If this lint was renamed, apply the new lint instead of ignoring the
@@ -844,8 +847,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
844847 if self . lint_added_lints {
845848 let name =
846849 tool_ident. map ( |tool| format ! ( "{tool}::{name}" ) ) . unwrap_or ( name) ;
847- let lint = RemovedLint { name : name. as_str ( ) , reason } ;
848- self . emit_span_lint ( RENAMED_AND_REMOVED_LINTS , sp. into ( ) , lint) ;
850+ self . emit_span_lint (
851+ RENAMED_AND_REMOVED_LINTS ,
852+ sp. into ( ) ,
853+ RemovedLint { name : name. as_str ( ) , reason } ,
854+ ) ;
849855 }
850856 continue ;
851857 }
@@ -861,8 +867,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
861867 from_rustc,
862868 }
863869 } ) ;
864- let lint = UnknownLint { name, suggestion } ;
865- self . emit_span_lint ( UNKNOWN_LINTS , sp. into ( ) , lint) ;
870+ self . emit_span_lint (
871+ UNKNOWN_LINTS ,
872+ sp. into ( ) ,
873+ UnknownLint { name, suggestion } ,
874+ ) ;
866875 }
867876 continue ;
868877 }
@@ -967,8 +976,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
967976
968977 /// Used to emit a lint-related diagnostic based on the current state of
969978 /// this lint context.
970- ///
971- /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
972979 #[ track_caller]
973980 pub ( crate ) fn opt_span_lint (
974981 & self ,
@@ -980,25 +987,34 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
980987 lint_level ( self . sess , lint, level, span, decorate)
981988 }
982989
990+ /// Used to emit a lint-related diagnostic based on the current state of
991+ /// this lint context.
992+ #[ track_caller]
993+ pub ( crate ) fn opt_span_diag_lint (
994+ & self ,
995+ lint : & ' static Lint ,
996+ span : Option < MultiSpan > ,
997+ decorator : impl for < ' a > Diagnostic < ' a , ( ) > ,
998+ ) {
999+ let level = self . lint_level ( lint) ;
1000+ diag_lint_level ( self . sess , lint, level, span, decorator)
1001+ }
1002+
9831003 #[ track_caller]
9841004 pub fn emit_span_lint (
9851005 & self ,
9861006 lint : & ' static Lint ,
9871007 span : MultiSpan ,
988- decorate : impl for < ' a > LintDiagnostic < ' a , ( ) > ,
1008+ decorator : impl for < ' a > Diagnostic < ' a , ( ) > ,
9891009 ) {
9901010 let level = self . lint_level ( lint) ;
991- lint_level ( self . sess , lint, level, Some ( span) , |lint| {
992- decorate. decorate_lint ( lint) ;
993- } ) ;
1011+ diag_lint_level ( self . sess , lint, level, Some ( span) , decorator) ;
9941012 }
9951013
9961014 #[ track_caller]
997- pub fn emit_lint ( & self , lint : & ' static Lint , decorate : impl for < ' a > LintDiagnostic < ' a , ( ) > ) {
1015+ pub fn emit_lint ( & self , lint : & ' static Lint , decorator : impl for < ' a > Diagnostic < ' a , ( ) > ) {
9981016 let level = self . lint_level ( lint) ;
999- lint_level ( self . sess , lint, level, None , |lint| {
1000- decorate. decorate_lint ( lint) ;
1001- } ) ;
1017+ diag_lint_level ( self . sess , lint, level, None , decorator) ;
10021018 }
10031019}
10041020
0 commit comments