@@ -6,14 +6,14 @@ use std::cell::Cell;
6
6
use rustc:: hir:: def:: DefKind ;
7
7
use rustc:: mir:: {
8
8
AggregateKind , Constant , Location , Place , PlaceBase , Body , Operand , Rvalue ,
9
- Local , NullOp , UnOp , StatementKind , Statement , LocalKind , Static , StaticKind ,
10
- TerminatorKind , Terminator , ClearCrossCrate , SourceInfo , BinOp , ProjectionElem ,
9
+ Local , NullOp , UnOp , StatementKind , Statement , LocalKind ,
10
+ TerminatorKind , Terminator , ClearCrossCrate , SourceInfo , BinOp ,
11
11
SourceScope , SourceScopeLocalData , LocalDecl ,
12
12
} ;
13
13
use rustc:: mir:: visit:: {
14
14
Visitor , PlaceContext , MutatingUseContext , MutVisitor , NonMutatingUseContext ,
15
15
} ;
16
- use rustc:: mir:: interpret:: { Scalar , GlobalId , InterpResult , PanicInfo } ;
16
+ use rustc:: mir:: interpret:: { Scalar , InterpResult , PanicInfo } ;
17
17
use rustc:: ty:: { self , Instance , ParamEnv , Ty , TyCtxt } ;
18
18
use syntax_pos:: { Span , DUMMY_SP } ;
19
19
use rustc:: ty:: subst:: InternalSubsts ;
@@ -282,53 +282,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
282
282
283
283
fn eval_place ( & mut self , place : & Place < ' tcx > , source_info : SourceInfo ) -> Option < Const < ' tcx > > {
284
284
trace ! ( "eval_place(place={:?})" , place) ;
285
- let mut eval = match place. base {
286
- PlaceBase :: Local ( loc) => self . get_const ( loc) . clone ( ) ?,
287
- PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( promoted, _) , ..} ) => {
288
- let generics = self . tcx . generics_of ( self . source . def_id ( ) ) ;
289
- if generics. requires_monomorphization ( self . tcx ) {
290
- // FIXME: can't handle code with generics
291
- return None ;
292
- }
293
- let substs = InternalSubsts :: identity_for_item ( self . tcx , self . source . def_id ( ) ) ;
294
- let instance = Instance :: new ( self . source . def_id ( ) , substs) ;
295
- let cid = GlobalId {
296
- instance,
297
- promoted : Some ( promoted) ,
298
- } ;
299
- let res = self . use_ecx ( source_info, |this| {
300
- this. ecx . const_eval_raw ( cid)
301
- } ) ?;
302
- trace ! ( "evaluated promoted {:?} to {:?}" , promoted, res) ;
303
- res. into ( )
304
- }
305
- _ => return None ,
306
- } ;
307
-
308
- for ( i, elem) in place. projection . iter ( ) . enumerate ( ) {
309
- let proj_base = & place. projection [ ..i] ;
310
-
311
- match elem {
312
- ProjectionElem :: Field ( field, _) => {
313
- trace ! ( "field proj on {:?}" , proj_base) ;
314
- eval = self . use_ecx ( source_info, |this| {
315
- this. ecx . operand_field ( eval, field. index ( ) as u64 )
316
- } ) ?;
317
- } ,
318
- ProjectionElem :: Deref => {
319
- trace ! ( "processing deref" ) ;
320
- eval = self . use_ecx ( source_info, |this| {
321
- this. ecx . deref_operand ( eval)
322
- } ) ?. into ( ) ;
323
- }
324
- // We could get more projections by using e.g., `operand_projection`,
325
- // but we do not even have the stack frame set up properly so
326
- // an `Index` projection would throw us off-track.
327
- _ => return None ,
328
- }
329
- }
330
-
331
- Some ( eval)
285
+ self . use_ecx ( source_info, |this| {
286
+ this. ecx . eval_place_to_op ( place, None )
287
+ } )
332
288
}
333
289
334
290
fn eval_operand ( & mut self , op : & Operand < ' tcx > , source_info : SourceInfo ) -> Option < Const < ' tcx > > {
0 commit comments