Skip to content

Commit f663521

Browse files
committed
Auto merge of #16152 - Austaras:alias, r=Veykril
fix: resolve alias before resolve variant Closes #15943 (again)
2 parents ae2c322 + bd61888 commit f663521

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

crates/hir-ty/src/infer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,12 @@ impl<'a> InferenceContext<'a> {
12001200
path: &ModPath,
12011201
) -> (Ty, Option<VariantId>) {
12021202
let remaining = unresolved.map(|it| path.segments()[it..].len()).filter(|it| it > &0);
1203+
let ty = match ty.kind(Interner) {
1204+
TyKind::Alias(AliasTy::Projection(proj_ty)) => {
1205+
self.db.normalize_projection(proj_ty.clone(), self.table.trait_env.clone())
1206+
}
1207+
_ => ty,
1208+
};
12031209
match remaining {
12041210
None => {
12051211
let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {

crates/hir-ty/src/tests/patterns.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,40 @@ fn main() {
11541154
);
11551155
}
11561156

1157+
#[test]
1158+
fn generic_alias_with_qualified_path() {
1159+
check_types(
1160+
r#"
1161+
type Wrap<T> = T;
1162+
1163+
struct S;
1164+
1165+
trait Schematic {
1166+
type Props;
1167+
}
1168+
1169+
impl Schematic for S {
1170+
type Props = X;
1171+
}
1172+
1173+
enum X {
1174+
A { cool: u32, stuff: u32 },
1175+
B,
1176+
}
1177+
1178+
fn main() {
1179+
let wrapped = Wrap::<<S as Schematic>::Props>::A {
1180+
cool: 100,
1181+
stuff: 100,
1182+
};
1183+
1184+
if let Wrap::<<S as Schematic>::Props>::A { cool, ..} = &wrapped {}
1185+
//^^^^ &u32
1186+
}
1187+
"#,
1188+
);
1189+
}
1190+
11571191
#[test]
11581192
fn type_mismatch_pat_const_reference() {
11591193
check_no_mismatches(

0 commit comments

Comments
 (0)