Skip to content

Commit 734b924

Browse files
authored
Rollup merge of #94087 - tmiasko:rm-ignore-borrow-on-drop, r=jackh726
Remove unused `unsound_ignore_borrow_on_drop`
2 parents 5dcee68 + 06ac05a commit 734b924

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed

compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs

+11-34
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,11 @@ use rustc_middle::mir::*;
1010
/// At present, this is used as a very limited form of alias analysis. For example,
1111
/// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for
1212
/// immovable generators.
13-
pub struct MaybeBorrowedLocals {
14-
ignore_borrow_on_drop: bool,
15-
}
16-
17-
impl MaybeBorrowedLocals {
18-
/// A dataflow analysis that records whether a pointer or reference exists that may alias the
19-
/// given local.
20-
pub fn all_borrows() -> Self {
21-
MaybeBorrowedLocals { ignore_borrow_on_drop: false }
22-
}
23-
}
13+
pub struct MaybeBorrowedLocals;
2414

2515
impl MaybeBorrowedLocals {
26-
/// During dataflow analysis, ignore the borrow that may occur when a place is dropped.
27-
///
28-
/// Drop terminators may call custom drop glue (`Drop::drop`), which takes `&mut self` as a
29-
/// parameter. In the general case, a drop impl could launder that reference into the
30-
/// surrounding environment through a raw pointer, thus creating a valid `*mut` pointing to the
31-
/// dropped local. We are not yet willing to declare this particular case UB, so we must treat
32-
/// all dropped locals as mutably borrowed for now. See discussion on [#61069].
33-
///
34-
/// In some contexts, we know that this borrow will never occur. For example, during
35-
/// const-eval, custom drop glue cannot be run. Code that calls this should document the
36-
/// assumptions that justify ignoring `Drop` terminators in this way.
37-
///
38-
/// [#61069]: https://github.com/rust-lang/rust/pull/61069
39-
pub fn unsound_ignore_borrow_on_drop(self) -> Self {
40-
MaybeBorrowedLocals { ignore_borrow_on_drop: true, ..self }
41-
}
42-
4316
fn transfer_function<'a, T>(&'a self, trans: &'a mut T) -> TransferFunction<'a, T> {
44-
TransferFunction { trans, ignore_borrow_on_drop: self.ignore_borrow_on_drop }
17+
TransferFunction { trans }
4518
}
4619
}
4720

@@ -92,7 +65,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeBorrowedLocals {
9265
/// A `Visitor` that defines the transfer function for `MaybeBorrowedLocals`.
9366
struct TransferFunction<'a, T> {
9467
trans: &'a mut T,
95-
ignore_borrow_on_drop: bool,
9668
}
9769

9870
impl<'tcx, T> Visitor<'tcx> for TransferFunction<'_, T>
@@ -146,10 +118,15 @@ where
146118
match terminator.kind {
147119
mir::TerminatorKind::Drop { place: dropped_place, .. }
148120
| mir::TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
149-
// See documentation for `unsound_ignore_borrow_on_drop` for an explanation.
150-
if !self.ignore_borrow_on_drop {
151-
self.trans.gen(dropped_place.local);
152-
}
121+
// Drop terminators may call custom drop glue (`Drop::drop`), which takes `&mut
122+
// self` as a parameter. In the general case, a drop impl could launder that
123+
// reference into the surrounding environment through a raw pointer, thus creating
124+
// a valid `*mut` pointing to the dropped local. We are not yet willing to declare
125+
// this particular case UB, so we must treat all dropped locals as mutably borrowed
126+
// for now. See discussion on [#61069].
127+
//
128+
// [#61069]: https://github.com/rust-lang/rust/pull/61069
129+
self.trans.gen(dropped_place.local);
153130
}
154131

155132
TerminatorKind::Abort

compiler/rustc_mir_transform/src/generator.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,8 @@ fn locals_live_across_suspend_points<'tcx>(
463463

464464
// Calculate the MIR locals which have been previously
465465
// borrowed (even if they are still active).
466-
let borrowed_locals_results = MaybeBorrowedLocals::all_borrows()
467-
.into_engine(tcx, body_ref)
468-
.pass_name("generator")
469-
.iterate_to_fixpoint();
466+
let borrowed_locals_results =
467+
MaybeBorrowedLocals.into_engine(tcx, body_ref).pass_name("generator").iterate_to_fixpoint();
470468

471469
let mut borrowed_locals_cursor =
472470
rustc_mir_dataflow::ResultsCursor::new(body_ref, &borrowed_locals_results);

0 commit comments

Comments
 (0)