File tree 3 files changed +9
-1
lines changed
3 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,7 @@ rustc_queries! {
220
220
desc { "checking if the crate is_panic_runtime" }
221
221
}
222
222
223
- /// Fetch the THIR for a given body.
223
+ /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
224
224
query thir_body( key: ty:: WithOptConstParam <LocalDefId >) -> ( & ' tcx Steal <thir:: Thir <' tcx>>, thir:: ExprId ) {
225
225
desc { |tcx| "building THIR for `{}`" , tcx. def_path_str( key. did. to_def_id( ) ) }
226
226
}
Original file line number Diff line number Diff line change @@ -331,6 +331,11 @@ impl UnsafeOpKind {
331
331
pub fn check_unsafety < ' tcx > ( tcx : TyCtxt < ' tcx > , def : ty:: WithOptConstParam < LocalDefId > ) {
332
332
let ( thir, expr) = tcx. thir_body ( def) ;
333
333
let thir = & thir. borrow ( ) ;
334
+ // If `thir` is empty, a type error occured, skip this body.
335
+ if thir. exprs . is_empty ( ) {
336
+ return ;
337
+ }
338
+
334
339
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
335
340
let body_unsafety = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) . map_or ( BodyUnsafety :: Safe , |fn_sig| {
336
341
if fn_sig. header . unsafety == hir:: Unsafety :: Unsafe {
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ crate fn thir_body<'tcx>(
23
23
let hir = tcx. hir ( ) ;
24
24
let body = hir. body ( hir. body_owned_by ( hir. local_def_id_to_hir_id ( owner_def. did ) ) ) ;
25
25
let mut cx = Cx :: new ( tcx, owner_def) ;
26
+ if cx. typeck_results . tainted_by_errors . is_some ( ) {
27
+ return ( tcx. alloc_steal_thir ( Thir :: new ( ) ) , ExprId :: from_u32 ( 0 ) ) ;
28
+ }
26
29
let expr = cx. mirror_expr ( & body. value ) ;
27
30
( tcx. alloc_steal_thir ( cx. thir ) , expr)
28
31
}
You can’t perform that action at this time.
0 commit comments