Only warn single-use lifetime when the binders match.
This commit is contained in:
parent
cba14074bb
commit
a2fe9935ea
@ -1482,7 +1482,7 @@ fn resolve_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::Lifeti
|
|||||||
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 @@ fn resolve_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::Lifeti
|
|||||||
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…
Reference in New Issue
Block a user