@@ -192,6 +192,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
192
192
node_id : id,
193
193
move_data : & mdpe. move_data ,
194
194
param_env : param_env,
195
+ locals_are_invalidated_at_exit : match tcx. hir . body_owner_kind ( id) {
196
+ hir:: BodyOwnerKind :: Const |
197
+ hir:: BodyOwnerKind :: Static ( _) => false ,
198
+ hir:: BodyOwnerKind :: Fn => true ,
199
+ } ,
195
200
storage_dead_or_drop_error_reported : FxHashSet ( ) ,
196
201
} ;
197
202
@@ -223,6 +228,9 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
223
228
node_id : ast:: NodeId ,
224
229
move_data : & ' cx MoveData < ' tcx > ,
225
230
param_env : ParamEnv < ' gcx > ,
231
+ /// This keeps track of whether local variables are free-ed when the function
232
+ /// exits even without a `StorageDead`.
233
+ locals_are_invalidated_at_exit : bool ,
226
234
/// This field keeps track of when storage dead or drop errors are reported
227
235
/// in order to stop duplicate error reporting and identify the conditions required
228
236
/// for a "temporary value dropped here while still borrowed" error. See #45360.
@@ -957,6 +965,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
957
965
// FIXME(nll-rfc#40): do more precise destructor tracking here. For now
958
966
// we just know that all locals are dropped at function exit (otherwise
959
967
// we'll have a memory leak) and assume that all statics have a destructor.
968
+ //
969
+ // FIXME: allow thread-locals to borrow other thread locals?x
960
970
let ( might_be_alive, will_be_dropped) = match root_place {
961
971
Place :: Static ( statik) => {
962
972
// Thread-locals might be dropped after the function exits, but
@@ -971,7 +981,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
971
981
Place :: Local ( _) => {
972
982
// Locals are always dropped at function exit, and if they
973
983
// have a destructor it would've been called already.
974
- ( false , true )
984
+ ( false , self . locals_are_invalidated_at_exit )
975
985
}
976
986
Place :: Projection ( ..) => {
977
987
bug ! ( "root of {:?} is a projection ({:?})?" , place, root_place)
@@ -1514,17 +1524,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1514
1524
Overlap :: Disjoint
1515
1525
}
1516
1526
}
1517
- ( Place :: Static ( statik1) , Place :: Static ( statik2) ) => {
1518
- // We ignore borrows of mutable statics elsewhere, but
1519
- // we need to keep track of thread-locals so we can
1520
- // complain if they live loner than the function.
1521
- if statik1. def_id == statik2. def_id {
1522
- debug ! ( "place_element_conflict: DISJOINT-OR-EQ-STATIC" ) ;
1523
- Overlap :: EqualOrDisjoint
1524
- } else {
1525
- debug ! ( "place_element_conflict: DISJOINT-STATIC" ) ;
1526
- Overlap :: Disjoint
1527
- }
1527
+ ( Place :: Static ( ..) , Place :: Static ( ..) ) => {
1528
+ // Borrows of statics do not have to be tracked here.
1529
+ debug ! ( "place_element_conflict: IGNORED-STATIC" ) ;
1530
+ Overlap :: Disjoint
1528
1531
}
1529
1532
( Place :: Local ( _) , Place :: Static ( _) ) |
1530
1533
( Place :: Static ( _) , Place :: Local ( _) ) => {
0 commit comments