@@ -93,6 +93,7 @@ use util::nodemap::ItemLocalSet;
93
93
#[ derive( Clone , Debug , PartialEq ) ]
94
94
pub enum Categorization < ' tcx > {
95
95
Rvalue ( ty:: Region < ' tcx > ) , // temporary val, argument is its scope
96
+ ThreadLocal ( ty:: Region < ' tcx > ) , // value that cannot move, but still restricted in scope
96
97
StaticItem ,
97
98
Upvar ( Upvar ) , // upvar referenced by closure env
98
99
Local ( ast:: NodeId ) , // local variable
@@ -268,6 +269,7 @@ impl<'tcx> cmt_<'tcx> {
268
269
Categorization :: Deref ( ref base_cmt, _) => {
269
270
base_cmt. immutability_blame ( )
270
271
}
272
+ Categorization :: ThreadLocal ( ..) |
271
273
Categorization :: StaticItem => {
272
274
// Do we want to do something here?
273
275
None
@@ -715,17 +717,23 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
715
717
}
716
718
717
719
Def :: Static ( def_id, mutbl) => {
718
- // `#[thread_local]` statics may not outlive the current function.
719
- for attr in & self . tcx . get_attrs ( def_id) [ ..] {
720
- if attr. check_name ( "thread_local" ) {
721
- return Ok ( self . cat_rvalue_node ( hir_id, span, expr_ty) ) ;
722
- }
723
- }
720
+ // `#[thread_local]` statics may not outlive the current function, but
721
+ // they also cannot be moved out of.
722
+ let is_thread_local = self . tcx . get_attrs ( def_id) [ ..]
723
+ . iter ( )
724
+ . any ( |attr| attr. check_name ( "thread_local" ) ) ;
725
+
726
+ let cat = if is_thread_local {
727
+ let re = self . temporary_scope ( hir_id. local_id ) ;
728
+ Categorization :: ThreadLocal ( re)
729
+ } else {
730
+ Categorization :: StaticItem
731
+ } ;
724
732
725
733
Ok ( cmt_ {
726
734
hir_id,
727
- span : span ,
728
- cat : Categorization :: StaticItem ,
735
+ span,
736
+ cat,
729
737
mutbl : if mutbl { McDeclared } else { McImmutable } ,
730
738
ty : expr_ty,
731
739
note : NoteNone
@@ -1408,6 +1416,7 @@ impl<'tcx> cmt_<'tcx> {
1408
1416
match self . cat {
1409
1417
Categorization :: Rvalue ( ..) |
1410
1418
Categorization :: StaticItem |
1419
+ Categorization :: ThreadLocal ( ..) |
1411
1420
Categorization :: Local ( ..) |
1412
1421
Categorization :: Deref ( _, UnsafePtr ( ..) ) |
1413
1422
Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
@@ -1439,6 +1448,7 @@ impl<'tcx> cmt_<'tcx> {
1439
1448
}
1440
1449
1441
1450
Categorization :: Rvalue ( ..) |
1451
+ Categorization :: ThreadLocal ( ..) |
1442
1452
Categorization :: Local ( ..) |
1443
1453
Categorization :: Upvar ( ..) |
1444
1454
Categorization :: Deref ( _, UnsafePtr ( ..) ) => { // yes, it's aliasable, but...
@@ -1485,6 +1495,9 @@ impl<'tcx> cmt_<'tcx> {
1485
1495
Categorization :: StaticItem => {
1486
1496
"static item" . into ( )
1487
1497
}
1498
+ Categorization :: ThreadLocal ( ..) => {
1499
+ "thread-local static item" . into ( )
1500
+ }
1488
1501
Categorization :: Rvalue ( ..) => {
1489
1502
"non-place" . into ( )
1490
1503
}
0 commit comments