@@ -201,9 +201,14 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
201
201
/// Handle closures/coroutines/inline-consts, which is unsafecked with their parent body.
202
202
fn visit_inner_body ( & mut self , def : LocalDefId ) {
203
203
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.
205
205
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
+ } ;
207
212
let hir_context = self . tcx . local_def_id_to_hir_id ( def) ;
208
213
let safety_context = mem:: replace ( & mut self . safety_context , SafetyContext :: Safe ) ;
209
214
let mut inner_visitor = UnsafetyVisitor {
@@ -1157,7 +1162,12 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
1157
1162
let Ok ( ( thir, expr) ) = tcx. thir_body ( def) else { return } ;
1158
1163
// Runs all other queries that depend on THIR.
1159
1164
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
+ } ;
1161
1171
1162
1172
let hir_id = tcx. local_def_id_to_hir_id ( def) ;
1163
1173
let safety_context = tcx. hir_fn_sig_by_hir_id ( hir_id) . map_or ( SafetyContext :: Safe , |fn_sig| {
0 commit comments