Skip to content

"implement missing members" assist uses incorrect lifetime name #13363

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

Closed
joseph-gio opened this issue Oct 7, 2022 · 3 comments · Fixed by #15054
Closed

"implement missing members" assist uses incorrect lifetime name #13363

joseph-gio opened this issue Oct 7, 2022 · 3 comments · Fixed by #15054
Labels
A-assists C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@joseph-gio
Copy link

rust-analyzer version: rust-analyzer version: 0.3.1229-standalone (5c28ad193 2022-10-01)

rustc version: rustc 1.63.0 (4b91a6ea7 2022-08-08)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)

Given the following code:

pub trait MyTrait<'lifetime> {
    fn foo(&'lifetime self);
}

impl<'a> MyTrait<'a> for () {

}

Using the assist "implement missing members" results in the following:

impl<'a> MyTrait<'a> {
    fn foo(&'lifetime self) { // this should be &'a self
        todo!()
    }
}
@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now A-assists C-bug Category: bug labels Oct 8, 2022
@TheDoctor314
Copy link
Contributor

I would like to look into this.

@ponyii
Copy link
Contributor

ponyii commented May 22, 2023

"imlement default members", a closely-related assist, doesn't update neither lifetimes nor const params:

pub trait Foo<const N: usize> {
    const CONST: usize = N * 4;
}

impl<const AAA: usize> Foo<AAA> for () {
    const CONST: usize = N * 4;             // the assist adds `N` instead of `AAA`
}

bors added a commit that referenced this issue Jun 10, 2023
…ansform-lifetimes, r=Veykril

fix: implemeted lifetime transformation fot assits

A part of #13363
I expect to implement transformation of const params in a separate PR

Other assists and a completion affected:
- `generate_function` currently just ignores lifetimes and, consequently, is not affected
- `inline_call` and `replace_derive_with...` don't seem to need lifetime transformation
- `trait_impl` (a completion) is fixed and tested
@ponyii
Copy link
Contributor

ponyii commented Jun 12, 2023

one more related problem - default types are not being transformed, e.g.:

mod m {
    pub struct S;

    pub trait Foo<T = S> {
        fn foo(&self, arg: &T) -> () {}
    }
}

impl m::Foo for () {
    fn foo(&self, arg: &S) -> () {}    // generated line with `S` instead of m::S
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
4 participants