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

arbitrary_self_types don't support lifetime elision #52675

Closed
Nemo157 opened this issue Jul 24, 2018 · 2 comments · Fixed by #61207
Closed

arbitrary_self_types don't support lifetime elision #52675

Nemo157 opened this issue Jul 24, 2018 · 2 comments · Fixed by #61207
Labels
A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Jul 24, 2018

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)

@Nemo157 Nemo157 changed the title arbitrary_self_types break lifetime elision arbitrary_self_types don't support lifetime elision Jul 24, 2018
@jonas-schievink jonas-schievink added A-lifetimes Area: lifetime related T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 27, 2019
@nox
Copy link
Contributor

nox commented Mar 11, 2019

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

@Nemo157
Copy link
Member Author

Nemo157 commented Apr 10, 2019

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

bors added a commit that referenced this issue May 20, 2019
… r=<try>

Allow lifetime elision in arbitrary_self_types

Currently, `self` except `&Self` and `&mut Self` is skipped. By this, other `self`s with lifetime is also ignored.
This PR changes it to only skip `Self`, `&Self` and `&mut Self`, and to handle other `self`s like normal arguments.

Closes #52675
bors added a commit that referenced this issue May 28, 2019
…2, r=<try>

Allow lifetime elision in `Pin<&(mut) Self>`

This replaces #60944.

~~This PR changes elision rules to apply `self: &(mut) Self` elision rules even if nested in `Pin`.~~
This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it

Closes #52675

r? @eddyb
cc @cramertj @Centril @withoutboats @scottmcm
Centril added a commit to Centril/rust that referenced this issue Jul 26, 2019
…me-elision-2, r=Centril

Allow lifetime elision in `Pin<&(mut) Self>`

This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it

Replaces rust-lang#60944

Closes rust-lang#52675

r? @eddyb
cc @cramertj @Centril @withoutboats @scottmcm
Centril added a commit to Centril/rust that referenced this issue Jul 27, 2019
…me-elision-2, r=Centril

Allow lifetime elision in `Pin<&(mut) Self>`

This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it

Replaces rust-lang#60944

Closes rust-lang#52675

r? @eddyb
cc @cramertj @Centril @withoutboats @scottmcm
Centril added a commit to Centril/rust that referenced this issue Jul 27, 2019
…me-elision-2, r=Centril

Allow lifetime elision in `Pin<&(mut) Self>`

This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it

Replaces rust-lang#60944

Closes rust-lang#52675

r? @eddyb
cc @cramertj @Centril @withoutboats @scottmcm
Centril added a commit to Centril/rust that referenced this issue Jul 28, 2019
…me-elision-2, r=Centril

Allow lifetime elision in `Pin<&(mut) Self>`

This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it

Replaces rust-lang#60944

Closes rust-lang#52675

r? @eddyb
cc @cramertj @Centril @withoutboats @scottmcm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants