@@ -201,9 +201,14 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
201201 /// Handle closures/coroutines/inline-consts, which is unsafecked with their parent body.
202202 fn visit_inner_body ( & mut self , def : LocalDefId ) {
203203 if let Ok ( ( inner_thir, expr) ) = self . tcx . thir_body ( def) {
204- // Runs all other queries that depend on THIR.
204+ // Run all other queries that depend on THIR.
205205 self . tcx . ensure_done ( ) . mir_built ( def) ;
206- let inner_thir = & inner_thir. steal ( ) ;
206+ let inner_thir = if self . tcx . sess . opts . unstable_opts . no_steal_thir {
207+ & inner_thir. borrow ( )
208+ } else {
209+ // We don't have other use for the THIR. Steal it to reduce memory usage.
210+ & inner_thir. steal ( )
211+ } ;
207212 let hir_context = self . tcx . local_def_id_to_hir_id ( def) ;
208213 let safety_context = mem:: replace ( & mut self . safety_context , SafetyContext :: Safe ) ;
209214 let mut inner_visitor = UnsafetyVisitor {
@@ -1157,7 +1162,12 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
11571162 let Ok ( ( thir, expr) ) = tcx. thir_body ( def) else { return } ;
11581163 // Runs all other queries that depend on THIR.
11591164 tcx. ensure_done ( ) . mir_built ( def) ;
1160- let thir = & thir. steal ( ) ;
1165+ let thir = if tcx. sess . opts . unstable_opts . no_steal_thir {
1166+ & thir. borrow ( )
1167+ } else {
1168+ // We don't have other use for the THIR. Steal it to reduce memory usage.
1169+ & thir. steal ( )
1170+ } ;
11611171
11621172 let hir_id = tcx. local_def_id_to_hir_id ( def) ;
11631173 let safety_context = tcx. hir_fn_sig_by_hir_id ( hir_id) . map_or ( SafetyContext :: Safe , |fn_sig| {
0 commit comments