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

Lifetime elision not working properly with self: &mut Rc<Self> #89094

Closed
steffahn opened this issue Sep 19, 2021 · 1 comment
Closed

Lifetime elision not working properly with self: &mut Rc<Self> #89094

steffahn opened this issue Sep 19, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@steffahn
Copy link
Member

steffahn commented Sep 19, 2021

I tried this code:

use std::rc::Rc;
trait Foo: Clone {
    fn f(self: &mut Rc<Self>) -> &mut Self {
        Rc::make_mut(self)
    }
}

I expected to see this happen: Code compiles

Instead, this happened:

   Compiling playground v0.0.1 (/playground)
error[E0106]: missing lifetime specifier
 --> src/lib.rs:3:34
  |
3 |     fn f(self: &mut Rc<Self>) -> &mut Self {
  |                                  ^ expected named 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 using the `'static` lifetime
  |
3 |     fn f(self: &mut Rc<Self>) -> &'static mut Self {
  |                                  ~~~~~~~~

(playground)

Meta

Happens on stable, nightly, and older rust versions


Same problem for inherent impls

#[derive(Clone)]
struct S;
use std::rc::Rc;
impl S {
    fn f(self: &mut Rc<Self>) -> &mut Self {
        Rc::make_mut(self)
    }
}
@steffahn steffahn added the C-bug Category: This is a bug. label Sep 19, 2021
@steffahn
Copy link
Member Author

Ah, there it is (duplicate): #69064

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant