@@ -101,19 +101,19 @@ impl<'tcx> From<ImmTy<'tcx>> for Value<'tcx> {
101
101
}
102
102
103
103
impl < ' tcx > Value < ' tcx > {
104
- fn project (
105
- & self ,
106
- proj : impl Iterator < Item = Option < ProjectionElem < FieldIdx , Ty < ' tcx > > > > ,
107
- ) -> Option < & Value < ' tcx > > {
104
+ fn project ( & self , proj : impl Iterator < Item = Option < PlaceElem < ' tcx > > > ) -> Option < & Value < ' tcx > > {
108
105
let mut this = self ;
109
106
for proj in proj {
110
107
this = match ( proj?, this) {
111
108
( ProjectionElem :: Field ( idx, _) , Value :: Aggregate { fields, .. } ) => {
112
109
fields. get ( idx) . unwrap_or ( & Value :: Uninit )
113
110
}
114
- ( ProjectionElem :: Index ( idx) , Value :: Aggregate { fields, .. } ) => {
115
- fields. get ( idx) . unwrap_or ( & Value :: Uninit )
116
- }
111
+ (
112
+ ProjectionElem :: ConstantIndex { offset, min_length : 1 , from_end : false } ,
113
+ Value :: Aggregate { fields, .. } ,
114
+ ) => fields
115
+ . get ( FieldIdx :: from_u32 ( offset. try_into ( ) . ok ( ) ?) )
116
+ . unwrap_or ( & Value :: Uninit ) ,
117
117
_ => return None ,
118
118
} ;
119
119
}
@@ -205,7 +205,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
205
205
206
206
fn get_const ( & self , place : Place < ' tcx > ) -> Option < & Value < ' tcx > > {
207
207
self . locals [ place. local ]
208
- . project ( place. projection . iter ( ) . map ( |proj| self . simple_projection ( proj) ) )
208
+ . project ( place. projection . iter ( ) . map ( |proj| self . try_eval_index_offset ( proj) ) )
209
209
}
210
210
211
211
/// Remove `local` from the pool of `Locals`. Allows writing to them,
@@ -719,29 +719,18 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
719
719
Some ( ( ) )
720
720
}
721
721
722
- fn simple_projection (
723
- & self ,
724
- proj : ProjectionElem < Local , Ty < ' tcx > > ,
725
- ) -> Option < ProjectionElem < FieldIdx , Ty < ' tcx > > > {
722
+ fn try_eval_index_offset ( & self , proj : PlaceElem < ' tcx > ) -> Option < PlaceElem < ' tcx > > {
726
723
Some ( match proj {
727
- ProjectionElem :: Deref => ProjectionElem :: Deref ,
728
- ProjectionElem :: Field ( idx, ty) => ProjectionElem :: Field ( idx, ty) ,
729
724
ProjectionElem :: Index ( local) => {
730
725
let val = self . get_const ( local. into ( ) ) ?;
731
726
let op = val. immediate ( ) ?;
732
- ProjectionElem :: Index ( FieldIdx :: from_u32 (
733
- self . ecx . read_target_usize ( op) . ok ( ) ?. try_into ( ) . ok ( ) ?,
734
- ) )
735
- }
736
- ProjectionElem :: ConstantIndex { offset, min_length, from_end } => {
737
- ProjectionElem :: ConstantIndex { offset, min_length, from_end }
738
- }
739
- ProjectionElem :: Subslice { from, to, from_end } => {
740
- ProjectionElem :: Subslice { from, to, from_end }
727
+ ProjectionElem :: ConstantIndex {
728
+ offset : self . ecx . read_target_usize ( op) . ok ( ) ?,
729
+ min_length : 1 ,
730
+ from_end : false ,
731
+ }
741
732
}
742
- ProjectionElem :: Downcast ( a, b) => ProjectionElem :: Downcast ( a, b) ,
743
- ProjectionElem :: OpaqueCast ( ty) => ProjectionElem :: OpaqueCast ( ty) ,
744
- ProjectionElem :: Subtype ( ty) => ProjectionElem :: Subtype ( ty) ,
733
+ other => other,
745
734
} )
746
735
}
747
736
}
0 commit comments