-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Comments
Will check to fix it :) |
Signed-off-by: Benjamin Coenen <[email protected]>
Signed-off-by: Benjamin Coenen <[email protected]>
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 This behavior remains the same in a |
It duplicates |
…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.
…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.
…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.
Right now if you have an enum that has some match arms and a match like this:
and you add a new variant and then run the fill match arms assist it will insert additional copies of
V1
andV2
in the match arms that are prefixed with the types own name rather than Self.The text was updated successfully, but these errors were encountered: