@@ -10,38 +10,11 @@ use rustc_middle::mir::*;
10
10
/// At present, this is used as a very limited form of alias analysis. For example,
11
11
/// `MaybeBorrowedLocals` is used to compute which locals are live during a yield expression for
12
12
/// 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 ;
24
14
25
15
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
-
43
16
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 }
45
18
}
46
19
}
47
20
@@ -92,7 +65,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeBorrowedLocals {
92
65
/// A `Visitor` that defines the transfer function for `MaybeBorrowedLocals`.
93
66
struct TransferFunction < ' a , T > {
94
67
trans : & ' a mut T ,
95
- ignore_borrow_on_drop : bool ,
96
68
}
97
69
98
70
impl < ' tcx , T > Visitor < ' tcx > for TransferFunction < ' _ , T >
@@ -146,10 +118,15 @@ where
146
118
match terminator. kind {
147
119
mir:: TerminatorKind :: Drop { place : dropped_place, .. }
148
120
| 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 ) ;
153
130
}
154
131
155
132
TerminatorKind :: Abort
0 commit comments