add: emit{,_spanned}_lint
for LintLevelsBuilder
add: `emit_spanned_lint` and `emit_lint` for `LintLevelsBuilder` migrate: `DeprecatedLintName`
This commit is contained in:
parent
f9289c35fb
commit
ab66ea61cf
3 changed files with 43 additions and 19 deletions
|
@ -16,6 +16,10 @@ lint_enum_intrinsics_mem_variant =
|
||||||
lint_expectation = this lint expectation is unfulfilled
|
lint_expectation = this lint expectation is unfulfilled
|
||||||
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
|
||||||
|
|
||||||
|
lint_deprecated_lint_name =
|
||||||
|
lint name `{$name}` is deprecated and may not have an effect in the future.
|
||||||
|
.suggestion = change it to
|
||||||
|
|
||||||
lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
|
lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
|
||||||
.label = this {$label} contains {$count ->
|
.label = this {$label} contains {$count ->
|
||||||
[one] an invisible
|
[one] an invisible
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
use crate::context::{CheckLintNameResult, LintStore};
|
use crate::context::{CheckLintNameResult, LintStore};
|
||||||
use crate::late::unerased_lint_store;
|
use crate::late::unerased_lint_store;
|
||||||
|
use crate::lints::DeprecatedLintName;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
use rustc_errors::{
|
||||||
|
Applicability, DecorateLint, Diagnostic, DiagnosticBuilder, DiagnosticMessage, MultiSpan,
|
||||||
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
|
@ -858,25 +861,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
}
|
}
|
||||||
Err((Some(ids), ref new_lint_name)) => {
|
Err((Some(ids), ref new_lint_name)) => {
|
||||||
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
|
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
|
||||||
let (lvl, src) = self.provider.get_lint_level(lint, &sess);
|
self.emit_spanned_lint(
|
||||||
struct_lint_level(
|
|
||||||
self.sess,
|
|
||||||
lint,
|
lint,
|
||||||
lvl,
|
sp.into(),
|
||||||
src,
|
DeprecatedLintName {
|
||||||
Some(sp.into()),
|
name,
|
||||||
format!(
|
suggestion: sp,
|
||||||
"lint name `{}` is deprecated \
|
replace: &new_lint_name,
|
||||||
and may not have an effect in the future.",
|
|
||||||
name
|
|
||||||
),
|
|
||||||
|lint| {
|
|
||||||
lint.span_suggestion(
|
|
||||||
sp,
|
|
||||||
"change it to",
|
|
||||||
new_lint_name,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1086,6 +1077,25 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
let (level, src) = self.lint_level(lint);
|
let (level, src) = self.lint_level(lint);
|
||||||
struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
|
struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn emit_spanned_lint(
|
||||||
|
&self,
|
||||||
|
lint: &'static Lint,
|
||||||
|
span: MultiSpan,
|
||||||
|
decorate: impl for<'a> DecorateLint<'a, ()>,
|
||||||
|
) {
|
||||||
|
let (level, src) = self.lint_level(lint);
|
||||||
|
struct_lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| {
|
||||||
|
decorate.decorate_lint(lint)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
|
||||||
|
let (level, src) = self.lint_level(lint);
|
||||||
|
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {
|
||||||
|
decorate.decorate_lint(lint)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn provide(providers: &mut Providers) {
|
pub(crate) fn provide(providers: &mut Providers) {
|
||||||
|
|
|
@ -49,6 +49,16 @@ pub struct EnumIntrinsicsMemVariant<'a> {
|
||||||
pub ty_param: Ty<'a>,
|
pub ty_param: Ty<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// levels.rs
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint::deprecated_lint_name)]
|
||||||
|
pub struct DeprecatedLintName<'a> {
|
||||||
|
pub name: String,
|
||||||
|
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
|
||||||
|
pub suggestion: Span,
|
||||||
|
pub replace: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
// methods.rs
|
// methods.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_cstring_ptr)]
|
#[diag(lint_cstring_ptr)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue