From d12923346c44ea09fa2ace6467836e22c7534bfd Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 15 Feb 2026 15:40:13 +0100 Subject: [PATCH] feat: show what lint was overruled --- compiler/rustc_lint/src/errors.rs | 7 ++++--- compiler/rustc_lint/src/levels.rs | 4 +++- tests/ui/lint/lint-forbid-attr.rs | 5 +++-- tests/ui/lint/lint-forbid-cmdline-1.rs | 5 +++++ ...id-cmdline.stderr => lint-forbid-cmdline-1.stderr} | 4 ++-- tests/ui/lint/lint-forbid-cmdline-2.rs | 8 ++++++++ tests/ui/lint/lint-forbid-cmdline-2.stderr | 11 +++++++++++ tests/ui/lint/lint-forbid-cmdline.rs | 5 ----- 8 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 tests/ui/lint/lint-forbid-cmdline-1.rs rename tests/ui/lint/{lint-forbid-cmdline.stderr => lint-forbid-cmdline-1.stderr} (70%) create mode 100644 tests/ui/lint/lint-forbid-cmdline-2.rs create mode 100644 tests/ui/lint/lint-forbid-cmdline-2.stderr delete mode 100644 tests/ui/lint/lint-forbid-cmdline.rs diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 51b97bc67d2c6..8fec30816bd13 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -20,7 +20,7 @@ pub(crate) struct OverruledAttribute<'a> { pub(crate) enum OverruledAttributeSub { DefaultSource { id: String }, NodeSource { span: Span, reason: Option }, - CommandLineSource, + CommandLineSource { id: Symbol }, } impl Subdiagnostic for OverruledAttributeSub { @@ -36,8 +36,9 @@ impl Subdiagnostic for OverruledAttributeSub { diag.note(rationale.to_string()); } } - OverruledAttributeSub::CommandLineSource => { - diag.note(msg!("`forbid` lint level was set on command line")); + OverruledAttributeSub::CommandLineSource { id } => { + diag.note(msg!("`forbid` lint level was set on command line (`-F {$id}`)")); + diag.arg("id", id); } } } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 0481188757129..a3376ad967e06 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -580,7 +580,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { LintLevelSource::Node { span, reason, .. } => { OverruledAttributeSub::NodeSource { span, reason } } - LintLevelSource::CommandLine(_, _) => OverruledAttributeSub::CommandLineSource, + LintLevelSource::CommandLine(name, _) => { + OverruledAttributeSub::CommandLineSource { id: name } + } }; if !fcw_warning { self.sess.dcx().emit_err(OverruledAttribute { diff --git a/tests/ui/lint/lint-forbid-attr.rs b/tests/ui/lint/lint-forbid-attr.rs index 270a379c2f848..cbe7a02a0c17f 100644 --- a/tests/ui/lint/lint-forbid-attr.rs +++ b/tests/ui/lint/lint-forbid-attr.rs @@ -1,6 +1,7 @@ -#![forbid(deprecated)] +#![forbid(deprecated)] //~ NOTE `forbid` level set here #[allow(deprecated)] -//~^ ERROR allow(deprecated) incompatible +//~^ ERROR allow(deprecated) incompatible with previous forbid [E0453] +//~^^ NOTE overruled by previous forbid fn main() { } diff --git a/tests/ui/lint/lint-forbid-cmdline-1.rs b/tests/ui/lint/lint-forbid-cmdline-1.rs new file mode 100644 index 0000000000000..19a8f825f57d0 --- /dev/null +++ b/tests/ui/lint/lint-forbid-cmdline-1.rs @@ -0,0 +1,5 @@ +//@ compile-flags: -F deprecated + +#[allow(deprecated)] //~ ERROR allow(deprecated) incompatible with previous forbid [E0453] +fn main() { +} diff --git a/tests/ui/lint/lint-forbid-cmdline.stderr b/tests/ui/lint/lint-forbid-cmdline-1.stderr similarity index 70% rename from tests/ui/lint/lint-forbid-cmdline.stderr rename to tests/ui/lint/lint-forbid-cmdline-1.stderr index 3920a7429763e..7f4893fabd972 100644 --- a/tests/ui/lint/lint-forbid-cmdline.stderr +++ b/tests/ui/lint/lint-forbid-cmdline-1.stderr @@ -1,10 +1,10 @@ error[E0453]: allow(deprecated) incompatible with previous forbid - --> $DIR/lint-forbid-cmdline.rs:3:9 + --> $DIR/lint-forbid-cmdline-1.rs:3:9 | LL | #[allow(deprecated)] | ^^^^^^^^^^ overruled by previous forbid | - = note: `forbid` lint level was set on command line + = note: `forbid` lint level was set on command line (`-F deprecated`) error: aborting due to 1 previous error diff --git a/tests/ui/lint/lint-forbid-cmdline-2.rs b/tests/ui/lint/lint-forbid-cmdline-2.rs new file mode 100644 index 0000000000000..3505c11f42011 --- /dev/null +++ b/tests/ui/lint/lint-forbid-cmdline-2.rs @@ -0,0 +1,8 @@ +//@ compile-flags: -F dead_code + +#[allow(unused)] +//~^ ERROR allow(unused) incompatible with previous forbid [E0453] +//~| NOTE overruled by previous forbid +//~| NOTE `forbid` lint level was set on command line (`-F dead_code`) +fn main() { +} diff --git a/tests/ui/lint/lint-forbid-cmdline-2.stderr b/tests/ui/lint/lint-forbid-cmdline-2.stderr new file mode 100644 index 0000000000000..18a60b2f8b7e0 --- /dev/null +++ b/tests/ui/lint/lint-forbid-cmdline-2.stderr @@ -0,0 +1,11 @@ +error[E0453]: allow(unused) incompatible with previous forbid + --> $DIR/lint-forbid-cmdline-2.rs:3:9 + | +LL | #[allow(unused)] + | ^^^^^^ overruled by previous forbid + | + = note: `forbid` lint level was set on command line (`-F dead_code`) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0453`. diff --git a/tests/ui/lint/lint-forbid-cmdline.rs b/tests/ui/lint/lint-forbid-cmdline.rs deleted file mode 100644 index 8a4eb449d3c8a..0000000000000 --- a/tests/ui/lint/lint-forbid-cmdline.rs +++ /dev/null @@ -1,5 +0,0 @@ -//@ compile-flags: -F deprecated - -#[allow(deprecated)] //~ ERROR allow(deprecated) incompatible -fn main() { -}