diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f4b4e50400530..d3ebb2b173da7 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2681,6 +2681,12 @@ fn lint_redundant_lifetimes<'tcx>( owner_id: LocalDefId, outlives_env: &OutlivesEnvironment<'tcx>, ) { + // Items produced by external macros (e.g. derived impls) reuse the lifetime spans of the + // macro input, so the usual external macro check on the lint span does not catch them. + if tcx.def_span(owner_id).in_external_macro(tcx.sess.source_map()) { + return; + } + let def_kind = tcx.def_kind(owner_id); match def_kind { DefKind::Struct 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 06ec71bb6c84d..4c09b40344c0f 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,11 +1,9 @@ -// 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. +// Make sure `#[expect]` on an item with a derive is fulfilled when the lint is only emitted on the +// item itself, and not also on the derived impl, which reuses the lifetime spans of the input. // // See for rational. -//@ check-fail +//@ check-pass #![deny(redundant_lifetimes)] @@ -14,7 +12,6 @@ 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 deleted file mode 100644 index c4047329d5c1f..0000000000000 --- a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr +++ /dev/null @@ -1,15 +0,0 @@ -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 -