Skip to content

arbitrary_self_types don't support lifetime elision #52675

Closed

Description

@Nemo157

I mentioned this on the RFC recently, but since this is being hit by futures 0.3 I thought it's worth having an issue for the current implementation in case it's an easy fix.

#![feature(arbitrary_self_types)]

struct Foo;
struct Bar<'a>(&'a Foo);

impl std::ops::Deref for Bar<'_> {
    type Target = Foo;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Foo {
    fn a(&self) -> Bar<'_> {
        Bar(self)
    }
    
    fn b(c: &Self) -> Bar<'_> {
        Bar(c)
    }

    fn c(self: Bar<'_>) -> Bar<'_> {
        self
    }
    
    fn d(e: Bar<'_>) -> Bar<'_> {
        e
    }
}

fn main() {
    let foo = Foo;
    { foo.a() };
    { Foo::b(&foo) };
    { Bar(&foo).c() };
    { Foo::d(Bar(&foo)) };
}
error[E0106]: missing lifetime specifier
  --> src/main.rs:15:32
   |
15 |     fn c(self: Bar<'_>) -> Bar<'_> {
   |                                ^^ expected lifetime parameter
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
   = help: consider giving it a 'static lifetime

(playground)

Activity

  1. changed the title [-]arbitrary_self_types break lifetime elision[/-] [+]arbitrary_self_types don't support lifetime elision[/+] on Jul 24, 2018
  2. added
    A-lifetimesArea: Lifetimes / regions
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jan 27, 2019
  3. nox commented on Mar 11, 2019

    @nox
    Contributor

    Any progress on that? I need this feature in Servo and the absence of lifetime elision is a huge papercut.

  4. Nemo157 commented on Apr 10, 2019

    @Nemo157
    ContributorAuthor

    This also interacts with the just added suggestion in #58919, the suggested fix won't work:

    impl Foo {
        fn c(self: Bar<'_>) -> impl std::fmt::Debug {
            self
        }
    }

    suggests adding + '_ to the return type, but that gives

    error[E0106]: missing lifetime specifier
    
  5. added a commit that references this issue on May 20, 2019
    42445de
  6. added a commit that references this issue on May 28, 2019
    f939092
  7. added a commit that references this issue on Jul 26, 2019
    7811ae8
  8. added 3 commits that reference this issue on Jul 27, 2019
    fe99a81
    5629d9f
    ece18b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions