mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 06:33:58 +00:00
Auto merge of #15970 - Austaras:master, r=Veykril
fix variant resolve for type alias Closes #15943
This commit is contained in:
commit
2ee17bc5f2
4 changed files with 62 additions and 14 deletions
|
@ -1152,20 +1152,15 @@ impl<'a> InferenceContext<'a> {
|
||||||
(ty, variant)
|
(ty, variant)
|
||||||
}
|
}
|
||||||
TypeNs::TypeAliasId(it) => {
|
TypeNs::TypeAliasId(it) => {
|
||||||
let container = it.lookup(self.db.upcast()).container;
|
let resolved_seg = match unresolved {
|
||||||
let parent_subst = match container {
|
None => path.segments().last().unwrap(),
|
||||||
ItemContainerId::TraitId(id) => {
|
Some(n) => path.segments().get(path.segments().len() - n - 1).unwrap(),
|
||||||
let subst = TyBuilder::subst_for_def(self.db, id, None)
|
|
||||||
.fill_with_inference_vars(&mut self.table)
|
|
||||||
.build();
|
|
||||||
Some(subst)
|
|
||||||
}
|
|
||||||
// Type aliases do not exist in impls.
|
|
||||||
_ => None,
|
|
||||||
};
|
};
|
||||||
let ty = TyBuilder::def_ty(self.db, it.into(), parent_subst)
|
let substs =
|
||||||
.fill_with_inference_vars(&mut self.table)
|
ctx.substs_from_path_segment(resolved_seg, Some(it.into()), true, None);
|
||||||
.build();
|
let ty = self.db.ty(it.into());
|
||||||
|
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||||
|
|
||||||
self.resolve_variant_on_alias(ty, unresolved, mod_path)
|
self.resolve_variant_on_alias(ty, unresolved, mod_path)
|
||||||
}
|
}
|
||||||
TypeNs::AdtSelfType(_) => {
|
TypeNs::AdtSelfType(_) => {
|
||||||
|
|
|
@ -768,7 +768,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn substs_from_path_segment(
|
pub(super) fn substs_from_path_segment(
|
||||||
&self,
|
&self,
|
||||||
segment: PathSegment<'_>,
|
segment: PathSegment<'_>,
|
||||||
def: Option<GenericDefId>,
|
def: Option<GenericDefId>,
|
||||||
|
|
|
@ -1129,3 +1129,27 @@ fn foo() {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generic_alias() {
|
||||||
|
check_types(
|
||||||
|
r#"
|
||||||
|
type Wrap<T> = T;
|
||||||
|
|
||||||
|
enum X {
|
||||||
|
A { cool: u32, stuff: u32 },
|
||||||
|
B,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let wrapped = Wrap::<X>::A {
|
||||||
|
cool: 100,
|
||||||
|
stuff: 100,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Wrap::<X>::A { cool, ..} = &wrapped {}
|
||||||
|
//^^^^ &u32
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -354,6 +354,35 @@ fn outer(Foo { bar$0 }: Foo) {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn completes_in_record_field_pat_with_generic_type_alias() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
type Wrap<T> = T;
|
||||||
|
|
||||||
|
enum X {
|
||||||
|
A { cool: u32, stuff: u32 },
|
||||||
|
B,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let wrapped = Wrap::<X>::A {
|
||||||
|
cool: 100,
|
||||||
|
stuff: 100,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Wrap::<X>::A { $0 } = &wrapped {};
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fd cool u32
|
||||||
|
fd stuff u32
|
||||||
|
kw mut
|
||||||
|
kw ref
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_in_fn_param() {
|
fn completes_in_fn_param() {
|
||||||
check_empty(
|
check_empty(
|
||||||
|
|
Loading…
Reference in a new issue