@@ -447,26 +447,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
447
447
448
448
Projection ( base, elem) => {
449
449
let base = self . evaluated [ base] . as_ref ( ) ?;
450
- let elem = match elem {
451
- ProjectionElem :: Deref => ProjectionElem :: Deref ,
452
- ProjectionElem :: Downcast ( name, read_variant) => {
453
- ProjectionElem :: Downcast ( name, read_variant)
454
- }
455
- ProjectionElem :: Field ( f, ( ) ) => ProjectionElem :: Field ( f, ty. ty ) ,
456
- ProjectionElem :: ConstantIndex { offset, min_length, from_end } => {
457
- ProjectionElem :: ConstantIndex { offset, min_length, from_end }
458
- }
459
- ProjectionElem :: Subslice { from, to, from_end } => {
460
- ProjectionElem :: Subslice { from, to, from_end }
461
- }
462
- ProjectionElem :: OpaqueCast ( ( ) ) => ProjectionElem :: OpaqueCast ( ty. ty ) ,
463
- ProjectionElem :: Subtype ( ( ) ) => ProjectionElem :: Subtype ( ty. ty ) ,
464
- ProjectionElem :: UnwrapUnsafeBinder ( ( ) ) => {
465
- ProjectionElem :: UnwrapUnsafeBinder ( ty. ty )
466
- }
467
- // This should have been replaced by a `ConstantIndex` earlier.
468
- ProjectionElem :: Index ( _) => return None ,
469
- } ;
450
+ // `Index` by constants should have been replaces by `ConstantIndex` by
451
+ // `simplify_place_projection`.
452
+ let elem = elem. try_map ( |_| None , |( ) | ty. ty ) ?;
470
453
self . ecx . project ( base, elem) . discard_err ( ) ?
471
454
}
472
455
Address { place, kind : _, provenance : _ } => {
@@ -476,13 +459,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
476
459
let local = self . locals [ place. local ] ?;
477
460
let pointer = self . evaluated [ local] . as_ref ( ) ?;
478
461
let mut mplace = self . ecx . deref_pointer ( pointer) . discard_err ( ) ?;
479
- for proj in place. projection . iter ( ) . skip ( 1 ) {
480
- // We have no call stack to associate a local with a value, so we cannot
481
- // interpret indexing.
482
- if matches ! ( proj, ProjectionElem :: Index ( _) ) {
483
- return None ;
484
- }
485
- mplace = self . ecx . project ( & mplace, proj) . discard_err ( ) ?;
462
+ for elem in place. projection . iter ( ) . skip ( 1 ) {
463
+ // `Index` by constants should have been replaces by `ConstantIndex` by
464
+ // `simplify_place_projection`.
465
+ let elem = elem. try_map ( |_| None , |ty| ty) ?;
466
+ mplace = self . ecx . project ( & mplace, elem) . discard_err ( ) ?;
486
467
}
487
468
let pointer = mplace. to_ref ( & self . ecx ) ;
488
469
ImmTy :: from_immediate ( pointer, ty) . into ( )
@@ -891,27 +872,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
891
872
proj : ProjectionElem < VnIndex , ( ) > ,
892
873
loc : Location ,
893
874
) -> Option < PlaceElem < ' tcx > > {
894
- Some ( match proj {
895
- ProjectionElem :: Deref => ProjectionElem :: Deref ,
896
- ProjectionElem :: Field ( idx, ( ) ) => ProjectionElem :: Field ( idx, ty) ,
897
- ProjectionElem :: Index ( idx) => {
898
- let Some ( local) = self . try_as_local ( idx, loc) else {
899
- return None ;
900
- } ;
875
+ proj. try_map (
876
+ |value| {
877
+ let local = self . try_as_local ( value, loc) ?;
901
878
self . reused_locals . insert ( local) ;
902
- ProjectionElem :: Index ( local)
903
- }
904
- ProjectionElem :: ConstantIndex { offset, min_length, from_end } => {
905
- ProjectionElem :: ConstantIndex { offset, min_length, from_end }
906
- }
907
- ProjectionElem :: Subslice { from, to, from_end } => {
908
- ProjectionElem :: Subslice { from, to, from_end }
909
- }
910
- ProjectionElem :: Downcast ( symbol, idx) => ProjectionElem :: Downcast ( symbol, idx) ,
911
- ProjectionElem :: OpaqueCast ( ( ) ) => ProjectionElem :: OpaqueCast ( ty) ,
912
- ProjectionElem :: Subtype ( ( ) ) => ProjectionElem :: Subtype ( ty) ,
913
- ProjectionElem :: UnwrapUnsafeBinder ( ( ) ) => ProjectionElem :: UnwrapUnsafeBinder ( ty) ,
914
- } )
879
+ Some ( local)
880
+ } ,
881
+ |( ) | ty,
882
+ )
915
883
}
916
884
917
885
fn simplify_aggregate_to_copy (
0 commit comments