Skip to content

Commit 1396514

Browse files
committed
Auto merge of #152452 - ShE3py:overruled-lint, r=BoxyUwU
feat: show what lint was overruled We can't `#[allow]` a whole lint group if any of its members is forbidden, but the offending member is not currently shown if it was forbidden from the command line. Before/after: ```diff $ rustc -F dead_code - <<< '#![allow(unused)]' error[E0453]: allow(unused) incompatible with previous forbid --> <anon>:1:10 | 1 | #![allow(unused)] | ^^^^^^ overruled by previous forbid | - = note: `forbid` lint level was set on command line + = note: `forbid` lint level was set on command line (`-F dead_code`) error: aborting due to 1 previous error ``` @rustbot label +A-diagnostics +A-lints +D-terse
2 parents 873b4be + d129233 commit 1396514

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

compiler/rustc_lint/src/errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(crate) struct OverruledAttribute<'a> {
2020
pub(crate) enum OverruledAttributeSub {
2121
DefaultSource { id: String },
2222
NodeSource { span: Span, reason: Option<Symbol> },
23-
CommandLineSource,
23+
CommandLineSource { id: Symbol },
2424
}
2525

2626
impl Subdiagnostic for OverruledAttributeSub {
@@ -36,8 +36,9 @@ impl Subdiagnostic for OverruledAttributeSub {
3636
diag.note(rationale.to_string());
3737
}
3838
}
39-
OverruledAttributeSub::CommandLineSource => {
40-
diag.note(msg!("`forbid` lint level was set on command line"));
39+
OverruledAttributeSub::CommandLineSource { id } => {
40+
diag.note(msg!("`forbid` lint level was set on command line (`-F {$id}`)"));
41+
diag.arg("id", id);
4142
}
4243
}
4344
}

compiler/rustc_lint/src/levels.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
580580
LintLevelSource::Node { span, reason, .. } => {
581581
OverruledAttributeSub::NodeSource { span, reason }
582582
}
583-
LintLevelSource::CommandLine(_, _) => OverruledAttributeSub::CommandLineSource,
583+
LintLevelSource::CommandLine(name, _) => {
584+
OverruledAttributeSub::CommandLineSource { id: name }
585+
}
584586
};
585587
if !fcw_warning {
586588
self.sess.dcx().emit_err(OverruledAttribute {

tests/ui/lint/lint-forbid-attr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#![forbid(deprecated)]
1+
#![forbid(deprecated)] //~ NOTE `forbid` level set here
22

33
#[allow(deprecated)]
4-
//~^ ERROR allow(deprecated) incompatible
4+
//~^ ERROR allow(deprecated) incompatible with previous forbid [E0453]
5+
//~^^ NOTE overruled by previous forbid
56
fn main() {
67
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ compile-flags: -F deprecated
2+
3+
#[allow(deprecated)] //~ ERROR allow(deprecated) incompatible with previous forbid [E0453]
4+
fn main() {
5+
}

tests/ui/lint/lint-forbid-cmdline.stderr renamed to tests/ui/lint/lint-forbid-cmdline-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0453]: allow(deprecated) incompatible with previous forbid
2-
--> $DIR/lint-forbid-cmdline.rs:3:9
2+
--> $DIR/lint-forbid-cmdline-1.rs:3:9
33
|
44
LL | #[allow(deprecated)]
55
| ^^^^^^^^^^ overruled by previous forbid
66
|
7-
= note: `forbid` lint level was set on command line
7+
= note: `forbid` lint level was set on command line (`-F deprecated`)
88

99
error: aborting due to 1 previous error
1010

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ compile-flags: -F dead_code
2+
3+
#[allow(unused)]
4+
//~^ ERROR allow(unused) incompatible with previous forbid [E0453]
5+
//~| NOTE overruled by previous forbid
6+
//~| NOTE `forbid` lint level was set on command line (`-F dead_code`)
7+
fn main() {
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0453]: allow(unused) incompatible with previous forbid
2+
--> $DIR/lint-forbid-cmdline-2.rs:3:9
3+
|
4+
LL | #[allow(unused)]
5+
| ^^^^^^ overruled by previous forbid
6+
|
7+
= note: `forbid` lint level was set on command line (`-F dead_code`)
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0453`.

tests/ui/lint/lint-forbid-cmdline.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)