Skip to content

Commit f8c35d9

Browse files
committed
fix handling of consts in borrow-checking
I'm not sure how correct it this, but it gets whatever needs to compile to compile.
1 parent 87a8a70 commit f8c35d9

File tree

1 file changed

+15
-12
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+15
-12
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
192192
node_id: id,
193193
move_data: &mdpe.move_data,
194194
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+
},
195200
storage_dead_or_drop_error_reported: FxHashSet(),
196201
};
197202

@@ -223,6 +228,9 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
223228
node_id: ast::NodeId,
224229
move_data: &'cx MoveData<'tcx>,
225230
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,
226234
/// This field keeps track of when storage dead or drop errors are reported
227235
/// in order to stop duplicate error reporting and identify the conditions required
228236
/// for a "temporary value dropped here while still borrowed" error. See #45360.
@@ -957,6 +965,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
957965
// FIXME(nll-rfc#40): do more precise destructor tracking here. For now
958966
// we just know that all locals are dropped at function exit (otherwise
959967
// 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
960970
let (might_be_alive, will_be_dropped) = match root_place {
961971
Place::Static(statik) => {
962972
// Thread-locals might be dropped after the function exits, but
@@ -971,7 +981,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
971981
Place::Local(_) => {
972982
// Locals are always dropped at function exit, and if they
973983
// have a destructor it would've been called already.
974-
(false, true)
984+
(false, self.locals_are_invalidated_at_exit)
975985
}
976986
Place::Projection(..) => {
977987
bug!("root of {:?} is a projection ({:?})?", place, root_place)
@@ -1514,17 +1524,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15141524
Overlap::Disjoint
15151525
}
15161526
}
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
15281531
}
15291532
(Place::Local(_), Place::Static(_)) |
15301533
(Place::Static(_), Place::Local(_)) => {

0 commit comments

Comments
 (0)