|
1 | 1 | use crate::context::{CheckLintNameResult, LintStore};
|
2 | 2 | use crate::late::unerased_lint_store;
|
| 3 | +use crate::lints::DeprecatedLintName; |
3 | 4 | use rustc_ast as ast;
|
4 | 5 | use rustc_ast_pretty::pprust;
|
5 | 6 | use rustc_data_structures::fx::FxHashMap;
|
6 |
| -use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage, MultiSpan}; |
| 7 | +use rustc_errors::{ |
| 8 | + Applicability, DecorateLint, Diagnostic, DiagnosticBuilder, DiagnosticMessage, MultiSpan, |
| 9 | +}; |
7 | 10 | use rustc_hir as hir;
|
8 | 11 | use rustc_hir::intravisit::{self, Visitor};
|
9 | 12 | use rustc_hir::HirId;
|
@@ -858,25 +861,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
858 | 861 | }
|
859 | 862 | Err((Some(ids), ref new_lint_name)) => {
|
860 | 863 | let lint = builtin::RENAMED_AND_REMOVED_LINTS;
|
861 |
| - let (lvl, src) = self.provider.get_lint_level(lint, &sess); |
862 |
| - struct_lint_level( |
863 |
| - self.sess, |
| 864 | + self.emit_spanned_lint( |
864 | 865 | lint,
|
865 |
| - lvl, |
866 |
| - src, |
867 |
| - Some(sp.into()), |
868 |
| - format!( |
869 |
| - "lint name `{}` is deprecated \ |
870 |
| - and may not have an effect in the future.", |
871 |
| - name |
872 |
| - ), |
873 |
| - |lint| { |
874 |
| - lint.span_suggestion( |
875 |
| - sp, |
876 |
| - "change it to", |
877 |
| - new_lint_name, |
878 |
| - Applicability::MachineApplicable, |
879 |
| - ) |
| 866 | + sp.into(), |
| 867 | + DeprecatedLintName { |
| 868 | + name, |
| 869 | + suggestion: sp, |
| 870 | + replace: &new_lint_name, |
880 | 871 | },
|
881 | 872 | );
|
882 | 873 |
|
@@ -1086,6 +1077,25 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
1086 | 1077 | let (level, src) = self.lint_level(lint);
|
1087 | 1078 | struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
|
1088 | 1079 | }
|
| 1080 | + |
| 1081 | + pub fn emit_spanned_lint( |
| 1082 | + &self, |
| 1083 | + lint: &'static Lint, |
| 1084 | + span: MultiSpan, |
| 1085 | + decorate: impl for<'a> DecorateLint<'a, ()>, |
| 1086 | + ) { |
| 1087 | + let (level, src) = self.lint_level(lint); |
| 1088 | + struct_lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| { |
| 1089 | + decorate.decorate_lint(lint) |
| 1090 | + }); |
| 1091 | + } |
| 1092 | + |
| 1093 | + pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) { |
| 1094 | + let (level, src) = self.lint_level(lint); |
| 1095 | + struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| { |
| 1096 | + decorate.decorate_lint(lint) |
| 1097 | + }); |
| 1098 | + } |
1089 | 1099 | }
|
1090 | 1100 |
|
1091 | 1101 | pub(crate) fn provide(providers: &mut Providers) {
|
|
0 commit comments