@@ -91,7 +91,7 @@ use rustc_middle::middle::region;
91
91
use rustc_middle:: mir:: * ;
92
92
use rustc_middle:: thir:: { Expr , LintLevel } ;
93
93
94
- use rustc_span:: { Span , DUMMY_SP } ;
94
+ use rustc_span:: { DesugaringKind , Span , DUMMY_SP } ;
95
95
96
96
#[ derive( Debug ) ]
97
97
pub struct Scopes < ' tcx > {
@@ -1118,24 +1118,35 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1118
1118
}
1119
1119
1120
1120
/// Utility function for *non*-scope code to build their own drops
1121
+ /// Force a drop at this point in the MIR by creating a new block.
1121
1122
pub ( crate ) fn build_drop_and_replace (
1122
1123
& mut self ,
1123
1124
block : BasicBlock ,
1124
1125
span : Span ,
1125
1126
place : Place < ' tcx > ,
1126
- value : Operand < ' tcx > ,
1127
+ value : Rvalue < ' tcx > ,
1127
1128
) -> BlockAnd < ( ) > {
1129
+ let span = self . tcx . with_stable_hashing_context ( |hcx| {
1130
+ span. mark_with_reason ( None , DesugaringKind :: Replace , self . tcx . sess . edition ( ) , hcx)
1131
+ } ) ;
1128
1132
let source_info = self . source_info ( span) ;
1129
- let next_target = self . cfg . start_new_block ( ) ;
1133
+
1134
+ // create the new block for the assignment
1135
+ let assign = self . cfg . start_new_block ( ) ;
1136
+ self . cfg . push_assign ( assign, source_info, place, value. clone ( ) ) ;
1137
+
1138
+ // create the new block for the assignment in the case of unwinding
1139
+ let assign_unwind = self . cfg . start_new_cleanup_block ( ) ;
1140
+ self . cfg . push_assign ( assign_unwind, source_info, place, value. clone ( ) ) ;
1130
1141
1131
1142
self . cfg . terminate (
1132
1143
block,
1133
1144
source_info,
1134
- TerminatorKind :: DropAndReplace { place, value , target : next_target , unwind : None } ,
1145
+ TerminatorKind :: Drop { place, target : assign , unwind : Some ( assign_unwind ) } ,
1135
1146
) ;
1136
1147
self . diverge_from ( block) ;
1137
1148
1138
- next_target . unit ( )
1149
+ assign . unit ( )
1139
1150
}
1140
1151
1141
1152
/// Creates an `Assert` terminator and return the success block.
@@ -1413,8 +1424,15 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
1413
1424
fn add_entry ( cfg : & mut CFG < ' tcx > , from : BasicBlock , to : BasicBlock ) {
1414
1425
let term = & mut cfg. block_data_mut ( from) . terminator_mut ( ) ;
1415
1426
match & mut term. kind {
1416
- TerminatorKind :: Drop { unwind, .. }
1417
- | TerminatorKind :: DropAndReplace { unwind, .. }
1427
+ TerminatorKind :: Drop { unwind, .. } => {
1428
+ if let Some ( unwind) = * unwind {
1429
+ let source_info = term. source_info ;
1430
+ cfg. terminate ( unwind, source_info, TerminatorKind :: Goto { target : to } ) ;
1431
+ } else {
1432
+ * unwind = Some ( to) ;
1433
+ }
1434
+ }
1435
+ TerminatorKind :: DropAndReplace { unwind, .. }
1418
1436
| TerminatorKind :: FalseUnwind { unwind, .. }
1419
1437
| TerminatorKind :: Call { cleanup : unwind, .. }
1420
1438
| TerminatorKind :: Assert { cleanup : unwind, .. }
0 commit comments