@@ -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
2515impl 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`.
9366struct TransferFunction < ' a , T > {
9467 trans : & ' a mut T ,
95- ignore_borrow_on_drop : bool ,
9668}
9769
9870impl < ' 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
0 commit comments