Skip to content

Commit eb188f1

Browse files
authored
Rollup merge of rust-lang#61824 - rust-lang:single_derive, r=eddyb
in which we decline to lint single-use lifetimes in `derive`d impls Resolves rust-lang#53738. r? @eddyb
2 parents be09427 + 17653dd commit eb188f1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/librustc/middle/resolve_lifetime.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15861586
continue;
15871587
}
15881588

1589+
if let Some(parent_def_id) = self.tcx.parent(def_id) {
1590+
if let Some(parent_hir_id) = self.tcx.hir()
1591+
.as_local_hir_id(parent_def_id) {
1592+
// lifetimes in `derive` expansions don't count (Issue #53738)
1593+
if self.tcx.hir().attrs_by_hir_id(parent_hir_id).iter()
1594+
.any(|attr| attr.check_name(sym::automatically_derived)) {
1595+
continue;
1596+
}
1597+
}
1598+
}
1599+
15891600
let mut err = self.tcx.struct_span_lint_hir(
15901601
lint::builtin::SINGLE_USE_LIFETIMES,
15911602
id,

src/test/ui/single-use-lifetime/one-use-in-struct.rs

+7
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ enum Bar<'f> {
1818

1919
trait Baz<'f> { }
2020

21+
// `Derive`d impls shouldn't trigger a warning, either (Issue #53738).
22+
23+
#[derive(Debug)]
24+
struct Quux<'a> {
25+
priors: &'a u32,
26+
}
27+
2128
fn main() { }

0 commit comments

Comments
 (0)