@@ -8,7 +8,9 @@ use rustc::infer::InferCtxt;
8
8
use rustc:: lint:: builtin:: UNUSED_MUT ;
9
9
use rustc:: middle:: borrowck:: SignalledError ;
10
10
use rustc:: mir:: { AggregateKind , BasicBlock , BorrowCheckResult , BorrowKind } ;
11
- use rustc:: mir:: { ClearCrossCrate , Local , Location , Mir , Mutability , Operand , Place , PlaceBase } ;
11
+ use rustc:: mir:: {
12
+ ClearCrossCrate , Local , Location , Mir , Mutability , Operand , Place , PlaceBase , Static , StaticKind
13
+ } ;
12
14
use rustc:: mir:: { Field , Projection , ProjectionElem , Rvalue , Statement , StatementKind } ;
13
15
use rustc:: mir:: { Terminator , TerminatorKind } ;
14
16
use rustc:: ty:: query:: Providers ;
@@ -1308,8 +1310,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1308
1310
//
1309
1311
// FIXME: allow thread-locals to borrow other thread locals?
1310
1312
let ( might_be_alive, will_be_dropped) = match root_place {
1311
- Place :: Base ( PlaceBase :: Static ( st) ) => {
1312
- ( true , st. promoted . is_none ( ) && self . is_place_thread_local ( & root_place) )
1313
+ Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) ) => {
1314
+ ( true , false )
1315
+ }
1316
+ Place :: Base ( PlaceBase :: Static ( box Static { kind : _, .. } ) ) => {
1317
+ // Thread-locals might be dropped after the function exits, but
1318
+ // "true" statics will never be.
1319
+ ( true , self . is_place_thread_local ( & root_place) )
1313
1320
}
1314
1321
Place :: Base ( PlaceBase :: Local ( _) ) => {
1315
1322
// Locals are always dropped at function exit, and if they
@@ -1982,18 +1989,19 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1982
1989
}
1983
1990
// The rules for promotion are made by `qualify_consts`, there wouldn't even be a
1984
1991
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
1985
- Place :: Base ( PlaceBase :: Static ( ref static_) ) => {
1986
- if static_. promoted . is_some ( ) ||
1987
- ( static_. promoted . is_none ( ) &&
1988
- self . infcx . tcx . is_static ( static_. def_id )
1989
- == Some ( hir:: Mutability :: MutMutable )
1990
- ) {
1992
+ Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , ..} ) ) =>
1993
+ Ok ( RootPlace {
1994
+ place,
1995
+ is_local_mutation_allowed,
1996
+ } ) ,
1997
+ Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) ) => {
1998
+ if self . infcx . tcx . is_static ( def_id) != Some ( hir:: Mutability :: MutMutable ) {
1999
+ Err ( place)
2000
+ } else {
1991
2001
Ok ( RootPlace {
1992
2002
place,
1993
2003
is_local_mutation_allowed,
1994
2004
} )
1995
- } else {
1996
- Err ( place)
1997
2005
}
1998
2006
}
1999
2007
Place :: Projection ( ref proj) => {
0 commit comments