mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 22:54:00 +00:00
Auto merge of #16152 - Austaras:alias, r=Veykril
fix: resolve alias before resolve variant Closes #15943 (again)
This commit is contained in:
commit
f6635211ce
2 changed files with 40 additions and 0 deletions
|
@ -1200,6 +1200,12 @@ impl<'a> InferenceContext<'a> {
|
||||||
path: &ModPath,
|
path: &ModPath,
|
||||||
) -> (Ty, Option<VariantId>) {
|
) -> (Ty, Option<VariantId>) {
|
||||||
let remaining = unresolved.map(|it| path.segments()[it..].len()).filter(|it| it > &0);
|
let remaining = unresolved.map(|it| path.segments()[it..].len()).filter(|it| it > &0);
|
||||||
|
let ty = match ty.kind(Interner) {
|
||||||
|
TyKind::Alias(AliasTy::Projection(proj_ty)) => {
|
||||||
|
self.db.normalize_projection(proj_ty.clone(), self.table.trait_env.clone())
|
||||||
|
}
|
||||||
|
_ => ty,
|
||||||
|
};
|
||||||
match remaining {
|
match remaining {
|
||||||
None => {
|
None => {
|
||||||
let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {
|
let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {
|
||||||
|
|
|
@ -1154,6 +1154,40 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generic_alias_with_qualified_path() {
|
||||||
|
check_types(
|
||||||
|
r#"
|
||||||
|
type Wrap<T> = T;
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
trait Schematic {
|
||||||
|
type Props;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Schematic for S {
|
||||||
|
type Props = X;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum X {
|
||||||
|
A { cool: u32, stuff: u32 },
|
||||||
|
B,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let wrapped = Wrap::<<S as Schematic>::Props>::A {
|
||||||
|
cool: 100,
|
||||||
|
stuff: 100,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Wrap::<<S as Schematic>::Props>::A { cool, ..} = &wrapped {}
|
||||||
|
//^^^^ &u32
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn type_mismatch_pat_const_reference() {
|
fn type_mismatch_pat_const_reference() {
|
||||||
check_no_mismatches(
|
check_no_mismatches(
|
||||||
|
|
Loading…
Reference in a new issue