about summary refs log tree commit diff
path: root/compiler/rustc_resolve
diff options
context:
space:
mode:
authorAdrian Taylor <adetaylor@chromium.org>2024-01-09 17:32:32 +0000
committerAdrian Taylor <adetaylor@chromium.org>2024-05-22 14:22:52 +0000
commite62599f8569509e5ebbea407d81f77fd0a9ca01b (patch)
treed7c2112c120008498f57997096647da1b0f71606 /compiler/rustc_resolve
parent8d1958f0d27f2a3393f2d6fde9560356c78b5f60 (diff)
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.
Diffstat (limited to 'compiler/rustc_resolve')
-rw-r--r--compiler/rustc_resolve/src/late.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 7c971e1f1bb..eb6827c85ec 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -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,