Skip to content

Commit

Permalink
Rollup merge of rust-lang#61824 - rust-lang:single_derive, r=eddyb
Browse files Browse the repository at this point in the history
in which we decline to lint single-use lifetimes in `derive`d impls

Resolves rust-lang#53738.

r? @eddyb
  • Loading branch information
Centril authored Jun 14, 2019
2 parents 40f1744 + 17653dd commit 20aba33
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 20aba33

Please sign in to comment.