Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ambiguous cases of multiple & in elided self lifetimes #117967

Merged
merged 7 commits into from
Jul 18, 2024

Commits on May 22, 2024

  1. Ambiguous Self lifetimes: don't elide.

      struct Concrete(u32);
    
      impl Concrete {
          fn m(self: &Box<Self>) -> &u32 {
              &self.0
          }
      }
    
    resulted in a confusing error.
    
      impl Concrete {
          fn n(self: &Box<&Self>) -> &u32 {
              &self.0
          }
      }
    
    resulted in no error or warning, despite apparent ambiguity over the elided
    lifetime.
    
    This commit changes two aspects of the behavior.
    
    Previously, when examining the self type, we considered lifetimes only if they
    were immediately adjacent to Self. We now consider lifetimes anywhere in the
    self type.
    
    Secondly, if more than one lifetime is discovered in the self type, we
    disregard it as a possible lifetime elision candidate.
    
    This is a compatibility break, and in fact has required some changes to tests
    which assumed the earlier behavior.
    
    Fixes rust-lang#117715
    adetaylor committed May 22, 2024
    Configuration menu
    Copy the full SHA
    8d1958f View commit details
    Browse the repository at this point in the history
  2. 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.
    adetaylor committed May 22, 2024
    Configuration menu
    Copy the full SHA
    e62599f View commit details
    Browse the repository at this point in the history

Commits on May 31, 2024

  1. Adjust crash bug to still reproduce.

    This test reproduces a rustc ICE. Unfortunately, the changes to lifetime
    elision mask the original ICE bug by making this function signature
    illegal. However, by simplifying the signature we can regain the
    original ICE.
    adetaylor committed May 31, 2024
    Configuration menu
    Copy the full SHA
    6287c94 View commit details
    Browse the repository at this point in the history
  2. Remove duplicative test.

    I think that this test is supposed to be a treereduced version of
    122903-1.rs, but is actually identical.
    adetaylor committed May 31, 2024
    Configuration menu
    Copy the full SHA
    8c17777 View commit details
    Browse the repository at this point in the history

Commits on Jun 4, 2024

  1. Add additional tests.

    adetaylor committed Jun 4, 2024
    Configuration menu
    Copy the full SHA
    c20a90f View commit details
    Browse the repository at this point in the history

Commits on Jun 5, 2024

  1. Configuration menu
    Copy the full SHA
    386838d View commit details
    Browse the repository at this point in the history

Commits on Jun 10, 2024

  1. Elision: consider lifetimes from &T iff T has Self

    Change the algorithm which determines whether a self lifetime can be
    used for return type lifetime elision, such that we consider lifetimes
    attached to any reference in the self type, so long as Self can be found
    anywhere inside the type of that reference.
    adetaylor committed Jun 10, 2024
    Configuration menu
    Copy the full SHA
    a22130e View commit details
    Browse the repository at this point in the history