Partly flatten the user-type loop in TypeVerifier::visit_local_decl
This commit is contained in:
parent
6d3c050de8
commit
849b0920b1
1 changed files with 33 additions and 30 deletions
|
@ -456,38 +456,41 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||||
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
|
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
|
||||||
self.super_local_decl(local, local_decl);
|
self.super_local_decl(local, local_decl);
|
||||||
|
|
||||||
if let Some(user_ty) = &local_decl.user_ty {
|
for (user_ty, span) in local_decl
|
||||||
for (user_ty, span) in user_ty.projections_and_spans() {
|
.user_ty
|
||||||
let ty = if !local_decl.is_nonref_binding() {
|
.as_deref()
|
||||||
// If we have a binding of the form `let ref x: T = ..`
|
.into_iter()
|
||||||
// then remove the outermost reference so we can check the
|
.flat_map(UserTypeProjections::projections_and_spans)
|
||||||
// type annotation for the remaining type.
|
{
|
||||||
if let ty::Ref(_, rty, _) = local_decl.ty.kind() {
|
let ty = if !local_decl.is_nonref_binding() {
|
||||||
*rty
|
// If we have a binding of the form `let ref x: T = ..`
|
||||||
} else {
|
// then remove the outermost reference so we can check the
|
||||||
bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty);
|
// type annotation for the remaining type.
|
||||||
}
|
if let ty::Ref(_, rty, _) = local_decl.ty.kind() {
|
||||||
|
*rty
|
||||||
} else {
|
} else {
|
||||||
local_decl.ty
|
bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty);
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(terr) = self.typeck.relate_type_and_user_type(
|
|
||||||
ty,
|
|
||||||
ty::Invariant,
|
|
||||||
user_ty,
|
|
||||||
Locations::All(*span),
|
|
||||||
ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
|
|
||||||
) {
|
|
||||||
span_mirbug!(
|
|
||||||
self,
|
|
||||||
local,
|
|
||||||
"bad user type on variable {:?}: {:?} != {:?} ({:?})",
|
|
||||||
local,
|
|
||||||
local_decl.ty,
|
|
||||||
local_decl.user_ty,
|
|
||||||
terr,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
local_decl.ty
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(terr) = self.typeck.relate_type_and_user_type(
|
||||||
|
ty,
|
||||||
|
ty::Invariant,
|
||||||
|
user_ty,
|
||||||
|
Locations::All(*span),
|
||||||
|
ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
|
||||||
|
) {
|
||||||
|
span_mirbug!(
|
||||||
|
self,
|
||||||
|
local,
|
||||||
|
"bad user type on variable {:?}: {:?} != {:?} ({:?})",
|
||||||
|
local,
|
||||||
|
local_decl.ty,
|
||||||
|
local_decl.user_ty,
|
||||||
|
terr,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue