@@ -8,7 +8,9 @@ use rustc::infer::InferCtxt;
88use rustc:: lint:: builtin:: UNUSED_MUT ;
99use rustc:: middle:: borrowck:: SignalledError ;
1010use 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+ } ;
1214use rustc:: mir:: { Field , Projection , ProjectionElem , Rvalue , Statement , StatementKind } ;
1315use rustc:: mir:: { Terminator , TerminatorKind } ;
1416use rustc:: ty:: query:: Providers ;
@@ -1308,8 +1310,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13081310 //
13091311 // FIXME: allow thread-locals to borrow other thread locals?
13101312 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) )
13131320 }
13141321 Place :: Base ( PlaceBase :: Local ( _) ) => {
13151322 // Locals are always dropped at function exit, and if they
@@ -1982,18 +1989,19 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19821989 }
19831990 // The rules for promotion are made by `qualify_consts`, there wouldn't even be a
19841991 // `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 {
19912001 Ok ( RootPlace {
19922002 place,
19932003 is_local_mutation_allowed,
19942004 } )
1995- } else {
1996- Err ( place)
19972005 }
19982006 }
19992007 Place :: Projection ( ref proj) => {
0 commit comments