@@ -1088,8 +1088,18 @@ pub enum TerminatorKind<'tcx> {
1088
1088
/// Indicates a terminator that can never be reached.
1089
1089
Unreachable ,
1090
1090
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
+ } ,
1093
1103
1094
1104
/// Drop the `Place` and assign the new value over it. This ensures
1095
1105
/// that the assignment to `P` occurs *even if* the destructor for
@@ -1464,7 +1474,10 @@ impl<'tcx> TerminatorKind<'tcx> {
1464
1474
Abort => write ! ( fmt, "abort" ) ,
1465
1475
Yield { ref value, .. } => write ! ( fmt, "_1 = suspend({:?})" , value) ,
1466
1476
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) ,
1468
1481
DropAndReplace { ref location, ref value, .. } => {
1469
1482
write ! ( fmt, "replace({:?} <- {:?})" , location, value)
1470
1483
}
@@ -2967,8 +2980,13 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
2967
2980
values : values. clone ( ) ,
2968
2981
targets : targets. clone ( ) ,
2969
2982
} ,
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
+ }
2972
2990
}
2973
2991
DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
2974
2992
location : location. fold_with ( folder) ,
@@ -3025,7 +3043,9 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
3025
3043
SwitchInt { ref discr, switch_ty, .. } => {
3026
3044
discr. visit_with ( visitor) || switch_ty. visit_with ( visitor)
3027
3045
}
3028
- Drop { ref location, .. } => location. visit_with ( visitor) ,
3046
+ Drop { ref location, ref flag, .. } => {
3047
+ location. visit_with ( visitor) || flag. visit_with ( visitor)
3048
+ } ,
3029
3049
DropAndReplace { ref location, ref value, .. } => {
3030
3050
location. visit_with ( visitor) || value. visit_with ( visitor)
3031
3051
}
0 commit comments