Skip to content

Commit 3c9b079

Browse files
authored
Rollup merge of rust-lang#108856 - Zeegomo:remove-drop-and-rep, r=tmiasko
Remove DropAndReplace terminator rust-lang#107844 made DropAndReplace unused, let's remove it completely from the codebase.
2 parents a64e3f3 + 153bfa0 commit 3c9b079

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+33
-344
lines changed

compiler/rustc_borrowck/src/invalidation.rs

-9
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
118118
LocalMutationIsAllowed::Yes,
119119
);
120120
}
121-
TerminatorKind::DropAndReplace {
122-
place: drop_place,
123-
value: new_value,
124-
target: _,
125-
unwind: _,
126-
} => {
127-
self.mutate_place(location, *drop_place, Deep);
128-
self.consume_operand(location, new_value);
129-
}
130121
TerminatorKind::Call {
131122
func,
132123
args,

compiler/rustc_borrowck/src/lib.rs

-10
Original file line numberDiff line numberDiff line change
@@ -743,15 +743,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
743743
flow_state,
744744
);
745745
}
746-
TerminatorKind::DropAndReplace {
747-
place: drop_place,
748-
value: new_value,
749-
target: _,
750-
unwind: _,
751-
} => {
752-
self.mutate_place(loc, (*drop_place, span), Deep, flow_state);
753-
self.consume_operand(loc, (new_value, span), flow_state);
754-
}
755746
TerminatorKind::Call {
756747
func,
757748
args,
@@ -866,7 +857,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
866857
| TerminatorKind::Assert { .. }
867858
| TerminatorKind::Call { .. }
868859
| TerminatorKind::Drop { .. }
869-
| TerminatorKind::DropAndReplace { .. }
870860
| TerminatorKind::FalseEdge { real_target: _, imaginary_target: _ }
871861
| TerminatorKind::FalseUnwind { real_target: _, unwind: _ }
872862
| TerminatorKind::Goto { .. }

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
435435
//
436436
// What we *actually* generate is a store to a temporary
437437
// for the call (`TMP = call()...`) and then a
438-
// `DropAndReplace` to swap that with `X`
439-
// (`DropAndReplace` has very particular semantics).
438+
// `Drop(X)` followed by `X = TMP` to swap that with `X`.
440439
}
441440
}
442441

compiler/rustc_borrowck/src/type_check/mod.rs

-19
Original file line numberDiff line numberDiff line change
@@ -1312,24 +1312,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13121312
// no checks needed for these
13131313
}
13141314

1315-
TerminatorKind::DropAndReplace { place, value, target: _, unwind: _ } => {
1316-
let place_ty = place.ty(body, tcx).ty;
1317-
let rv_ty = value.ty(body, tcx);
1318-
1319-
let locations = term_location.to_locations();
1320-
if let Err(terr) =
1321-
self.sub_types(rv_ty, place_ty, locations, ConstraintCategory::Assignment)
1322-
{
1323-
span_mirbug!(
1324-
self,
1325-
term,
1326-
"bad DropAndReplace ({:?} = {:?}): {:?}",
1327-
place_ty,
1328-
rv_ty,
1329-
terr
1330-
);
1331-
}
1332-
}
13331315
TerminatorKind::SwitchInt { discr, .. } => {
13341316
self.check_operand(discr, term_location);
13351317

@@ -1629,7 +1611,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16291611
}
16301612
TerminatorKind::Unreachable => {}
16311613
TerminatorKind::Drop { target, unwind, .. }
1632-
| TerminatorKind::DropAndReplace { target, unwind, .. }
16331614
| TerminatorKind::Assert { target, cleanup: unwind, .. } => {
16341615
self.assert_iscleanup(body, block_data, target, is_cleanup);
16351616
if let Some(unwind) = unwind {

compiler/rustc_borrowck/src/used_muts.rs

-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc
7171
TerminatorKind::Call { destination, .. } => {
7272
self.remove_never_initialized_mut_locals(*destination);
7373
}
74-
TerminatorKind::DropAndReplace { place, .. } => {
75-
self.remove_never_initialized_mut_locals(*place);
76-
}
7774
_ => {}
7875
}
7976

compiler/rustc_codegen_cranelift/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
499499
TerminatorKind::Yield { .. }
500500
| TerminatorKind::FalseEdge { .. }
501501
| TerminatorKind::FalseUnwind { .. }
502-
| TerminatorKind::DropAndReplace { .. }
503502
| TerminatorKind::GeneratorDrop => {
504503
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
505504
}

compiler/rustc_codegen_cranelift/src/constant.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
543543
| TerminatorKind::Unreachable
544544
| TerminatorKind::Drop { .. }
545545
| TerminatorKind::Assert { .. } => {}
546-
TerminatorKind::DropAndReplace { .. }
547-
| TerminatorKind::Yield { .. }
546+
TerminatorKind::Yield { .. }
548547
| TerminatorKind::GeneratorDrop
549548
| TerminatorKind::FalseEdge { .. }
550549
| TerminatorKind::FalseUnwind { .. } => unreachable!(),

compiler/rustc_codegen_ssa/src/mir/analyze.rs

-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
295295
TerminatorKind::Call { cleanup: unwind, .. }
296296
| TerminatorKind::InlineAsm { cleanup: unwind, .. }
297297
| TerminatorKind::Assert { cleanup: unwind, .. }
298-
| TerminatorKind::DropAndReplace { unwind, .. }
299298
| TerminatorKind::Drop { unwind, .. } => {
300299
if let Some(unwind) = unwind {
301300
debug!(

compiler/rustc_codegen_ssa/src/mir/block.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1305,10 +1305,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13051305
mergeable_succ(),
13061306
),
13071307

1308-
mir::TerminatorKind::DropAndReplace { .. } => {
1309-
bug!("undesugared DropAndReplace in codegen: {:?}", terminator);
1310-
}
1311-
13121308
mir::TerminatorKind::Call {
13131309
ref func,
13141310
ref args,

compiler/rustc_const_eval/src/interpret/terminator.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
171171
Unreachable => throw_ub!(Unreachable),
172172

173173
// These should never occur for MIR we actually run.
174-
DropAndReplace { .. }
175-
| FalseEdge { .. }
176-
| FalseUnwind { .. }
177-
| Yield { .. }
178-
| GeneratorDrop => span_bug!(
174+
FalseEdge { .. } | FalseUnwind { .. } | Yield { .. } | GeneratorDrop => span_bug!(
179175
terminator.source_info.span,
180176
"{:#?} should have been eliminated by MIR pass",
181177
terminator.kind

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
985985

986986
// Forbid all `Drop` terminators unless the place being dropped is a local with no
987987
// projections that cannot be `NeedsNonConstDrop`.
988-
TerminatorKind::Drop { place: dropped_place, .. }
989-
| TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
988+
TerminatorKind::Drop { place: dropped_place, .. } => {
990989
// If we are checking live drops after drop-elaboration, don't emit duplicate
991990
// errors here.
992991
if super::post_drop_elaboration::checking_enabled(self.ccx) {

compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> {
8080
trace!("visit_terminator: terminator={:?} location={:?}", terminator, location);
8181

8282
match &terminator.kind {
83-
mir::TerminatorKind::Drop { place: dropped_place, .. }
84-
| mir::TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
83+
mir::TerminatorKind::Drop { place: dropped_place, .. } => {
8584
let dropped_ty = dropped_place.ty(self.body, self.tcx).ty;
8685
if !NeedsNonConstDrop::in_any_value_of_ty(self.ccx, dropped_ty) {
8786
// Instead of throwing a bug, we just return here. This is because we have to

compiler/rustc_const_eval/src/transform/check_consts/resolver.rs

-15
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,8 @@ where
222222
// The effect of assignment to the return place in `TerminatorKind::Call` is not applied
223223
// here; that occurs in `apply_call_return_effect`.
224224

225-
if let mir::TerminatorKind::DropAndReplace { value, place, .. } = &terminator.kind {
226-
let qualif = qualifs::in_operand::<Q, _>(
227-
self.ccx,
228-
&mut |l| self.state.qualif.contains(l),
229-
value,
230-
);
231-
232-
if !place.is_indirect() {
233-
self.assign_qualif_direct(place, qualif);
234-
}
235-
}
236-
237225
// We ignore borrow on drop because custom drop impls are not allowed in consts.
238226
// FIXME: Reconsider if accounting for borrows in drops is necessary for const drop.
239-
240-
// We need to assign qualifs to the dropped location before visiting the operand that
241-
// replaces it since qualifs can be cleared on move.
242227
self.super_terminator(terminator, location);
243228
}
244229
}

compiler/rustc_const_eval/src/transform/validate.rs

-12
Original file line numberDiff line numberDiff line change
@@ -846,18 +846,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
846846
self.check_edge(location, *unwind, EdgeKind::Unwind);
847847
}
848848
}
849-
TerminatorKind::DropAndReplace { target, unwind, .. } => {
850-
if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) {
851-
self.fail(
852-
location,
853-
"`DropAndReplace` should have been removed during drop elaboration",
854-
);
855-
}
856-
self.check_edge(location, *target, EdgeKind::Normal);
857-
if let Some(unwind) = unwind {
858-
self.check_edge(location, *unwind, EdgeKind::Unwind);
859-
}
860-
}
861849
TerminatorKind::Call { func, args, destination, target, cleanup, .. } => {
862850
let func_ty = func.ty(&self.body.local_decls, self.tcx);
863851
match func_ty.kind() {

compiler/rustc_middle/src/mir/spanview.rs

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ pub fn terminator_kind_name(term: &Terminator<'_>) -> &'static str {
265265
Return => "Return",
266266
Unreachable => "Unreachable",
267267
Drop { .. } => "Drop",
268-
DropAndReplace { .. } => "DropAndReplace",
269268
Call { .. } => "Call",
270269
Assert { .. } => "Assert",
271270
Yield { .. } => "Yield",

compiler/rustc_middle/src/mir/syntax.rs

-38
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ pub enum AnalysisPhase {
133133
pub enum RuntimePhase {
134134
/// In addition to the semantic changes, beginning with this phase, the following variants are
135135
/// disallowed:
136-
/// * [`TerminatorKind::DropAndReplace`]
137136
/// * [`TerminatorKind::Yield`]
138137
/// * [`TerminatorKind::GeneratorDrop`]
139138
/// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array`
@@ -596,43 +595,6 @@ pub enum TerminatorKind<'tcx> {
596595
/// > consider indirect assignments.
597596
Drop { place: Place<'tcx>, target: BasicBlock, unwind: Option<BasicBlock> },
598597

599-
/// Drops the place and assigns a new value to it.
600-
///
601-
/// This first performs the exact same operation as the pre drop-elaboration `Drop` terminator;
602-
/// it then additionally assigns the `value` to the `place` as if by an assignment statement.
603-
/// This assignment occurs both in the unwind and the regular code paths. The semantics are best
604-
/// explained by the elaboration:
605-
///
606-
/// ```ignore (MIR)
607-
/// BB0 {
608-
/// DropAndReplace(P <- V, goto BB1, unwind BB2)
609-
/// }
610-
/// ```
611-
///
612-
/// becomes
613-
///
614-
/// ```ignore (MIR)
615-
/// BB0 {
616-
/// Drop(P, goto BB1, unwind BB2)
617-
/// }
618-
/// BB1 {
619-
/// // P is now uninitialized
620-
/// P <- V
621-
/// }
622-
/// BB2 {
623-
/// // P is now uninitialized -- its dtor panicked
624-
/// P <- V
625-
/// }
626-
/// ```
627-
///
628-
/// Disallowed after drop elaboration.
629-
DropAndReplace {
630-
place: Place<'tcx>,
631-
value: Operand<'tcx>,
632-
target: BasicBlock,
633-
unwind: Option<BasicBlock>,
634-
},
635-
636598
/// Roughly speaking, evaluates the `func` operand and the arguments, and starts execution of
637599
/// the referred to function. The operand types must match the argument types of the function.
638600
/// The return place type must match the return type. The type of the `func` operand must be

compiler/rustc_middle/src/mir/terminator.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ impl<'tcx> TerminatorKind<'tcx> {
148148
| Call { target: None, cleanup: Some(t), .. }
149149
| Call { target: Some(t), cleanup: None, .. }
150150
| Yield { resume: t, drop: None, .. }
151-
| DropAndReplace { target: t, unwind: None, .. }
152151
| Drop { target: t, unwind: None, .. }
153152
| Assert { target: t, cleanup: None, .. }
154153
| FalseUnwind { real_target: t, unwind: None }
@@ -158,7 +157,6 @@ impl<'tcx> TerminatorKind<'tcx> {
158157
}
159158
Call { target: Some(t), cleanup: Some(ref u), .. }
160159
| Yield { resume: t, drop: Some(ref u), .. }
161-
| DropAndReplace { target: t, unwind: Some(ref u), .. }
162160
| Drop { target: t, unwind: Some(ref u), .. }
163161
| Assert { target: t, cleanup: Some(ref u), .. }
164162
| FalseUnwind { real_target: t, unwind: Some(ref u) }
@@ -188,7 +186,6 @@ impl<'tcx> TerminatorKind<'tcx> {
188186
| Call { target: None, cleanup: Some(ref mut t), .. }
189187
| Call { target: Some(ref mut t), cleanup: None, .. }
190188
| Yield { resume: ref mut t, drop: None, .. }
191-
| DropAndReplace { target: ref mut t, unwind: None, .. }
192189
| Drop { target: ref mut t, unwind: None, .. }
193190
| Assert { target: ref mut t, cleanup: None, .. }
194191
| FalseUnwind { real_target: ref mut t, unwind: None }
@@ -198,7 +195,6 @@ impl<'tcx> TerminatorKind<'tcx> {
198195
}
199196
Call { target: Some(ref mut t), cleanup: Some(ref mut u), .. }
200197
| Yield { resume: ref mut t, drop: Some(ref mut u), .. }
201-
| DropAndReplace { target: ref mut t, unwind: Some(ref mut u), .. }
202198
| Drop { target: ref mut t, unwind: Some(ref mut u), .. }
203199
| Assert { target: ref mut t, cleanup: Some(ref mut u), .. }
204200
| FalseUnwind { real_target: ref mut t, unwind: Some(ref mut u) }
@@ -225,7 +221,6 @@ impl<'tcx> TerminatorKind<'tcx> {
225221
| TerminatorKind::FalseEdge { .. } => None,
226222
TerminatorKind::Call { cleanup: ref unwind, .. }
227223
| TerminatorKind::Assert { cleanup: ref unwind, .. }
228-
| TerminatorKind::DropAndReplace { ref unwind, .. }
229224
| TerminatorKind::Drop { ref unwind, .. }
230225
| TerminatorKind::FalseUnwind { ref unwind, .. }
231226
| TerminatorKind::InlineAsm { cleanup: ref unwind, .. } => Some(unwind),
@@ -245,7 +240,6 @@ impl<'tcx> TerminatorKind<'tcx> {
245240
| TerminatorKind::FalseEdge { .. } => None,
246241
TerminatorKind::Call { cleanup: ref mut unwind, .. }
247242
| TerminatorKind::Assert { cleanup: ref mut unwind, .. }
248-
| TerminatorKind::DropAndReplace { ref mut unwind, .. }
249243
| TerminatorKind::Drop { ref mut unwind, .. }
250244
| TerminatorKind::FalseUnwind { ref mut unwind, .. }
251245
| TerminatorKind::InlineAsm { cleanup: ref mut unwind, .. } => Some(unwind),
@@ -309,9 +303,6 @@ impl<'tcx> TerminatorKind<'tcx> {
309303
Yield { value, resume_arg, .. } => write!(fmt, "{:?} = yield({:?})", resume_arg, value),
310304
Unreachable => write!(fmt, "unreachable"),
311305
Drop { place, .. } => write!(fmt, "drop({:?})", place),
312-
DropAndReplace { place, value, .. } => {
313-
write!(fmt, "replace({:?} <- {:?})", place, value)
314-
}
315306
Call { func, args, destination, .. } => {
316307
write!(fmt, "{:?} = ", destination)?;
317308
write!(fmt, "{:?}(", func)?;
@@ -403,10 +394,10 @@ impl<'tcx> TerminatorKind<'tcx> {
403394
Call { target: None, cleanup: None, .. } => vec![],
404395
Yield { drop: Some(_), .. } => vec!["resume".into(), "drop".into()],
405396
Yield { drop: None, .. } => vec!["resume".into()],
406-
DropAndReplace { unwind: None, .. } | Drop { unwind: None, .. } => {
397+
Drop { unwind: None, .. } => {
407398
vec!["return".into()]
408399
}
409-
DropAndReplace { unwind: Some(_), .. } | Drop { unwind: Some(_), .. } => {
400+
Drop { unwind: Some(_), .. } => {
410401
vec!["return".into(), "unwind".into()]
411402
}
412403
Assert { cleanup: None, .. } => vec!["".into()],

compiler/rustc_middle/src/mir/visit.rs

-14
Original file line numberDiff line numberDiff line change
@@ -495,20 +495,6 @@ macro_rules! make_mir_visitor {
495495
);
496496
}
497497

498-
TerminatorKind::DropAndReplace {
499-
place,
500-
value,
501-
target: _,
502-
unwind: _,
503-
} => {
504-
self.visit_place(
505-
place,
506-
PlaceContext::MutatingUse(MutatingUseContext::Drop),
507-
location
508-
);
509-
self.visit_operand(value, location);
510-
}
511-
512498
TerminatorKind::Call {
513499
func,
514500
args,

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
5959
unwind: None,
6060
})
6161
},
62-
@call("mir_drop_and_replace", args) => {
63-
Ok(TerminatorKind::DropAndReplace {
64-
place: self.parse_place(args[0])?,
65-
value: self.parse_operand(args[1])?,
66-
target: self.parse_block(args[2])?,
67-
unwind: None,
68-
})
69-
},
7062
@call("mir_call", args) => {
7163
let destination = self.parse_place(args[0])?;
7264
let target = self.parse_block(args[1])?;

compiler/rustc_mir_build/src/build/scope.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10721072
TerminatorKind::Assert { .. }
10731073
| TerminatorKind::Call { .. }
10741074
| TerminatorKind::Drop { .. }
1075-
| TerminatorKind::DropAndReplace { .. }
10761075
| TerminatorKind::FalseUnwind { .. }
10771076
| TerminatorKind::InlineAsm { .. }
10781077
),
@@ -1432,8 +1431,7 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
14321431
*unwind = Some(to);
14331432
}
14341433
}
1435-
TerminatorKind::DropAndReplace { unwind, .. }
1436-
| TerminatorKind::FalseUnwind { unwind, .. }
1434+
TerminatorKind::FalseUnwind { unwind, .. }
14371435
| TerminatorKind::Call { cleanup: unwind, .. }
14381436
| TerminatorKind::Assert { cleanup: unwind, .. }
14391437
| TerminatorKind::InlineAsm { cleanup: unwind, .. } => {

compiler/rustc_mir_build/src/lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ impl<'mir, 'tcx> TriColorVisitor<BasicBlocks<'tcx>> for Search<'mir, 'tcx> {
128128
TerminatorKind::Assert { .. }
129129
| TerminatorKind::Call { .. }
130130
| TerminatorKind::Drop { .. }
131-
| TerminatorKind::DropAndReplace { .. }
132131
| TerminatorKind::FalseEdge { .. }
133132
| TerminatorKind::FalseUnwind { .. }
134133
| TerminatorKind::Goto { .. }

0 commit comments

Comments
 (0)