migrate: levels.rs
This commit is contained in:
parent
ab66ea61cf
commit
80df25e160
4 changed files with 128 additions and 107 deletions
|
@ -20,6 +20,18 @@ lint_deprecated_lint_name =
|
||||||
lint name `{$name}` is deprecated and may not have an effect in the future.
|
lint name `{$name}` is deprecated and may not have an effect in the future.
|
||||||
.suggestion = change it to
|
.suggestion = change it to
|
||||||
|
|
||||||
|
lint_renamed_or_removed_lint_suggestion = use the new name
|
||||||
|
|
||||||
|
lint_unknown_lint =
|
||||||
|
unknown lint: `{$name}`
|
||||||
|
.suggestion = did you mean
|
||||||
|
|
||||||
|
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level
|
||||||
|
|
||||||
|
lint_unknown_gated_lint =
|
||||||
|
unknown lint: `{$name}`
|
||||||
|
.note = the `{$name}` lint is unstable
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -10,12 +10,12 @@ use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(lint_overruled_attribute, code = "E0453")]
|
#[diag(lint_overruled_attribute, code = "E0453")]
|
||||||
pub struct OverruledAttribute {
|
pub struct OverruledAttribute<'a> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[label]
|
#[label]
|
||||||
pub overruled: Span,
|
pub overruled: Span,
|
||||||
pub lint_level: String,
|
pub lint_level: &'a str,
|
||||||
pub lint_source: Symbol,
|
pub lint_source: Symbol,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub sub: OverruledAttributeSub,
|
pub sub: OverruledAttributeSub,
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
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 crate::lints::{
|
||||||
|
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAtributeLint, RenamedOrRemovedLint,
|
||||||
|
UnknownLint,
|
||||||
|
};
|
||||||
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::{
|
use rustc_errors::{fluent, DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||||
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;
|
||||||
|
@ -18,6 +21,7 @@ use rustc_middle::lint::{
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
||||||
|
use rustc_session::lint::builtin::{RENAMED_AND_REMOVED_LINTS, UNKNOWN_LINTS, UNUSED_ATTRIBUTES};
|
||||||
use rustc_session::lint::{
|
use rustc_session::lint::{
|
||||||
builtin::{self, FORBIDDEN_LINT_GROUPS, SINGLE_USE_LIFETIMES, UNFULFILLED_LINT_EXPECTATIONS},
|
builtin::{self, FORBIDDEN_LINT_GROUPS, SINGLE_USE_LIFETIMES, UNFULFILLED_LINT_EXPECTATIONS},
|
||||||
Level, Lint, LintExpectationId, LintId,
|
Level, Lint, LintExpectationId, LintId,
|
||||||
|
@ -586,57 +590,32 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
old_src,
|
old_src,
|
||||||
id_name
|
id_name
|
||||||
);
|
);
|
||||||
|
let sub = match old_src {
|
||||||
let decorate_diag = |diag: &mut Diagnostic| {
|
|
||||||
diag.span_label(src.span(), "overruled by previous forbid");
|
|
||||||
match old_src {
|
|
||||||
LintLevelSource::Default => {
|
|
||||||
diag.note(&format!(
|
|
||||||
"`forbid` lint level is the default for {}",
|
|
||||||
id.to_string()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
LintLevelSource::Node { span, reason, .. } => {
|
|
||||||
diag.span_label(span, "`forbid` level set here");
|
|
||||||
if let Some(rationale) = reason {
|
|
||||||
diag.note(rationale.as_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LintLevelSource::CommandLine(_, _) => {
|
|
||||||
diag.note("`forbid` lint level was set on command line");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if !fcw_warning {
|
|
||||||
self.sess.emit_err(OverruledAttribute {
|
|
||||||
span: src.span(),
|
|
||||||
overruled: src.span(),
|
|
||||||
lint_level: level.as_str().to_string(),
|
|
||||||
lint_source: src.name(),
|
|
||||||
sub: match old_src {
|
|
||||||
LintLevelSource::Default => {
|
LintLevelSource::Default => {
|
||||||
OverruledAttributeSub::DefaultSource { id: id.to_string() }
|
OverruledAttributeSub::DefaultSource { id: id.to_string() }
|
||||||
}
|
}
|
||||||
LintLevelSource::Node { span, reason, .. } => {
|
LintLevelSource::Node { span, reason, .. } => {
|
||||||
OverruledAttributeSub::NodeSource { span, reason }
|
OverruledAttributeSub::NodeSource { span, reason }
|
||||||
}
|
}
|
||||||
LintLevelSource::CommandLine(_, _) => {
|
LintLevelSource::CommandLine(_, _) => OverruledAttributeSub::CommandLineSource,
|
||||||
OverruledAttributeSub::CommandLineSource
|
};
|
||||||
}
|
if !fcw_warning {
|
||||||
},
|
self.sess.emit_err(OverruledAttribute {
|
||||||
|
span: src.span(),
|
||||||
|
overruled: src.span(),
|
||||||
|
lint_level: level.as_str(),
|
||||||
|
lint_source: src.name(),
|
||||||
|
sub,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.struct_lint(
|
self.emit_spanned_lint(
|
||||||
FORBIDDEN_LINT_GROUPS,
|
FORBIDDEN_LINT_GROUPS,
|
||||||
Some(src.span().into()),
|
src.span().into(),
|
||||||
format!(
|
OverruledAtributeLint {
|
||||||
"{}({}) incompatible with previous forbid",
|
overruled: src.span(),
|
||||||
level.as_str(),
|
lint_level: level.as_str(),
|
||||||
src.name(),
|
lint_source: src.name(),
|
||||||
),
|
sub,
|
||||||
|lint| {
|
|
||||||
decorate_diag(lint);
|
|
||||||
lint
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -908,54 +887,22 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
_ if !self.warn_about_weird_lints => {}
|
_ if !self.warn_about_weird_lints => {}
|
||||||
|
|
||||||
CheckLintNameResult::Warning(msg, renamed) => {
|
CheckLintNameResult::Warning(msg, renamed) => {
|
||||||
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
|
self.emit_spanned_lint(
|
||||||
let (renamed_lint_level, src) = self.provider.get_lint_level(lint, &sess);
|
RENAMED_AND_REMOVED_LINTS,
|
||||||
struct_lint_level(
|
sp.into(),
|
||||||
self.sess,
|
RenamedOrRemovedLint { msg, suggestion: sp, renamed },
|
||||||
lint,
|
|
||||||
renamed_lint_level,
|
|
||||||
src,
|
|
||||||
Some(sp.into()),
|
|
||||||
msg,
|
|
||||||
|lint| {
|
|
||||||
if let Some(new_name) = &renamed {
|
|
||||||
lint.span_suggestion(
|
|
||||||
sp,
|
|
||||||
"use the new name",
|
|
||||||
new_name,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
lint
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
CheckLintNameResult::NoLint(suggestion) => {
|
CheckLintNameResult::NoLint(suggestion) => {
|
||||||
let lint = builtin::UNKNOWN_LINTS;
|
|
||||||
let (level, src) = self.provider.get_lint_level(lint, self.sess);
|
|
||||||
let name = if let Some(tool_ident) = tool_ident {
|
let name = if let Some(tool_ident) = tool_ident {
|
||||||
format!("{}::{}", tool_ident.name, name)
|
format!("{}::{}", tool_ident.name, name)
|
||||||
} else {
|
} else {
|
||||||
name.to_string()
|
name.to_string()
|
||||||
};
|
};
|
||||||
struct_lint_level(
|
self.emit_spanned_lint(
|
||||||
self.sess,
|
UNKNOWN_LINTS,
|
||||||
lint,
|
sp.into(),
|
||||||
level,
|
UnknownLint { name, suggestion: sp, replace: suggestion },
|
||||||
src,
|
|
||||||
Some(sp.into()),
|
|
||||||
format!("unknown lint: `{}`", name),
|
|
||||||
|lint| {
|
|
||||||
if let Some(suggestion) = suggestion {
|
|
||||||
lint.span_suggestion(
|
|
||||||
sp,
|
|
||||||
"did you mean",
|
|
||||||
suggestion,
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
lint
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1001,20 +948,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
continue
|
continue
|
||||||
};
|
};
|
||||||
|
|
||||||
let lint = builtin::UNUSED_ATTRIBUTES;
|
self.emit_spanned_lint(
|
||||||
let (lint_level, lint_src) = self.provider.get_lint_level(lint, &self.sess);
|
UNUSED_ATTRIBUTES,
|
||||||
struct_lint_level(
|
lint_attr_span.into(),
|
||||||
self.sess,
|
IgnoredUnlessCrateSpecified { level: level.as_str(), name: lint_attr_name },
|
||||||
lint,
|
|
||||||
lint_level,
|
|
||||||
lint_src,
|
|
||||||
Some(lint_attr_span.into()),
|
|
||||||
format!(
|
|
||||||
"{}({}) is ignored unless specified at crate level",
|
|
||||||
level.as_str(),
|
|
||||||
lint_attr_name
|
|
||||||
),
|
|
||||||
|lint| lint,
|
|
||||||
);
|
);
|
||||||
// don't set a separate error for every lint in the group
|
// don't set a separate error for every lint in the group
|
||||||
break;
|
break;
|
||||||
|
@ -1038,11 +975,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
level,
|
level,
|
||||||
src,
|
src,
|
||||||
Some(span.into()),
|
Some(span.into()),
|
||||||
format!("unknown lint: `{}`", lint_id.lint.name_lower()),
|
fluent::lint_unknown_gated_lint,
|
||||||
|lint| {
|
|lint| {
|
||||||
lint.note(
|
lint.set_arg("name", lint_id.lint.name_lower());
|
||||||
&format!("the `{}` lint is unstable", lint_id.lint.name_lower(),),
|
lint.note(fluent::note);
|
||||||
);
|
|
||||||
add_feature_diagnostics(lint, &self.sess.parse_sess, feature);
|
add_feature_diagnostics(lint, &self.sess.parse_sess, feature);
|
||||||
lint
|
lint
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
|
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
|
||||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||||
|
|
||||||
use crate::LateContext;
|
use crate::{errors::OverruledAttributeSub, LateContext};
|
||||||
|
|
||||||
// array_into_iter.rs
|
// array_into_iter.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
|
@ -51,7 +51,18 @@ pub struct EnumIntrinsicsMemVariant<'a> {
|
||||||
|
|
||||||
// levels.rs
|
// levels.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint::deprecated_lint_name)]
|
#[diag(lint_overruled_attribute)]
|
||||||
|
pub struct OverruledAtributeLint<'a> {
|
||||||
|
#[label]
|
||||||
|
pub overruled: Span,
|
||||||
|
pub lint_level: &'a str,
|
||||||
|
pub lint_source: Symbol,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub sub: OverruledAttributeSub,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_deprecated_lint_name)]
|
||||||
pub struct DeprecatedLintName<'a> {
|
pub struct DeprecatedLintName<'a> {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
|
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
|
||||||
|
@ -59,6 +70,68 @@ pub struct DeprecatedLintName<'a> {
|
||||||
pub replace: &'a str,
|
pub replace: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RenamedOrRemovedLint<'a> {
|
||||||
|
pub msg: &'a str,
|
||||||
|
pub suggestion: Span,
|
||||||
|
pub renamed: &'a Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> DecorateLint<'a, ()> for RenamedOrRemovedLint<'_> {
|
||||||
|
fn decorate_lint<'b>(
|
||||||
|
self,
|
||||||
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
||||||
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
||||||
|
if let Some(new_name) = self.renamed {
|
||||||
|
diag.span_suggestion(
|
||||||
|
self.suggestion,
|
||||||
|
fluent::lint_renamed_or_removed_lint_suggestion,
|
||||||
|
new_name,
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
diag
|
||||||
|
}
|
||||||
|
|
||||||
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
||||||
|
rustc_errors::DiagnosticMessage::Str(self.msg.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct UnknownLint<'a> {
|
||||||
|
pub name: String,
|
||||||
|
pub suggestion: Span,
|
||||||
|
pub replace: &'a Option<Symbol>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> DecorateLint<'a, ()> for UnknownLint<'_> {
|
||||||
|
fn decorate_lint<'b>(
|
||||||
|
self,
|
||||||
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
||||||
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
||||||
|
diag.set_arg("name", self.name);
|
||||||
|
if let Some(replace) = self.replace {
|
||||||
|
diag.span_suggestion(
|
||||||
|
self.suggestion,
|
||||||
|
fluent::suggestion,
|
||||||
|
replace,
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
diag
|
||||||
|
}
|
||||||
|
|
||||||
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
||||||
|
fluent::lint_unknown_lint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_ignored_unless_crate_specified)]
|
||||||
|
pub struct IgnoredUnlessCrateSpecified<'a> {
|
||||||
|
pub level: &'a str,
|
||||||
|
pub name: Symbol,
|
||||||
|
}
|
||||||
|
|
||||||
// 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