mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-22 12:34:43 +00:00
Propogate error types in mir type projections
This commit is contained in:
parent
8aa4ae5e69
commit
5af2d6abea
@ -10,7 +10,7 @@ use crate::{
|
|||||||
lang_items::is_box,
|
lang_items::is_box,
|
||||||
mapping::ToChalk,
|
mapping::ToChalk,
|
||||||
CallableDefId, ClosureId, Const, ConstScalar, InferenceResult, Interner, MemoryMap,
|
CallableDefId, ClosureId, Const, ConstScalar, InferenceResult, Interner, MemoryMap,
|
||||||
Substitution, TraitEnvironment, Ty, TyKind,
|
Substitution, TraitEnvironment, Ty, TyExt, TyKind,
|
||||||
};
|
};
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use chalk_ir::Mutability;
|
use chalk_ir::Mutability;
|
||||||
@ -144,6 +144,13 @@ impl<V, T> ProjectionElem<V, T> {
|
|||||||
closure_field: impl FnOnce(ClosureId, &Substitution, usize) -> Ty,
|
closure_field: impl FnOnce(ClosureId, &Substitution, usize) -> Ty,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
) -> Ty {
|
) -> Ty {
|
||||||
|
// we only bail on mir building when there are type mismatches
|
||||||
|
// but error types may pop up resulting in us still attempting to build the mir
|
||||||
|
// so just propagate the error type
|
||||||
|
if base.is_unknown() {
|
||||||
|
return TyKind::Error.intern(Interner);
|
||||||
|
}
|
||||||
|
|
||||||
if matches!(base.kind(Interner), TyKind::Alias(_) | TyKind::AssociatedType(..)) {
|
if matches!(base.kind(Interner), TyKind::Alias(_) | TyKind::AssociatedType(..)) {
|
||||||
base = normalize(
|
base = normalize(
|
||||||
db,
|
db,
|
||||||
@ -166,7 +173,7 @@ impl<V, T> ProjectionElem<V, T> {
|
|||||||
TyKind::Error.intern(Interner)
|
TyKind::Error.intern(Interner)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ProjectionElem::Field(Either::Left(f)) => match &base.kind(Interner) {
|
ProjectionElem::Field(Either::Left(f)) => match base.kind(Interner) {
|
||||||
TyKind::Adt(_, subst) => {
|
TyKind::Adt(_, subst) => {
|
||||||
db.field_types(f.parent)[f.local_id].clone().substitute(Interner, subst)
|
db.field_types(f.parent)[f.local_id].clone().substitute(Interner, subst)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -260,6 +260,19 @@ fn main() {
|
|||||||
let arr = [1, 2, 3, 4, 5];
|
let arr = [1, 2, 3, 4, 5];
|
||||||
let [_x, _y @ ..] = arr;
|
let [_x, _y @ ..] = arr;
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// regression test as we used to panic in this scenario
|
||||||
|
#[test]
|
||||||
|
fn unknown_struct_pattern_param_type() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
struct S { field : u32 }
|
||||||
|
fn f(S { field }: error) {
|
||||||
|
// ^^^^^ 💡 warn: unused variable
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user