Do not consider repeated lifetime params for elision.
This commit is contained in:
parent
6c9c2d862d
commit
47704bbcc0
3 changed files with 21 additions and 6 deletions
|
@ -565,7 +565,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
/// They will be used to determine the correct lifetime for the fn return type.
|
/// They will be used to determine the correct lifetime for the fn return type.
|
||||||
/// The `LifetimeElisionCandidate` is used for diagnostics, to suggest introducing named
|
/// The `LifetimeElisionCandidate` is used for diagnostics, to suggest introducing named
|
||||||
/// lifetimes.
|
/// lifetimes.
|
||||||
lifetime_elision_candidates: Option<FxIndexMap<LifetimeRes, LifetimeElisionCandidate>>,
|
lifetime_elision_candidates: Option<Vec<(LifetimeRes, LifetimeElisionCandidate)>>,
|
||||||
|
|
||||||
/// The trait that the current context can refer to.
|
/// The trait that the current context can refer to.
|
||||||
current_trait_ref: Option<(Module<'a>, TraitRef)>,
|
current_trait_ref: Option<(Module<'a>, TraitRef)>,
|
||||||
|
@ -1799,7 +1799,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
match res {
|
match res {
|
||||||
LifetimeRes::Param { .. } | LifetimeRes::Fresh { .. } | LifetimeRes::Static => {
|
LifetimeRes::Param { .. } | LifetimeRes::Fresh { .. } | LifetimeRes::Static => {
|
||||||
if let Some(ref mut candidates) = self.lifetime_elision_candidates {
|
if let Some(ref mut candidates) = self.lifetime_elision_candidates {
|
||||||
candidates.insert(res, candidate);
|
candidates.push((res, candidate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LifetimeRes::Infer | LifetimeRes::Error | LifetimeRes::ElidedAnchor { .. } => {}
|
LifetimeRes::Infer | LifetimeRes::Error | LifetimeRes::ElidedAnchor { .. } => {}
|
||||||
|
@ -1910,8 +1910,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
|
|
||||||
// We do not have a `self` candidate, look at the full list.
|
// We do not have a `self` candidate, look at the full list.
|
||||||
let all_candidates = all_candidates.unwrap();
|
let all_candidates = all_candidates.unwrap();
|
||||||
if all_candidates.len() == 1 {
|
if let [(res, _)] = &all_candidates[..] {
|
||||||
Ok(*all_candidates.first().unwrap().0)
|
Ok(*res)
|
||||||
} else {
|
} else {
|
||||||
let all_candidates = all_candidates
|
let all_candidates = all_candidates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -2391,7 +2391,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
// Do not account for the parameters we just bound for function lifetime elision.
|
// Do not account for the parameters we just bound for function lifetime elision.
|
||||||
if let Some(ref mut candidates) = self.lifetime_elision_candidates {
|
if let Some(ref mut candidates) = self.lifetime_elision_candidates {
|
||||||
for (_, res) in function_lifetime_rib.bindings.values() {
|
for (_, res) in function_lifetime_rib.bindings.values() {
|
||||||
candidates.remove(res);
|
candidates.retain(|(r, _)| r != res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,4 +42,7 @@ fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
|
||||||
|
//~^ ERROR missing lifetime specifier
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -70,6 +70,18 @@ help: consider using the `'a` lifetime
|
||||||
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &'a isize {
|
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &'a isize {
|
||||||
| ++
|
| ++
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error[E0106]: missing lifetime specifier
|
||||||
|
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:45:37
|
||||||
|
|
|
||||||
|
LL | fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
|
||||||
|
| ------- ------- ^ expected named lifetime parameter
|
||||||
|
|
|
||||||
|
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||||
|
help: consider using the `'a` lifetime
|
||||||
|
|
|
||||||
|
LL | fn l<'a>(_: &'a str, _: &'a str) -> &'a str { "" }
|
||||||
|
| ++
|
||||||
|
|
||||||
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0106`.
|
For more information about this error, try `rustc --explain E0106`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue