From 17653dd3da53c2b1114dcb36b85c7d6512c6cc5f Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 13 Jun 2019 23:16:47 -0700 Subject: [PATCH] in which we decline to lint single-use lifetimes in `derive`d impls Resolves #53738. --- src/librustc/middle/resolve_lifetime.rs | 11 +++++++++++ src/test/ui/single-use-lifetime/one-use-in-struct.rs | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index edd5cb4541a96..1d88f25497269 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1591,6 +1591,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { continue; } + if let Some(parent_def_id) = self.tcx.parent(def_id) { + if let Some(parent_hir_id) = self.tcx.hir() + .as_local_hir_id(parent_def_id) { + // lifetimes in `derive` expansions don't count (Issue #53738) + if self.tcx.hir().attrs_by_hir_id(parent_hir_id).iter() + .any(|attr| attr.check_name(sym::automatically_derived)) { + continue; + } + } + } + let mut err = self.tcx.struct_span_lint_hir( lint::builtin::SINGLE_USE_LIFETIMES, id, diff --git a/src/test/ui/single-use-lifetime/one-use-in-struct.rs b/src/test/ui/single-use-lifetime/one-use-in-struct.rs index e0328c9d94a14..6c4d2a4a7ad41 100644 --- a/src/test/ui/single-use-lifetime/one-use-in-struct.rs +++ b/src/test/ui/single-use-lifetime/one-use-in-struct.rs @@ -18,4 +18,11 @@ enum Bar<'f> { trait Baz<'f> { } +// `Derive`d impls shouldn't trigger a warning, either (Issue #53738). + +#[derive(Debug)] +struct Quux<'a> { + priors: &'a u32, +} + fn main() { }