Skip to content

Commit

Permalink
in which we decline to lint single-use lifetimes in derived impls
Browse files Browse the repository at this point in the history
Resolves #53738.
  • Loading branch information
zackmdavis committed Jun 14, 2019
1 parent cdd7437 commit 17653dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/single-use-lifetime/one-use-in-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

0 comments on commit 17653dd

Please sign in to comment.