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

Fill match arms assist ignores existing variants prefixed with Self:: #4650

Open
yaahc opened this issue May 29, 2020 · 3 comments
Open

Fill match arms assist ignores existing variants prefixed with Self:: #4650

yaahc opened this issue May 29, 2020 · 3 comments
Labels
A-assists A-pattern pattern handling related things C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@yaahc
Copy link
Member

yaahc commented May 29, 2020

Right now if you have an enum that has some match arms and a match like this:

match x {
    Self::V1 => todo!(),
    Self::V2 => todo!(),
}

and you add a new variant and then run the fill match arms assist it will insert additional copies of V1 and V2 in the match arms that are prefixed with the types own name rather than Self.

@bnjjj
Copy link
Contributor

bnjjj commented May 29, 2020

Will check to fix it :)

bnjjj added a commit to bnjjj/rust-analyzer that referenced this issue May 30, 2020
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
bnjjj added a commit to bnjjj/rust-analyzer that referenced this issue May 30, 2020
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@Havvy
Copy link

Havvy commented Nov 9, 2020

This is a special case of the fill match arms assist not understanding use and type aliases. For example, given the following enum and various matches on its variants...

pub(crate) enum Foo {A, B, C, D, E, F}
type Bar = Foo;
mod Mod {
    pub(crate) use super::Foo as ModFoo;
}

impl Foo {
    fn match_assist(self) {
        use Foo::*;

        match self {
            Foo::A => {},
            Self::B => {},
            Bar::C => {},
            Mod::ModFoo::D => {}
            E => {},
        }
    }
}

...Rust Analyzer detects that the match is non-exhaustive and suggests to fill in the missing match arms. When using it, it changes the example to...

pub(crate) enum Foo {A, B, C, D, E, F}
type Bar = Foo;
mod Mod {
    pub(crate) use super::Foo as ModFoo;
}

impl Foo {
    fn match_assist(self) {
        use Foo::*;

        match self {
            Foo::A => {},
            Self::B => {},
            Bar::C => {},
            Mod::ModFoo::D => {}
            E => {},
            Foo::B => {}
            Foo::C => {}
            Foo::D => {}
            Foo::E => {}
            Foo::F => {}
        }
    }
}

...add arms for B through F. It should only add an arm for F, as that's the only one missing.

This behavior remains the same in a fn outside of an impl (ignoring the Self case that obviously doesn't compile).

@pksunkara
Copy link
Contributor

It duplicates E because of #1165 for sure.

@lnicola lnicola added A-assists S-actionable Someone could pick this issue up and work on it right now labels Jan 18, 2021
@flodiebold flodiebold added the C-bug Category: bug label Sep 2, 2022
noritada added a commit to noritada/rust-analyzer that referenced this issue Dec 25, 2022
noritada added a commit to noritada/rust-analyzer that referenced this issue Dec 25, 2022
…ts prefixed with `Self::`

This is an ad hoc fix of rust-lang#4650 by making only the last identifier
segment compared when the variant is prefixed, so that the comparison
is not affected by differences in prefix, such as type names, type
aliases, or `Self::`.

(The appropriate fix would be to use `hir_ty::diagnostics::match_check`,
as discussed in rust-lang#8493.)

Closes rust-lang#4650.
noritada added a commit to noritada/rust-analyzer that referenced this issue Dec 25, 2022
…ariants prefixed with `Self::`

This is an ad hoc fix of rust-lang#4650 by making only the last identifier
segment compared when the variant is prefixed, so that the comparison
is not affected by differences in prefix, such as type names, type
aliases, or `Self::`.

(The appropriate fix would be to use `hir_ty::diagnostics::match_check`,
as discussed in rust-lang#8493.)

Closes rust-lang#4650.
noritada added a commit to noritada/rust-analyzer that referenced this issue Dec 25, 2022
…ariants prefixed with `Self::`

This is an ad hoc fix of rust-lang#4650 by making only the last identifier
segment used for comparison when the variant is prefixed, so that the
comparison is not affected by differences in prefix, such as type
names, type aliases, or `Self::`.

(The appropriate fix would be to use `hir_ty::diagnostics::match_check`,
as discussed in rust-lang#8493.)

Closes rust-lang#4650.
@Nadrieril Nadrieril added the A-pattern pattern handling related things label Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists A-pattern pattern handling related things C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants