lint: translate RenamedOrRemovedLint
This commit is contained in:
parent
249595b752
commit
81a24922e7
@ -158,13 +158,15 @@ lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
|
|||||||
|
|
||||||
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
|
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
|
||||||
|
|
||||||
|
lint_check_name_removed = lint `{$lint_name}` has been removed: {$reason}
|
||||||
|
|
||||||
|
lint_check_name_renamed = lint `{$lint_name}` has been renamed to `{$replace}`
|
||||||
|
|
||||||
lint_check_name_unknown = unknown lint: `{$lint_name}`
|
lint_check_name_unknown = unknown lint: `{$lint_name}`
|
||||||
.help = did you mean: `{$suggestion}`
|
.help = did you mean: `{$suggestion}`
|
||||||
|
|
||||||
lint_check_name_unknown_tool = unknown lint tool: `{$tool_name}`
|
lint_check_name_unknown_tool = unknown lint tool: `{$tool_name}`
|
||||||
|
|
||||||
lint_check_name_warning = {$msg}
|
|
||||||
|
|
||||||
lint_command_line_source = `forbid` lint level was set on command line
|
lint_command_line_source = `forbid` lint level was set on command line
|
||||||
|
|
||||||
lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike
|
lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike
|
||||||
@ -484,8 +486,11 @@ lint_redundant_semicolons =
|
|||||||
*[false] this semicolon
|
*[false] this semicolon
|
||||||
}
|
}
|
||||||
|
|
||||||
lint_renamed_or_removed_lint = {$msg}
|
lint_removed_lint = lint `{$name}` has been removed: {$reason}
|
||||||
|
|
||||||
|
lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
|
||||||
.suggestion = use the new name
|
.suggestion = use the new name
|
||||||
|
.help = use the new name `{$replace}`
|
||||||
|
|
||||||
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
|
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
use self::TargetLint::*;
|
use self::TargetLint::*;
|
||||||
|
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
CheckNameDeprecated, CheckNameUnknown, CheckNameUnknownTool, CheckNameWarning, RequestedLevel,
|
CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown,
|
||||||
UnsupportedGroup,
|
CheckNameUnknownTool, RequestedLevel, UnsupportedGroup,
|
||||||
};
|
};
|
||||||
use crate::levels::LintLevelsBuilder;
|
use crate::levels::LintLevelsBuilder;
|
||||||
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
|
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
|
||||||
@ -124,9 +124,10 @@ pub enum CheckLintNameResult<'a> {
|
|||||||
NoLint(Option<Symbol>),
|
NoLint(Option<Symbol>),
|
||||||
/// The lint refers to a tool that has not been registered.
|
/// The lint refers to a tool that has not been registered.
|
||||||
NoTool,
|
NoTool,
|
||||||
/// The lint is either renamed or removed. This is the warning
|
/// The lint has been renamed to a new name.
|
||||||
/// message, and an optional new name (`None` if removed).
|
Renamed(String),
|
||||||
Warning(String, Option<String>),
|
/// The lint has been removed due to the given reason.
|
||||||
|
Removed(String),
|
||||||
/// The lint is from a tool. If the Option is None, then either
|
/// The lint is from a tool. If the Option is None, then either
|
||||||
/// the lint does not exist in the tool or the code was not
|
/// the lint does not exist in the tool or the code was not
|
||||||
/// compiled with the tool and therefore the lint was never
|
/// compiled with the tool and therefore the lint was never
|
||||||
@ -344,9 +345,17 @@ impl LintStore {
|
|||||||
}
|
}
|
||||||
let lint_name = lint_name.to_string();
|
let lint_name = lint_name.to_string();
|
||||||
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
|
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
|
||||||
CheckLintNameResult::Warning(msg, _) => {
|
CheckLintNameResult::Renamed(replace) => {
|
||||||
sess.emit_warning(CheckNameWarning {
|
sess.emit_warning(CheckNameRenamed {
|
||||||
msg,
|
lint_name: lint_name.clone(),
|
||||||
|
replace,
|
||||||
|
sub: RequestedLevel { level, lint_name },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
CheckLintNameResult::Removed(reason) => {
|
||||||
|
sess.emit_warning(CheckNameRemoved {
|
||||||
|
lint_name: lint_name.clone(),
|
||||||
|
reason,
|
||||||
sub: RequestedLevel { level, lint_name },
|
sub: RequestedLevel { level, lint_name },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -445,14 +454,8 @@ impl LintStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
match self.by_name.get(&complete_name) {
|
match self.by_name.get(&complete_name) {
|
||||||
Some(Renamed(new_name, _)) => CheckLintNameResult::Warning(
|
Some(Renamed(new_name, _)) => CheckLintNameResult::Renamed(new_name.to_string()),
|
||||||
format!("lint `{complete_name}` has been renamed to `{new_name}`"),
|
Some(Removed(reason)) => CheckLintNameResult::Removed(reason.to_string()),
|
||||||
Some(new_name.to_owned()),
|
|
||||||
),
|
|
||||||
Some(Removed(reason)) => CheckLintNameResult::Warning(
|
|
||||||
format!("lint `{complete_name}` has been removed: {reason}"),
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
None => match self.lint_groups.get(&*complete_name) {
|
None => match self.lint_groups.get(&*complete_name) {
|
||||||
// If neither the lint, nor the lint group exists check if there is a `clippy::`
|
// If neither the lint, nor the lint group exists check if there is a `clippy::`
|
||||||
// variant of this lint
|
// variant of this lint
|
||||||
|
@ -134,9 +134,19 @@ pub struct CheckNameUnknownTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(lint_check_name_warning)]
|
#[diag(lint_check_name_renamed)]
|
||||||
pub struct CheckNameWarning {
|
pub struct CheckNameRenamed {
|
||||||
pub msg: String,
|
pub lint_name: String,
|
||||||
|
pub replace: String,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub sub: RequestedLevel,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(lint_check_name_removed)]
|
||||||
|
pub struct CheckNameRemoved {
|
||||||
|
pub lint_name: String,
|
||||||
|
pub reason: String,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub sub: RequestedLevel,
|
pub sub: RequestedLevel,
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ use crate::{
|
|||||||
fluent_generated as fluent,
|
fluent_generated as fluent,
|
||||||
late::unerased_lint_store,
|
late::unerased_lint_store,
|
||||||
lints::{
|
lints::{
|
||||||
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint,
|
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint, RemovedLint,
|
||||||
RenamedOrRemovedLint, RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
|
RenamedLint, RenamedLintSuggestion, UnknownLint, UnknownLintSuggestion,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
@ -915,18 +915,26 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||||||
|
|
||||||
_ if !self.warn_about_weird_lints => {}
|
_ if !self.warn_about_weird_lints => {}
|
||||||
|
|
||||||
CheckLintNameResult::Warning(msg, renamed) => {
|
CheckLintNameResult::Renamed(new_name) => {
|
||||||
let suggestion =
|
let suggestion =
|
||||||
renamed.as_ref().map(|replace| RenamedOrRemovedLintSuggestion {
|
RenamedLintSuggestion { suggestion: sp, replace: new_name.as_str() };
|
||||||
suggestion: sp,
|
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
|
||||||
replace: replace.as_str(),
|
|
||||||
});
|
|
||||||
self.emit_spanned_lint(
|
self.emit_spanned_lint(
|
||||||
RENAMED_AND_REMOVED_LINTS,
|
RENAMED_AND_REMOVED_LINTS,
|
||||||
sp.into(),
|
sp.into(),
|
||||||
RenamedOrRemovedLint { msg, suggestion },
|
RenamedLint { name: name.as_str(), suggestion },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckLintNameResult::Removed(reason) => {
|
||||||
|
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
|
||||||
|
self.emit_spanned_lint(
|
||||||
|
RENAMED_AND_REMOVED_LINTS,
|
||||||
|
sp.into(),
|
||||||
|
RemovedLint { name: name.as_str(), reason: reason.as_str() },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
CheckLintNameResult::NoLint(suggestion) => {
|
CheckLintNameResult::NoLint(suggestion) => {
|
||||||
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)
|
||||||
@ -945,7 +953,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||||||
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
|
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
|
||||||
// This happens outside of the match because the new lint should be applied even if
|
// This happens outside of the match because the new lint should be applied even if
|
||||||
// we don't warn about the name change.
|
// we don't warn about the name change.
|
||||||
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
|
if let CheckLintNameResult::Renamed(new_name) = lint_result {
|
||||||
// Ignore any errors or warnings that happen because the new name is inaccurate
|
// Ignore any errors or warnings that happen because the new name is inaccurate
|
||||||
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
|
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
|
||||||
if let CheckLintNameResult::Ok(ids) =
|
if let CheckLintNameResult::Ok(ids) =
|
||||||
|
@ -1012,23 +1012,29 @@ pub struct DeprecatedLintName<'a> {
|
|||||||
pub replace: &'a str,
|
pub replace: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Non-translatable msg
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_renamed_or_removed_lint)]
|
#[diag(lint_renamed_lint)]
|
||||||
pub struct RenamedOrRemovedLint<'a> {
|
pub struct RenamedLint<'a> {
|
||||||
pub msg: &'a str,
|
pub name: &'a str,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>,
|
pub suggestion: RenamedLintSuggestion<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
|
||||||
pub struct RenamedOrRemovedLintSuggestion<'a> {
|
pub struct RenamedLintSuggestion<'a> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub suggestion: Span,
|
pub suggestion: Span,
|
||||||
pub replace: &'a str,
|
pub replace: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_removed_lint)]
|
||||||
|
pub struct RemovedLint<'a> {
|
||||||
|
pub name: &'a str,
|
||||||
|
pub reason: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_unknown_lint)]
|
#[diag(lint_unknown_lint)]
|
||||||
pub struct UnknownLint {
|
pub struct UnknownLint {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user