This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +9
-1
lines changed Expand file tree Collapse file tree 3 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,7 @@ rustc_queries! {
220220 desc { "checking if the crate is_panic_runtime" }
221221 }
222222
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`.
224224 query thir_body( key: ty:: WithOptConstParam <LocalDefId >) -> ( & ' tcx Steal <thir:: Thir <' tcx>>, thir:: ExprId ) {
225225 desc { |tcx| "building THIR for `{}`" , tcx. def_path_str( key. did. to_def_id( ) ) }
226226 }
Original file line number Diff line number Diff line change @@ -331,6 +331,11 @@ impl UnsafeOpKind {
331331pub fn check_unsafety < ' tcx > ( tcx : TyCtxt < ' tcx > , def : ty:: WithOptConstParam < LocalDefId > ) {
332332 let ( thir, expr) = tcx. thir_body ( def) ;
333333 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+
334339 let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
335340 let body_unsafety = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) . map_or ( BodyUnsafety :: Safe , |fn_sig| {
336341 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>(
2323 let hir = tcx. hir ( ) ;
2424 let body = hir. body ( hir. body_owned_by ( hir. local_def_id_to_hir_id ( owner_def. did ) ) ) ;
2525 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+ }
2629 let expr = cx. mirror_expr ( & body. value ) ;
2730 ( tcx. alloc_steal_thir ( cx. thir ) , expr)
2831}
You can’t perform that action at this time.
0 commit comments