@@ -1088,8 +1088,18 @@ pub enum TerminatorKind<'tcx> {
10881088 /// Indicates a terminator that can never be reached.
10891089 Unreachable ,
10901090
1091- /// Drop the `Place`.
1092- Drop { location : Place < ' tcx > , target : BasicBlock , unwind : Option < BasicBlock > } ,
1091+ /// Drop the `Place`, possibly conditioned on a flag being true.
1092+ Drop {
1093+ location : Place < ' tcx > ,
1094+ /// Whether to drop the value.
1095+ ///
1096+ /// Before drop elaboration this is always `None. After drop elaboration
1097+ /// If this is `None` then the drop is unconditional, otherwise the drop
1098+ /// is only evaluated when the flag is true.
1099+ flag : Option < Place < ' tcx > > ,
1100+ target : BasicBlock ,
1101+ unwind : Option < BasicBlock > ,
1102+ } ,
10931103
10941104 /// Drop the `Place` and assign the new value over it. This ensures
10951105 /// that the assignment to `P` occurs *even if* the destructor for
@@ -1464,7 +1474,10 @@ impl<'tcx> TerminatorKind<'tcx> {
14641474 Abort => write ! ( fmt, "abort" ) ,
14651475 Yield { ref value, .. } => write ! ( fmt, "_1 = suspend({:?})" , value) ,
14661476 Unreachable => write ! ( fmt, "unreachable" ) ,
1467- Drop { ref location, .. } => write ! ( fmt, "drop({:?})" , location) ,
1477+ Drop { ref location, flag : Some ( ref flag) , .. } => {
1478+ write ! ( fmt, "if {:?} drop({:?})" , flag, location)
1479+ }
1480+ Drop { ref location, flag : None , .. } => write ! ( fmt, "drop({:?})" , location) ,
14681481 DropAndReplace { ref location, ref value, .. } => {
14691482 write ! ( fmt, "replace({:?} <- {:?})" , location, value)
14701483 }
@@ -2967,8 +2980,13 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
29672980 values : values. clone ( ) ,
29682981 targets : targets. clone ( ) ,
29692982 } ,
2970- Drop { ref location, target, unwind } => {
2971- Drop { location : location. fold_with ( folder) , target, unwind }
2983+ Drop { ref location, ref flag, target, unwind } => {
2984+ Drop {
2985+ location : location. fold_with ( folder) ,
2986+ flag : flag. fold_with ( folder) ,
2987+ target,
2988+ unwind,
2989+ }
29722990 }
29732991 DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
29742992 location : location. fold_with ( folder) ,
@@ -3025,7 +3043,9 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
30253043 SwitchInt { ref discr, switch_ty, .. } => {
30263044 discr. visit_with ( visitor) || switch_ty. visit_with ( visitor)
30273045 }
3028- Drop { ref location, .. } => location. visit_with ( visitor) ,
3046+ Drop { ref location, ref flag, .. } => {
3047+ location. visit_with ( visitor) || flag. visit_with ( visitor)
3048+ } ,
30293049 DropAndReplace { ref location, ref value, .. } => {
30303050 location. visit_with ( visitor) || value. visit_with ( visitor)
30313051 }
0 commit comments