Skip to content

Commit 17653dd

Browse files
committed
in which we decline to lint single-use lifetimes in derived impls
Resolves rust-lang#53738.
1 parent cdd7437 commit 17653dd

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
@@ -1591,6 +1591,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15911591
continue;
15921592
}
15931593

1594+
if let Some(parent_def_id) = self.tcx.parent(def_id) {
1595+
if let Some(parent_hir_id) = self.tcx.hir()
1596+
.as_local_hir_id(parent_def_id) {
1597+
// lifetimes in `derive` expansions don't count (Issue #53738)
1598+
if self.tcx.hir().attrs_by_hir_id(parent_hir_id).iter()
1599+
.any(|attr| attr.check_name(sym::automatically_derived)) {
1600+
continue;
1601+
}
1602+
}
1603+
}
1604+
15941605
let mut err = self.tcx.struct_span_lint_hir(
15951606
lint::builtin::SINGLE_USE_LIFETIMES,
15961607
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)