Skip to content

Commit 4985df8

Browse files
authored
Rollup merge of #165818 - Albab-Hasan:redundant-lifetimes-external-macro, r=petrochenkov
do not lint `redundant_lifetimes` on items from external macros derived impls copy the lifetime spans from the derive input so the external macro check on the lint span never fires and the lint is reported on the generated impl. that also left `#[expect(redundant_lifetimes)]` on a derived struct unfulfillable. now the lint skips items whose own span is in an external macro. fixes #150553 as suggested in #150553 (comment) r? @petrochenkov
2 parents 6ee27ce + 3a04685 commit 4985df8

3 files changed

Lines changed: 9 additions & 21 deletions

File tree

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,12 @@ fn lint_redundant_lifetimes<'tcx>(
26812681
owner_id: LocalDefId,
26822682
outlives_env: &OutlivesEnvironment<'tcx>,
26832683
) {
2684+
// Items produced by external macros (e.g. derived impls) reuse the lifetime spans of the
2685+
// macro input, so the usual external macro check on the lint span does not catch them.
2686+
if tcx.def_span(owner_id).in_external_macro(tcx.sess.source_map()) {
2687+
return;
2688+
}
2689+
26842690
let def_kind = tcx.def_kind(owner_id);
26852691
match def_kind {
26862692
DefKind::Struct

‎tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
2-
//
3-
// Make sure we properly copy the `#[expect]` attr to the derived code and that no
4-
// unfulfilled expectations are trigerred.
1+
// Make sure `#[expect]` on an item with a derive is fulfilled when the lint is only emitted on the
2+
// item itself, and not also on the derived impl, which reuses the lifetime spans of the input.
53
//
64
// See <https://github.com/rust-lang/rust/issues/150553> for rational.
75

8-
//@ check-fail
6+
//@ check-pass
97

108
#![deny(redundant_lifetimes)]
119

@@ -14,7 +12,6 @@ use std::fmt::Debug;
1412
#[derive(Debug)]
1513
#[expect(redundant_lifetimes)]
1614
pub struct RefWrapper<'a, T>
17-
//~^ ERROR redundant_lifetimes
1815
where
1916
'a: 'static,
2017
T: Debug,

‎tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr‎

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

0 commit comments

Comments
 (0)