@@ -9,7 +9,6 @@ use rustc_const_eval::interpret::{
9
9
} ;
10
10
use rustc_hir:: def:: DefKind ;
11
11
use rustc_hir:: HirId ;
12
- use rustc_index:: vec:: IndexSlice ;
13
12
use rustc_middle:: mir:: visit:: Visitor ;
14
13
use rustc_middle:: mir:: * ;
15
14
use rustc_middle:: ty:: layout:: { LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
@@ -130,8 +129,6 @@ struct ConstPropagator<'mir, 'tcx> {
130
129
ecx : InterpCx < ' mir , ' tcx , ConstPropMachine < ' mir , ' tcx > > ,
131
130
tcx : TyCtxt < ' tcx > ,
132
131
param_env : ParamEnv < ' tcx > ,
133
- source_scopes : & ' mir IndexSlice < SourceScope , SourceScopeData < ' tcx > > ,
134
- local_decls : & ' mir IndexSlice < Local , LocalDecl < ' tcx > > ,
135
132
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
136
133
// the last known `SourceInfo` here and just keep revisiting it.
137
134
source_info : Option < SourceInfo > ,
@@ -209,14 +206,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
209
206
)
210
207
. expect ( "failed to push initial stack frame" ) ;
211
208
212
- ConstPropagator {
213
- ecx,
214
- tcx,
215
- param_env,
216
- source_scopes : & dummy_body. source_scopes ,
217
- local_decls : & dummy_body. local_decls ,
218
- source_info : None ,
219
- }
209
+ ConstPropagator { ecx, tcx, param_env, source_info : None }
210
+ }
211
+
212
+ fn body ( & self ) -> & ' mir Body < ' tcx > {
213
+ self . ecx . frame ( ) . body
214
+ }
215
+
216
+ fn local_decls ( & self ) -> & ' mir LocalDecls < ' tcx > {
217
+ & self . body ( ) . local_decls
220
218
}
221
219
222
220
fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
@@ -251,7 +249,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
251
249
}
252
250
253
251
fn lint_root ( & self , source_info : SourceInfo ) -> Option < HirId > {
254
- source_info. scope . lint_root ( self . source_scopes )
252
+ source_info. scope . lint_root ( & self . body ( ) . source_scopes )
255
253
}
256
254
257
255
fn use_ecx < F , T > ( & mut self , source_info : SourceInfo , f : F ) -> Option < T >
@@ -368,7 +366,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
368
366
let r = r. clone ( ) ?;
369
367
// We need the type of the LHS. We cannot use `place_layout` as that is the type
370
368
// of the result, which for checked binops is not the same!
371
- let left_ty = left. ty ( self . local_decls , self . tcx ) ;
369
+ let left_ty = left. ty ( self . local_decls ( ) , self . tcx ) ;
372
370
let left_size = self . ecx . layout_of ( left_ty) . ok ( ) ?. size ;
373
371
let right_size = r. layout . size ;
374
372
let r_bits = r. to_scalar ( ) . to_bits ( right_size) . ok ( ) ;
@@ -481,10 +479,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
481
479
if rvalue. needs_subst ( ) {
482
480
return None ;
483
481
}
484
- if !rvalue
485
- . ty ( & self . ecx . frame ( ) . body . local_decls , * self . ecx . tcx )
486
- . is_sized ( * self . ecx . tcx , self . param_env )
487
- {
482
+ if !rvalue. ty ( self . local_decls ( ) , self . tcx ) . is_sized ( self . tcx , self . param_env ) {
488
483
// the interpreter doesn't support unsized locals (only unsized arguments),
489
484
// but rustc does (in a kinda broken way), so we have to skip them here
490
485
return None ;
@@ -498,7 +493,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
498
493
assert ! (
499
494
self . get_const( local. into( ) ) . is_none( )
500
495
|| self
501
- . layout_of( self . local_decls[ local] . ty)
496
+ . layout_of( self . local_decls( ) [ local] . ty)
502
497
. map_or( true , |layout| layout. is_zst( ) ) ,
503
498
"failed to remove values for `{local:?}`, value={:?}" ,
504
499
self . get_const( local. into( ) ) ,
0 commit comments