Skip to content

Commit 7c31df9

Browse files
Rollup merge of #111444 - cjgillot:issue-111400, r=oli-obk
Only warn single-use lifetime when the binders match. Fixes #111400
2 parents d4d15e8 + a2fe993 commit 7c31df9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

compiler/rustc_resolve/src/late.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
14821482
if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
14831483
self.record_lifetime_res(lifetime.id, res, LifetimeElisionCandidate::Named);
14841484

1485-
if let LifetimeRes::Param { param, .. } = res {
1485+
if let LifetimeRes::Param { param, binder } = res {
14861486
match self.lifetime_uses.entry(param) {
14871487
Entry::Vacant(v) => {
14881488
debug!("First use of {:?} at {:?}", res, ident.span);
@@ -1496,10 +1496,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
14961496
LifetimeRibKind::Item
14971497
| LifetimeRibKind::AnonymousReportError
14981498
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
1499-
// An anonymous lifetime is legal here, go ahead.
1500-
LifetimeRibKind::AnonymousCreateParameter { .. } => {
1501-
Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
1502-
}
1499+
// An anonymous lifetime is legal here, and bound to the right
1500+
// place, go ahead.
1501+
LifetimeRibKind::AnonymousCreateParameter {
1502+
binder: anon_binder,
1503+
..
1504+
} => Some(if binder == anon_binder {
1505+
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
1506+
} else {
1507+
LifetimeUseSet::Many
1508+
}),
15031509
// Only report if eliding the lifetime would have the same
15041510
// semantics.
15051511
LifetimeRibKind::Elided(r) => Some(if res == r {

tests/ui/associated-inherent-types/issue-109790.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![feature(inherent_associated_types)]
44
#![allow(incomplete_features)]
5+
#![deny(single_use_lifetimes)]
56

67
struct Foo<T>(T);
78

0 commit comments

Comments
 (0)