@@ -447,26 +447,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
447447
448448 Projection ( base, elem) => {
449449 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 ) ?;
470453 self . ecx . project ( base, elem) . discard_err ( ) ?
471454 }
472455 Address { place, kind : _, provenance : _ } => {
@@ -476,13 +459,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
476459 let local = self . locals [ place. local ] ?;
477460 let pointer = self . evaluated [ local] . as_ref ( ) ?;
478461 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 ( ) ?;
486467 }
487468 let pointer = mplace. to_ref ( & self . ecx ) ;
488469 ImmTy :: from_immediate ( pointer, ty) . into ( )
@@ -902,27 +883,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
902883 proj : ProjectionElem < VnIndex , ( ) > ,
903884 loc : Location ,
904885 ) -> 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) ?;
912889 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+ )
926894 }
927895
928896 fn simplify_aggregate_to_copy (
0 commit comments