Skip to content

Commit 6808802

Browse files
author
Joshua Nelson
authored
Rollup merge of #82620 - jyn514:apply-renamed-lints, r=Manishearth
Apply lint restrictions from renamed lints Previously, if you denied the old name of a renamed lint, it would warn about using the new name, but otherwise do nothing. Now, it will behave the same as if you'd used the new name. Fixes #82615. r? `@ehuss`
2 parents efb9ee2 + df156c1 commit 6808802

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

compiler/rustc_lint/src/levels.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,18 @@ impl<'s> LintLevelsBuilder<'s> {
321321
None
322322
};
323323
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
324-
match store.check_lint_name(&name.as_str(), tool_name) {
324+
let lint_result = store.check_lint_name(&name.as_str(), tool_name);
325+
match &lint_result {
325326
CheckLintNameResult::Ok(ids) => {
326327
let src = LintLevelSource::Node(name, li.span(), reason);
327-
for &id in ids {
328+
for &id in *ids {
328329
self.check_gated_lint(id, attr.span);
329330
self.insert_spec(&mut specs, id, (level, src));
330331
}
331332
}
332333

333334
CheckLintNameResult::Tool(result) => {
334-
match result {
335+
match *result {
335336
Ok(ids) => {
336337
let complete_name = &format!("{}::{}", tool_name.unwrap(), name);
337338
let src = LintLevelSource::Node(
@@ -343,7 +344,7 @@ impl<'s> LintLevelsBuilder<'s> {
343344
self.insert_spec(&mut specs, *id, (level, src));
344345
}
345346
}
346-
Err((Some(ids), new_lint_name)) => {
347+
Err((Some(ids), ref new_lint_name)) => {
347348
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
348349
let (lvl, src) =
349350
self.sets.get_lint_level(lint, self.cur, Some(&specs), &sess);
@@ -392,21 +393,21 @@ impl<'s> LintLevelsBuilder<'s> {
392393

393394
CheckLintNameResult::Warning(msg, renamed) => {
394395
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
395-
let (level, src) =
396+
let (renamed_lint_level, src) =
396397
self.sets.get_lint_level(lint, self.cur, Some(&specs), &sess);
397398
struct_lint_level(
398399
self.sess,
399400
lint,
400-
level,
401+
renamed_lint_level,
401402
src,
402403
Some(li.span().into()),
403404
|lint| {
404405
let mut err = lint.build(&msg);
405-
if let Some(new_name) = renamed {
406+
if let Some(new_name) = &renamed {
406407
err.span_suggestion(
407408
li.span(),
408409
"use the new name",
409-
new_name,
410+
new_name.to_string(),
410411
Applicability::MachineApplicable,
411412
);
412413
}
@@ -444,6 +445,22 @@ impl<'s> LintLevelsBuilder<'s> {
444445
);
445446
}
446447
}
448+
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
449+
// This happens outside of the match because the new lint should be applied even if
450+
// we don't warn about the name change.
451+
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
452+
// Ignore any errors or warnings that happen because the new name is inaccurate
453+
if let CheckLintNameResult::Ok(ids) =
454+
store.check_lint_name(&new_name, tool_name)
455+
{
456+
let src =
457+
LintLevelSource::Node(Symbol::intern(&new_name), li.span(), reason);
458+
for &id in ids {
459+
self.check_gated_lint(id, attr.span);
460+
self.insert_spec(&mut specs, id, (level, src));
461+
}
462+
}
463+
}
447464
}
448465
}
449466

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: --crate-type lib
2+
#![deny(single_use_lifetime)]
3+
//~^ WARNING renamed
4+
//~| NOTE `#[warn(renamed_and_removed_lints)]` on by default
5+
//~| NOTE defined here
6+
fn _foo<'a>(_x: &'a u32) {}
7+
//~^ ERROR only used once
8+
//~| NOTE this lifetime
9+
//~| NOTE is used only here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
warning: lint `single_use_lifetime` has been renamed to `single_use_lifetimes`
2+
--> $DIR/renamed-lints-still-apply.rs:2:9
3+
|
4+
LL | #![deny(single_use_lifetime)]
5+
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `single_use_lifetimes`
6+
|
7+
= note: `#[warn(renamed_and_removed_lints)]` on by default
8+
9+
error: lifetime parameter `'a` only used once
10+
--> $DIR/renamed-lints-still-apply.rs:6:9
11+
|
12+
LL | fn _foo<'a>(_x: &'a u32) {}
13+
| ^^ -- ...is used only here
14+
| |
15+
| this lifetime...
16+
|
17+
note: the lint level is defined here
18+
--> $DIR/renamed-lints-still-apply.rs:2:9
19+
|
20+
LL | #![deny(single_use_lifetime)]
21+
| ^^^^^^^^^^^^^^^^^^^
22+
help: elide the single-use lifetime
23+
|
24+
LL | fn _foo(_x: &u32) {}
25+
| -- --
26+
27+
error: aborting due to previous error; 1 warning emitted
28+

0 commit comments

Comments
 (0)