From 700cb1940820e1a9568c322d112448d7b5fd5cd8 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 24 Feb 2026 19:56:05 +0100 Subject: [PATCH 1/2] Revert "Also duplicate `#[expect]` attribute in `#[derive]`-ed code" --- .../src/deriving/generic/mod.rs | 1 - .../derive-expect-issue-150553-3.rs | 4 +++- .../derive-expect-issue-150553-3.stderr | 12 ++---------- .../derive-expect-issue-150553.rs | 5 ++++- .../derive-expect-issue-150553.stderr | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index b2fff77e3f162..b392a9623d050 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -540,7 +540,6 @@ impl<'a> TraitDef<'a> { .filter(|a| { a.has_any_name(&[ sym::allow, - sym::expect, sym::warn, sym::deny, sym::forbid, diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.rs b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.rs index 904366e6532e5..b5f06912a97fc 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.rs +++ b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.rs @@ -1,3 +1,5 @@ +// FIXME: Bring back duplication of the `#[expect]` attribute when deriving. +// // Make sure we produce the unfulfilled expectation lint if neither the struct or the // derived code fulfilled it. @@ -5,7 +7,7 @@ #[expect(unexpected_cfgs)] //~^ WARN this lint expectation is unfulfilled -//~^^ WARN this lint expectation is unfulfilled +//FIXME ~^^ WARN this lint expectation is unfulfilled #[derive(Debug)] pub struct MyStruct { pub t_ref: i64, diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.stderr b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.stderr index 6478ec435db07..e75483df3f78a 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.stderr +++ b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.stderr @@ -1,18 +1,10 @@ warning: this lint expectation is unfulfilled - --> $DIR/derive-expect-issue-150553-3.rs:6:10 + --> $DIR/derive-expect-issue-150553-3.rs:8:10 | LL | #[expect(unexpected_cfgs)] | ^^^^^^^^^^^^^^^ | = note: `#[warn(unfulfilled_lint_expectations)]` on by default -warning: this lint expectation is unfulfilled - --> $DIR/derive-expect-issue-150553-3.rs:6:10 - | -LL | #[expect(unexpected_cfgs)] - | ^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: 2 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs index 1752835c8bb81..06ec71bb6c84d 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs +++ b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs @@ -1,9 +1,11 @@ +// FIXME: Bring back duplication of the `#[expect]` attribute when deriving. +// // Make sure we properly copy the `#[expect]` attr to the derived code and that no // unfulfilled expectations are trigerred. // // See for rational. -//@ check-pass +//@ check-fail #![deny(redundant_lifetimes)] @@ -12,6 +14,7 @@ use std::fmt::Debug; #[derive(Debug)] #[expect(redundant_lifetimes)] pub struct RefWrapper<'a, T> +//~^ ERROR redundant_lifetimes where 'a: 'static, T: Debug, diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr new file mode 100644 index 0000000000000..c4047329d5c1f --- /dev/null +++ b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr @@ -0,0 +1,15 @@ +error: unnecessary lifetime parameter `'a` + --> $DIR/derive-expect-issue-150553.rs:16:23 + | +LL | pub struct RefWrapper<'a, T> + | ^^ + | + = note: you can use the `'static` lifetime directly, in place of `'a` +note: the lint level is defined here + --> $DIR/derive-expect-issue-150553.rs:10:9 + | +LL | #![deny(redundant_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + From 8fefa653a920cd7a723927466acb5c626efd0e3c Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 24 Feb 2026 20:00:58 +0100 Subject: [PATCH 2/2] Add regression test for lint expectations with expansion and derives --- .../derive-expect-issue-150553-4.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-4.rs diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-4.rs b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-4.rs new file mode 100644 index 0000000000000..fb0d508186f8b --- /dev/null +++ b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-4.rs @@ -0,0 +1,15 @@ +// This test makes sure that expended items with derives don't interfear with lint expectations. +// +// See for some context. + +//@ check-pass + +#[derive(Clone, Debug)] +#[expect(unused)] +pub struct LoggingArgs { + #[cfg(false)] + x: i32, + y: i32, +} + +fn main() {}