Handle typeck errors properly
This commit is contained in:
parent
3797b0335a
commit
3f31044d90
3 changed files with 9 additions and 1 deletions
|
@ -331,6 +331,11 @@ impl UnsafeOpKind {
|
|||
pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) {
|
||||
let (thir, expr) = tcx.thir_body(def);
|
||||
let thir = &thir.borrow();
|
||||
// If `thir` is empty, a type error occured, skip this body.
|
||||
if thir.exprs.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
||||
let body_unsafety = tcx.hir().fn_sig_by_hir_id(hir_id).map_or(BodyUnsafety::Safe, |fn_sig| {
|
||||
if fn_sig.header.unsafety == hir::Unsafety::Unsafe {
|
||||
|
|
|
@ -23,6 +23,9 @@ crate fn thir_body<'tcx>(
|
|||
let hir = tcx.hir();
|
||||
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(owner_def.did)));
|
||||
let mut cx = Cx::new(tcx, owner_def);
|
||||
if cx.typeck_results.tainted_by_errors.is_some() {
|
||||
return (tcx.alloc_steal_thir(Thir::new()), ExprId::from_u32(0));
|
||||
}
|
||||
let expr = cx.mirror_expr(&body.value);
|
||||
(tcx.alloc_steal_thir(cx.thir), expr)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue