Skip to content

Commit

Permalink
Rollup merge of #111444 - cjgillot:issue-111400, r=oli-obk
Browse files Browse the repository at this point in the history
Only warn single-use lifetime when the binders match.

Fixes #111400
  • Loading branch information
compiler-errors committed May 12, 2023
2 parents d4d15e8 + a2fe993 commit 7c31df9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
self.record_lifetime_res(lifetime.id, res, LifetimeElisionCandidate::Named);

if let LifetimeRes::Param { param, .. } = res {
if let LifetimeRes::Param { param, binder } = res {
match self.lifetime_uses.entry(param) {
Entry::Vacant(v) => {
debug!("First use of {:?} at {:?}", res, ident.span);
Expand All @@ -1496,10 +1496,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
LifetimeRibKind::Item
| LifetimeRibKind::AnonymousReportError
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
// An anonymous lifetime is legal here, go ahead.
LifetimeRibKind::AnonymousCreateParameter { .. } => {
Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
}
// An anonymous lifetime is legal here, and bound to the right
// place, go ahead.
LifetimeRibKind::AnonymousCreateParameter {
binder: anon_binder,
..
} => Some(if binder == anon_binder {
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
} else {
LifetimeUseSet::Many
}),
// Only report if eliding the lifetime would have the same
// semantics.
LifetimeRibKind::Elided(r) => Some(if res == r {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/associated-inherent-types/issue-109790.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![feature(inherent_associated_types)]
#![allow(incomplete_features)]
#![deny(single_use_lifetimes)]

struct Foo<T>(T);

Expand Down

0 comments on commit 7c31df9

Please sign in to comment.