Skip to content

Commit 81a2492

Browse files
committed
lint: translate RenamedOrRemovedLint
1 parent 249595b commit 81a2492

File tree

5 files changed

+69
-37
lines changed

5 files changed

+69
-37
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,15 @@ lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
158158
159159
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
160160
161+
lint_check_name_removed = lint `{$lint_name}` has been removed: {$reason}
162+
163+
lint_check_name_renamed = lint `{$lint_name}` has been renamed to `{$replace}`
164+
161165
lint_check_name_unknown = unknown lint: `{$lint_name}`
162166
.help = did you mean: `{$suggestion}`
163167
164168
lint_check_name_unknown_tool = unknown lint tool: `{$tool_name}`
165169
166-
lint_check_name_warning = {$msg}
167-
168170
lint_command_line_source = `forbid` lint level was set on command line
169171
170172
lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike
@@ -484,8 +486,11 @@ lint_redundant_semicolons =
484486
*[false] this semicolon
485487
}
486488
487-
lint_renamed_or_removed_lint = {$msg}
489+
lint_removed_lint = lint `{$name}` has been removed: {$reason}
490+
491+
lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
488492
.suggestion = use the new name
493+
.help = use the new name `{$replace}`
489494
490495
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
491496

compiler/rustc_lint/src/context.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use self::TargetLint::*;
1818

1919
use crate::errors::{
20-
CheckNameDeprecated, CheckNameUnknown, CheckNameUnknownTool, CheckNameWarning, RequestedLevel,
21-
UnsupportedGroup,
20+
CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown,
21+
CheckNameUnknownTool, RequestedLevel, UnsupportedGroup,
2222
};
2323
use crate::levels::LintLevelsBuilder;
2424
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
@@ -124,9 +124,10 @@ pub enum CheckLintNameResult<'a> {
124124
NoLint(Option<Symbol>),
125125
/// The lint refers to a tool that has not been registered.
126126
NoTool,
127-
/// The lint is either renamed or removed. This is the warning
128-
/// message, and an optional new name (`None` if removed).
129-
Warning(String, Option<String>),
127+
/// The lint has been renamed to a new name.
128+
Renamed(String),
129+
/// The lint has been removed due to the given reason.
130+
Removed(String),
130131
/// The lint is from a tool. If the Option is None, then either
131132
/// the lint does not exist in the tool or the code was not
132133
/// compiled with the tool and therefore the lint was never
@@ -344,9 +345,17 @@ impl LintStore {
344345
}
345346
let lint_name = lint_name.to_string();
346347
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
347-
CheckLintNameResult::Warning(msg, _) => {
348-
sess.emit_warning(CheckNameWarning {
349-
msg,
348+
CheckLintNameResult::Renamed(replace) => {
349+
sess.emit_warning(CheckNameRenamed {
350+
lint_name: lint_name.clone(),
351+
replace,
352+
sub: RequestedLevel { level, lint_name },
353+
});
354+
}
355+
CheckLintNameResult::Removed(reason) => {
356+
sess.emit_warning(CheckNameRemoved {
357+
lint_name: lint_name.clone(),
358+
reason,
350359
sub: RequestedLevel { level, lint_name },
351360
});
352361
}
@@ -445,14 +454,8 @@ impl LintStore {
445454
}
446455
}
447456
match self.by_name.get(&complete_name) {
448-
Some(Renamed(new_name, _)) => CheckLintNameResult::Warning(
449-
format!("lint `{complete_name}` has been renamed to `{new_name}`"),
450-
Some(new_name.to_owned()),
451-
),
452-
Some(Removed(reason)) => CheckLintNameResult::Warning(
453-
format!("lint `{complete_name}` has been removed: {reason}"),
454-
None,
455-
),
457+
Some(Renamed(new_name, _)) => CheckLintNameResult::Renamed(new_name.to_string()),
458+
Some(Removed(reason)) => CheckLintNameResult::Removed(reason.to_string()),
456459
None => match self.lint_groups.get(&*complete_name) {
457460
// If neither the lint, nor the lint group exists check if there is a `clippy::`
458461
// variant of this lint

compiler/rustc_lint/src/errors.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,19 @@ pub struct CheckNameUnknownTool {
134134
}
135135

136136
#[derive(Diagnostic)]
137-
#[diag(lint_check_name_warning)]
138-
pub struct CheckNameWarning {
139-
pub msg: String,
137+
#[diag(lint_check_name_renamed)]
138+
pub struct CheckNameRenamed {
139+
pub lint_name: String,
140+
pub replace: String,
141+
#[subdiagnostic]
142+
pub sub: RequestedLevel,
143+
}
144+
145+
#[derive(Diagnostic)]
146+
#[diag(lint_check_name_removed)]
147+
pub struct CheckNameRemoved {
148+
pub lint_name: String,
149+
pub reason: String,
140150
#[subdiagnostic]
141151
pub sub: RequestedLevel,
142152
}

compiler/rustc_lint/src/levels.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{
44
fluent_generated as fluent,
55
late::unerased_lint_store,
66
lints::{
7-
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint,
8-
RenamedOrRemovedLint, RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
7+
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint, RemovedLint,
8+
RenamedLint, RenamedLintSuggestion, UnknownLint, UnknownLintSuggestion,
99
},
1010
};
1111
use rustc_ast as ast;
@@ -915,18 +915,26 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
915915

916916
_ if !self.warn_about_weird_lints => {}
917917

918-
CheckLintNameResult::Warning(msg, renamed) => {
918+
CheckLintNameResult::Renamed(new_name) => {
919919
let suggestion =
920-
renamed.as_ref().map(|replace| RenamedOrRemovedLintSuggestion {
921-
suggestion: sp,
922-
replace: replace.as_str(),
923-
});
920+
RenamedLintSuggestion { suggestion: sp, replace: new_name.as_str() };
921+
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
922+
self.emit_spanned_lint(
923+
RENAMED_AND_REMOVED_LINTS,
924+
sp.into(),
925+
RenamedLint { name: name.as_str(), suggestion },
926+
);
927+
}
928+
929+
CheckLintNameResult::Removed(reason) => {
930+
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
924931
self.emit_spanned_lint(
925932
RENAMED_AND_REMOVED_LINTS,
926933
sp.into(),
927-
RenamedOrRemovedLint { msg, suggestion },
934+
RemovedLint { name: name.as_str(), reason: reason.as_str() },
928935
);
929936
}
937+
930938
CheckLintNameResult::NoLint(suggestion) => {
931939
let name = if let Some(tool_ident) = tool_ident {
932940
format!("{}::{}", tool_ident.name, name)
@@ -945,7 +953,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
945953
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
946954
// This happens outside of the match because the new lint should be applied even if
947955
// we don't warn about the name change.
948-
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
956+
if let CheckLintNameResult::Renamed(new_name) = lint_result {
949957
// Ignore any errors or warnings that happen because the new name is inaccurate
950958
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
951959
if let CheckLintNameResult::Ok(ids) =

compiler/rustc_lint/src/lints.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,23 +1012,29 @@ pub struct DeprecatedLintName<'a> {
10121012
pub replace: &'a str,
10131013
}
10141014

1015-
// FIXME: Non-translatable msg
10161015
#[derive(LintDiagnostic)]
1017-
#[diag(lint_renamed_or_removed_lint)]
1018-
pub struct RenamedOrRemovedLint<'a> {
1019-
pub msg: &'a str,
1016+
#[diag(lint_renamed_lint)]
1017+
pub struct RenamedLint<'a> {
1018+
pub name: &'a str,
10201019
#[subdiagnostic]
1021-
pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>,
1020+
pub suggestion: RenamedLintSuggestion<'a>,
10221021
}
10231022

10241023
#[derive(Subdiagnostic)]
10251024
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
1026-
pub struct RenamedOrRemovedLintSuggestion<'a> {
1025+
pub struct RenamedLintSuggestion<'a> {
10271026
#[primary_span]
10281027
pub suggestion: Span,
10291028
pub replace: &'a str,
10301029
}
10311030

1031+
#[derive(LintDiagnostic)]
1032+
#[diag(lint_removed_lint)]
1033+
pub struct RemovedLint<'a> {
1034+
pub name: &'a str,
1035+
pub reason: &'a str,
1036+
}
1037+
10321038
#[derive(LintDiagnostic)]
10331039
#[diag(lint_unknown_lint)]
10341040
pub struct UnknownLint {

0 commit comments

Comments
 (0)