@@ -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 replaced 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 replaced 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 ( )
@@ -902,27 +883,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
902
883
proj : ProjectionElem < VnIndex , ( ) > ,
903
884
loc : Location ,
904
885
) -> Option < PlaceElem < ' tcx > > {
905
- Some ( match proj {
906
- ProjectionElem :: Deref => ProjectionElem :: Deref ,
907
- ProjectionElem :: Field ( idx, ( ) ) => ProjectionElem :: Field ( idx, ty) ,
908
- ProjectionElem :: Index ( idx) => {
909
- let Some ( local) = self . try_as_local ( idx, loc) else {
910
- return None ;
911
- } ;
886
+ proj. try_map (
887
+ |value| {
888
+ let local = self . try_as_local ( value, loc) ?;
912
889
self . reused_locals . insert ( local) ;
913
- ProjectionElem :: Index ( local)
914
- }
915
- ProjectionElem :: ConstantIndex { offset, min_length, from_end } => {
916
- ProjectionElem :: ConstantIndex { offset, min_length, from_end }
917
- }
918
- ProjectionElem :: Subslice { from, to, from_end } => {
919
- ProjectionElem :: Subslice { from, to, from_end }
920
- }
921
- ProjectionElem :: Downcast ( symbol, idx) => ProjectionElem :: Downcast ( symbol, idx) ,
922
- ProjectionElem :: OpaqueCast ( ( ) ) => ProjectionElem :: OpaqueCast ( ty) ,
923
- ProjectionElem :: Subtype ( ( ) ) => ProjectionElem :: Subtype ( ty) ,
924
- ProjectionElem :: UnwrapUnsafeBinder ( ( ) ) => ProjectionElem :: UnwrapUnsafeBinder ( ty) ,
925
- } )
890
+ Some ( local)
891
+ } ,
892
+ |( ) | ty,
893
+ )
926
894
}
927
895
928
896
fn simplify_aggregate_to_copy (
0 commit comments