@@ -6,14 +6,14 @@ use std::cell::Cell;
66use rustc:: hir:: def:: DefKind ;
77use rustc:: mir:: {
88 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 ,
1111 SourceScope , SourceScopeLocalData , LocalDecl ,
1212} ;
1313use rustc:: mir:: visit:: {
1414 Visitor , PlaceContext , MutatingUseContext , MutVisitor , NonMutatingUseContext ,
1515} ;
16- use rustc:: mir:: interpret:: { Scalar , GlobalId , InterpResult , PanicInfo } ;
16+ use rustc:: mir:: interpret:: { Scalar , InterpResult , PanicInfo } ;
1717use rustc:: ty:: { self , Instance , ParamEnv , Ty , TyCtxt } ;
1818use syntax_pos:: { Span , DUMMY_SP } ;
1919use rustc:: ty:: subst:: InternalSubsts ;
@@ -282,53 +282,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
282282
283283 fn eval_place ( & mut self , place : & Place < ' tcx > , source_info : SourceInfo ) -> Option < Const < ' tcx > > {
284284 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+ } )
332288 }
333289
334290 fn eval_operand ( & mut self , op : & Operand < ' tcx > , source_info : SourceInfo ) -> Option < Const < ' tcx > > {
0 commit comments