Rollup merge of #111444 - cjgillot:issue-111400, r=oli-obk
Only warn single-use lifetime when the binders match. Fixes https://github.com/rust-lang/rust/issues/111400
This commit is contained in:
commit
7c31df9d6c
2 changed files with 12 additions and 5 deletions
|
@ -1482,7 +1482,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
|
if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
|
||||||
self.record_lifetime_res(lifetime.id, res, LifetimeElisionCandidate::Named);
|
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) {
|
match self.lifetime_uses.entry(param) {
|
||||||
Entry::Vacant(v) => {
|
Entry::Vacant(v) => {
|
||||||
debug!("First use of {:?} at {:?}", res, ident.span);
|
debug!("First use of {:?} at {:?}", res, ident.span);
|
||||||
|
@ -1496,10 +1496,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
LifetimeRibKind::Item
|
LifetimeRibKind::Item
|
||||||
| LifetimeRibKind::AnonymousReportError
|
| LifetimeRibKind::AnonymousReportError
|
||||||
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
|
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
|
||||||
// An anonymous lifetime is legal here, go ahead.
|
// An anonymous lifetime is legal here, and bound to the right
|
||||||
LifetimeRibKind::AnonymousCreateParameter { .. } => {
|
// place, go ahead.
|
||||||
Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
|
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
|
// Only report if eliding the lifetime would have the same
|
||||||
// semantics.
|
// semantics.
|
||||||
LifetimeRibKind::Elided(r) => Some(if res == r {
|
LifetimeRibKind::Elided(r) => Some(if res == r {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#![feature(inherent_associated_types)]
|
#![feature(inherent_associated_types)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
#![deny(single_use_lifetimes)]
|
||||||
|
|
||||||
struct Foo<T>(T);
|
struct Foo<T>(T);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue