@@ -440,15 +440,21 @@ impl<'tcx> Visitor<'tcx> for ConvertVisitor<'tcx> {
440
440
. any ( |x| matches ! ( x. desc, MirOriginDesc :: Adjustment ( _) ) ) ;
441
441
if self . materialize_adjustments || has_adjustment_rewrites {
442
442
let adjusts = self . typeck_results . expr_adjustments ( ex) ;
443
- hir_rw = materialize_adjustments ( self . tcx , adjusts, hir_rw, |i, mut hir_rw| {
444
- let load_rws = take_prefix_while ( & mut mir_rws, |x| {
445
- x. desc == MirOriginDesc :: LoadFromTempForAdjustment ( i)
443
+ hir_rw =
444
+ materialize_adjustments ( self . tcx , adjusts, hir_rw, |step, hir_rw| match step {
445
+ AdjustmentStep :: Before ( i) => {
446
+ let load_rws = take_prefix_while ( & mut mir_rws, |x| {
447
+ x. desc == MirOriginDesc :: LoadFromTempForAdjustment ( i)
448
+ } ) ;
449
+ self . rewrite_from_mir_rws ( Some ( ex) , load_rws, hir_rw)
450
+ }
451
+ AdjustmentStep :: After ( i) => {
452
+ let adj_rws = take_prefix_while ( & mut mir_rws, |x| {
453
+ x. desc == MirOriginDesc :: Adjustment ( i)
454
+ } ) ;
455
+ self . rewrite_from_mir_rws ( Some ( ex) , adj_rws, hir_rw)
456
+ }
446
457
} ) ;
447
- hir_rw = self . rewrite_from_mir_rws ( Some ( ex) , load_rws, hir_rw) ;
448
- let adj_rws =
449
- take_prefix_while ( & mut mir_rws, |x| x. desc == MirOriginDesc :: Adjustment ( i) ) ;
450
- self . rewrite_from_mir_rws ( Some ( ex) , adj_rws, hir_rw)
451
- } ) ;
452
458
}
453
459
454
460
// Apply late rewrites.
@@ -517,31 +523,37 @@ fn apply_adjustment<'tcx>(
517
523
}
518
524
}
519
525
526
+ enum AdjustmentStep {
527
+ Before ( usize ) ,
528
+ After ( usize ) ,
529
+ }
530
+
520
531
fn materialize_adjustments < ' tcx > (
521
532
tcx : TyCtxt < ' tcx > ,
522
533
adjustments : & [ Adjustment < ' tcx > ] ,
523
534
hir_rw : Rewrite ,
524
- mut callback : impl FnMut ( usize , Rewrite ) -> Rewrite ,
535
+ mut callback : impl FnMut ( AdjustmentStep , Rewrite ) -> Rewrite ,
525
536
) -> Rewrite {
526
537
let adj_kinds: Vec < & _ > = adjustments. iter ( ) . map ( |a| & a. kind ) . collect ( ) ;
527
538
match ( hir_rw, & adj_kinds[ ..] ) {
528
539
// The mut-to-const cast should be unneeded once the inner rewrite switches to a safe
529
540
// reference type appropriate for the pointer's uses. However, we still want to give
530
541
// `callback` a chance to remove the cast itself so that if there's a `RemoveCast` rewrite
531
542
// on this adjustment, we don't get an error about it failing to apply.
532
- ( rw, & [ Adjust :: Pointer ( PointerCast :: MutToConstPointer ) ] ) => {
533
- let mut hir_rw = Rewrite :: RemovedCast ( Box :: new ( rw) ) ;
534
- hir_rw = callback ( 0 , hir_rw) ;
543
+ ( mut hir_rw, & [ Adjust :: Pointer ( PointerCast :: MutToConstPointer ) ] ) => {
544
+ hir_rw = callback ( AdjustmentStep :: Before ( 0 ) , hir_rw) ;
545
+ hir_rw = Rewrite :: RemovedCast ( Box :: new ( hir_rw) ) ;
546
+ hir_rw = callback ( AdjustmentStep :: After ( 0 ) , hir_rw) ;
535
547
match hir_rw {
536
548
Rewrite :: RemovedCast ( rw) => * rw,
537
549
rw => rw,
538
550
}
539
551
}
540
- ( rw, _) => {
541
- let mut hir_rw = rw;
552
+ ( mut hir_rw, _) => {
542
553
for ( i, adj) in adjustments. iter ( ) . enumerate ( ) {
554
+ hir_rw = callback ( AdjustmentStep :: Before ( i) , hir_rw) ;
543
555
hir_rw = apply_adjustment ( tcx, adj, hir_rw) ;
544
- hir_rw = callback ( i , hir_rw) ;
556
+ hir_rw = callback ( AdjustmentStep :: After ( i ) , hir_rw) ;
545
557
}
546
558
hir_rw
547
559
}
0 commit comments