Handle typeck errors properly
This commit is contained in:
parent
3797b0335a
commit
3f31044d90
3 changed files with 9 additions and 1 deletions
|
@ -220,7 +220,7 @@ rustc_queries! {
|
||||||
desc { "checking if the crate is_panic_runtime" }
|
desc { "checking if the crate is_panic_runtime" }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the THIR for a given body.
|
/// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
|
||||||
query thir_body(key: ty::WithOptConstParam<LocalDefId>) -> (&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId) {
|
query thir_body(key: ty::WithOptConstParam<LocalDefId>) -> (&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId) {
|
||||||
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
|
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,6 +331,11 @@ impl UnsafeOpKind {
|
||||||
pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) {
|
pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) {
|
||||||
let (thir, expr) = tcx.thir_body(def);
|
let (thir, expr) = tcx.thir_body(def);
|
||||||
let thir = &thir.borrow();
|
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 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| {
|
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 {
|
if fn_sig.header.unsafety == hir::Unsafety::Unsafe {
|
||||||
|
|
|
@ -23,6 +23,9 @@ crate fn thir_body<'tcx>(
|
||||||
let hir = tcx.hir();
|
let hir = tcx.hir();
|
||||||
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(owner_def.did)));
|
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);
|
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);
|
let expr = cx.mirror_expr(&body.value);
|
||||||
(tcx.alloc_steal_thir(cx.thir), expr)
|
(tcx.alloc_steal_thir(cx.thir), expr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue