@@ -93,6 +93,7 @@ use util::nodemap::ItemLocalSet;
9393#[ derive( Clone , Debug , PartialEq ) ]
9494pub enum Categorization < ' tcx > {
9595 Rvalue ( ty:: Region < ' tcx > ) , // temporary val, argument is its scope
96+ ThreadLocal ( ty:: Region < ' tcx > ) , // value that cannot move, but still restricted in scope
9697 StaticItem ,
9798 Upvar ( Upvar ) , // upvar referenced by closure env
9899 Local ( ast:: NodeId ) , // local variable
@@ -268,6 +269,7 @@ impl<'tcx> cmt_<'tcx> {
268269 Categorization :: Deref ( ref base_cmt, _) => {
269270 base_cmt. immutability_blame ( )
270271 }
272+ Categorization :: ThreadLocal ( ..) |
271273 Categorization :: StaticItem => {
272274 // Do we want to do something here?
273275 None
@@ -715,17 +717,23 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
715717 }
716718
717719 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+ } ;
724732
725733 Ok ( cmt_ {
726734 hir_id,
727- span : span ,
728- cat : Categorization :: StaticItem ,
735+ span,
736+ cat,
729737 mutbl : if mutbl { McDeclared } else { McImmutable } ,
730738 ty : expr_ty,
731739 note : NoteNone
@@ -1408,6 +1416,7 @@ impl<'tcx> cmt_<'tcx> {
14081416 match self . cat {
14091417 Categorization :: Rvalue ( ..) |
14101418 Categorization :: StaticItem |
1419+ Categorization :: ThreadLocal ( ..) |
14111420 Categorization :: Local ( ..) |
14121421 Categorization :: Deref ( _, UnsafePtr ( ..) ) |
14131422 Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
@@ -1439,6 +1448,7 @@ impl<'tcx> cmt_<'tcx> {
14391448 }
14401449
14411450 Categorization :: Rvalue ( ..) |
1451+ Categorization :: ThreadLocal ( ..) |
14421452 Categorization :: Local ( ..) |
14431453 Categorization :: Upvar ( ..) |
14441454 Categorization :: Deref ( _, UnsafePtr ( ..) ) => { // yes, it's aliasable, but...
@@ -1485,6 +1495,9 @@ impl<'tcx> cmt_<'tcx> {
14851495 Categorization :: StaticItem => {
14861496 "static item" . into ( )
14871497 }
1498+ Categorization :: ThreadLocal ( ..) => {
1499+ "thread-local static item" . into ( )
1500+ }
14881501 Categorization :: Rvalue ( ..) => {
14891502 "non-place" . into ( )
14901503 }
0 commit comments