Don't skip mir typeck if body has errors
This commit is contained in:
parent
b3cbf7c835
commit
b1387e776c
1 changed files with 9 additions and 27 deletions
|
@ -183,17 +183,10 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
&mut borrowck_context,
|
&mut borrowck_context,
|
||||||
);
|
);
|
||||||
|
|
||||||
let errors_reported = {
|
let mut verifier = TypeVerifier::new(&mut checker, promoted);
|
||||||
let mut verifier = TypeVerifier::new(&mut checker, promoted);
|
verifier.visit_body(&body);
|
||||||
verifier.visit_body(&body);
|
|
||||||
verifier.errors_reported
|
|
||||||
};
|
|
||||||
|
|
||||||
if !errors_reported {
|
|
||||||
// if verifier failed, don't do further checks to avoid ICEs
|
|
||||||
checker.typeck_mir(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
checker.typeck_mir(body);
|
||||||
checker.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
checker.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
||||||
checker.check_signature_annotation(&body);
|
checker.check_signature_annotation(&body);
|
||||||
|
|
||||||
|
@ -294,7 +287,6 @@ struct TypeVerifier<'a, 'b, 'tcx> {
|
||||||
cx: &'a mut TypeChecker<'b, 'tcx>,
|
cx: &'a mut TypeChecker<'b, 'tcx>,
|
||||||
promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
|
promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
|
||||||
last_span: Span,
|
last_span: Span,
|
||||||
errors_reported: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||||
|
@ -383,13 +375,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if !self.errors_reported {
|
let promoted_body = &self.promoted[promoted];
|
||||||
let promoted_body = &self.promoted[promoted];
|
self.sanitize_promoted(promoted_body, location);
|
||||||
self.sanitize_promoted(promoted_body, location);
|
|
||||||
|
|
||||||
let promoted_ty = promoted_body.return_ty();
|
let promoted_ty = promoted_body.return_ty();
|
||||||
check_err(self, promoted_body, ty, promoted_ty);
|
check_err(self, promoted_body, ty, promoted_ty);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
self.cx.ascribe_user_type(
|
self.cx.ascribe_user_type(
|
||||||
constant.literal.ty(),
|
constant.literal.ty(),
|
||||||
|
@ -483,9 +473,6 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||||
for local_decl in &body.local_decls {
|
for local_decl in &body.local_decls {
|
||||||
self.sanitize_type(local_decl, local_decl.ty);
|
self.sanitize_type(local_decl, local_decl.ty);
|
||||||
}
|
}
|
||||||
if self.errors_reported {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.super_body(body);
|
self.super_body(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,7 +482,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||||
cx: &'a mut TypeChecker<'b, 'tcx>,
|
cx: &'a mut TypeChecker<'b, 'tcx>,
|
||||||
promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
|
promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
TypeVerifier { promoted, last_span: cx.body.span, cx, errors_reported: false }
|
TypeVerifier { promoted, last_span: cx.body.span, cx }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body(&self) -> &Body<'tcx> {
|
fn body(&self) -> &Body<'tcx> {
|
||||||
|
@ -529,7 +516,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||||
for elem in place.projection.iter() {
|
for elem in place.projection.iter() {
|
||||||
if place_ty.variant_index.is_none() {
|
if place_ty.variant_index.is_none() {
|
||||||
if let Err(guar) = place_ty.ty.error_reported() {
|
if let Err(guar) = place_ty.ty.error_reported() {
|
||||||
assert!(self.errors_reported);
|
|
||||||
return PlaceTy::from_ty(self.tcx().ty_error(guar));
|
return PlaceTy::from_ty(self.tcx().ty_error(guar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -593,10 +579,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
self.visit_body(&promoted_body);
|
self.visit_body(&promoted_body);
|
||||||
|
|
||||||
if !self.errors_reported {
|
self.cx.typeck_mir(promoted_body);
|
||||||
// if verifier failed, don't do further checks to avoid ICEs
|
|
||||||
self.cx.typeck_mir(promoted_body);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.cx.body = parent_body;
|
self.cx.body = parent_body;
|
||||||
// Merge the outlives constraints back in, at the given location.
|
// Merge the outlives constraints back in, at the given location.
|
||||||
|
@ -762,7 +745,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error(&mut self) -> Ty<'tcx> {
|
fn error(&mut self) -> Ty<'tcx> {
|
||||||
self.errors_reported = true;
|
|
||||||
self.tcx().ty_error_misc()
|
self.tcx().ty_error_misc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue