1
Fork 0

Do not elide if there's ambiguity in self lifetime.

This makes a small change as requested in code review, such that if there's
ambiguity in the self lifetime, we avoid lifetime elision entirely instead of
considering using lifetimes from any of the other parameters.

For example,

impl Something {
  fn method(self: &Box<&Self>, something_else: &u32) -> &u32 { ... }
}

in standard Rust would have assumed the return lifetime was that of &Self;
with this PR prior to this commit would have chosen the lifetime of
'something_else', and after this commit would give an error message explaining
that the lifetime is ambiguous.
This commit is contained in:
Adrian Taylor 2024-01-09 17:32:32 +00:00
parent 8d1958f0d2
commit e62599f856
7 changed files with 169 additions and 7 deletions

View file

@ -2136,8 +2136,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
// We found `self` elision.
Set1::One(lifetime) => Elision::Self_(lifetime),
// `self` itself had ambiguous lifetimes, e.g.
// &Box<&Self>
Set1::Many => Elision::None,
// &Box<&Self>. In this case we won't consider
// taking an alternative parameter lifetime; just avoid elision
// entirely.
Set1::Many => Elision::Err,
// We do not have `self` elision: disregard the `Elision::Param` that we may
// have found.
Set1::Empty => Elision::None,