Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 97c7321

Browse files
bors[bot]Jonas Schievink
andauthored
11753: feat: Complete assoc const patterns on builtin types r=jonas-schievink a=jonas-schievink followup to rust-lang/rust-analyzer#11713 bors r+ Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2 parents 849ac25 + 14203c6 commit 97c7321

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

crates/ide_completion/src/completions/pattern.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ fn pattern_path_completion(
141141
| hir::PathResolution::SelfType(_)
142142
| hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Struct(_)))
143143
| hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Enum(_)))
144-
| hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Union(_)))) => {
144+
| hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Union(_)))
145+
| hir::PathResolution::Def(hir::ModuleDef::BuiltinType(_))) => {
145146
let ty = match res {
146147
hir::PathResolution::TypeParam(param) => param.ty(ctx.db),
147148
hir::PathResolution::SelfType(impl_def) => impl_def.self_ty(ctx.db),
@@ -158,6 +159,13 @@ fn pattern_path_completion(
158159
hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Union(u))) => {
159160
u.ty(ctx.db)
160161
}
162+
hir::PathResolution::Def(hir::ModuleDef::BuiltinType(ty)) => {
163+
let module = match ctx.module {
164+
Some(m) => m,
165+
None => return,
166+
};
167+
ty.ty(ctx.db, module)
168+
}
161169
_ => return,
162170
};
163171

crates/ide_completion/src/tests/pattern.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ fn f(e: MyEnum) {
493493

494494
check_empty(
495495
r#"
496-
#[repr(C)]
497496
union U {
498497
i: i32,
499498
f: f32,
@@ -515,5 +514,23 @@ fn f(u: U) {
515514
ct C pub const C: i32
516515
ct D pub const D: i32
517516
"#]],
518-
)
517+
);
518+
519+
check_empty(
520+
r#"
521+
#[lang = "u32"]
522+
impl u32 {
523+
pub const MIN: Self = 0;
524+
}
525+
526+
fn f(v: u32) {
527+
match v {
528+
u32::$0
529+
}
530+
}
531+
"#,
532+
expect![[r#"
533+
ct MIN pub const MIN: Self
534+
"#]],
535+
);
519536
}

0 commit comments

Comments
 (0)