Skip to content

Commit c031184

Browse files
committed
Fix not complete type alias in pattern
Example --- ```rust enum Enum<T> { Unit, Tuple(T), } type EnumAlias<T> = Enum<T>; fn f(x: EnumAlias<u8>) { match x { $0 => (), _ => (), } } ``` **Before this PR** ```text en Enum bn Enum::Tuple(…) Enum::Tuple($1)$0 bn Enum::Unit Enum::Unit$0 kw mut kw ref ``` **After this PR** ```text en Enum ta EnumAlias bn Enum::Tuple(…) Enum::Tuple($1)$0 bn Enum::Unit Enum::Unit$0 kw mut kw ref ```
1 parent 2b05436 commit c031184

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub(crate) fn complete_pattern(
101101
hir::ModuleDef::Const(..) => refutable,
102102
hir::ModuleDef::Module(..) => true,
103103
hir::ModuleDef::Macro(mac) => mac.is_fn_like(ctx.db),
104+
hir::ModuleDef::TypeAlias(_) => true,
104105
_ => false,
105106
},
106107
hir::ScopeDef::ImplSelfType(impl_) => match impl_.self_ty(ctx.db).as_adt() {

src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,37 @@ fn f(x: EnumAlias<u8>) {
782782
);
783783
}
784784

785+
#[test]
786+
fn through_alias_it_self() {
787+
check(
788+
r#"
789+
enum Enum<T> {
790+
Unit,
791+
Tuple(T),
792+
}
793+
794+
type EnumAlias<T> = Enum<T>;
795+
796+
fn f(x: EnumAlias<u8>) {
797+
match x {
798+
$0 => (),
799+
_ => (),
800+
}
801+
802+
}
803+
804+
"#,
805+
expect![[r#"
806+
en Enum
807+
ta EnumAlias
808+
bn Enum::Tuple(…) Enum::Tuple($1)$0
809+
bn Enum::Unit Enum::Unit$0
810+
kw mut
811+
kw ref
812+
"#]],
813+
);
814+
}
815+
785816
#[test]
786817
fn pat_no_unstable_item_on_stable() {
787818
check(

0 commit comments

Comments
 (0)