@@ -79,12 +79,11 @@ use std::fmt;
7979use std:: hash:: { Hash , Hasher } ;
8080use rustc_data_structures:: fx:: FxIndexMap ;
8181use std:: rc:: Rc ;
82- use crate :: util:: nodemap:: ItemLocalSet ;
8382
8483#[ derive( Clone , Debug , PartialEq ) ]
8584pub enum Categorization < ' tcx > {
86- Rvalue ( ty :: Region < ' tcx > ) , // temporary val, argument is its scope
87- ThreadLocal ( ty :: Region < ' tcx > ) , // value that cannot move, but still restricted in scope
85+ Rvalue , // temporary val
86+ ThreadLocal , // value that cannot move, but still restricted in scope
8887 StaticItem ,
8988 Upvar ( Upvar ) , // upvar referenced by closure env
9089 Local ( hir:: HirId ) , // local variable
@@ -219,7 +218,6 @@ pub struct MemCategorizationContext<'a, 'tcx> {
219218 pub upvars : Option < & ' tcx FxIndexMap < hir:: HirId , hir:: Upvar > > ,
220219 pub region_scope_tree : & ' a region:: ScopeTree ,
221220 pub tables : & ' a ty:: TypeckTables < ' tcx > ,
222- rvalue_promotable_map : Option < & ' tcx ItemLocalSet > ,
223221 infcx : Option < & ' a InferCtxt < ' a , ' tcx > > ,
224222}
225223
@@ -335,15 +333,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
335333 body_owner : DefId ,
336334 region_scope_tree : & ' a region:: ScopeTree ,
337335 tables : & ' a ty:: TypeckTables < ' tcx > ,
338- rvalue_promotable_map : Option < & ' tcx ItemLocalSet > ,
339336 ) -> MemCategorizationContext < ' a , ' tcx > {
340337 MemCategorizationContext {
341338 tcx,
342339 body_owner,
343340 upvars : tcx. upvars ( body_owner) ,
344341 region_scope_tree,
345342 tables,
346- rvalue_promotable_map,
347343 infcx : None ,
348344 param_env,
349345 }
@@ -369,19 +365,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
369365 ) -> MemCategorizationContext < ' a , ' tcx > {
370366 let tcx = infcx. tcx ;
371367
372- // Subtle: we can't do rvalue promotion analysis until the
373- // typeck phase is complete, which means that you can't trust
374- // the rvalue lifetimes that result, but that's ok, since we
375- // don't need to know those during type inference.
376- let rvalue_promotable_map = None ;
377-
378368 MemCategorizationContext {
379369 tcx,
380370 body_owner,
381371 upvars : tcx. upvars ( body_owner) ,
382372 region_scope_tree,
383373 tables,
384- rvalue_promotable_map,
385374 infcx : Some ( infcx) ,
386375 param_env,
387376 }
@@ -664,8 +653,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
664653 . any ( |attr| attr. check_name ( sym:: thread_local) ) ;
665654
666655 let cat = if is_thread_local {
667- let re = self . temporary_scope ( hir_id. local_id ) ;
668- Categorization :: ThreadLocal ( re)
656+ Categorization :: ThreadLocal
669657 } else {
670658 Categorization :: StaticItem
671659 } ;
@@ -878,16 +866,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
878866 ret
879867 }
880868
881- /// Returns the lifetime of a temporary created by expr with id `id`.
882- /// This could be `'static` if `id` is part of a constant expression.
883- pub fn temporary_scope ( & self , id : hir:: ItemLocalId ) -> ty:: Region < ' tcx > {
884- let scope = self . region_scope_tree . temporary_scope ( id) ;
885- self . tcx . mk_region ( match scope {
886- Some ( scope) => ty:: ReScope ( scope) ,
887- None => ty:: ReStatic
888- } )
889- }
890-
891869 pub fn cat_rvalue_node ( & self ,
892870 hir_id : hir:: HirId ,
893871 span : Span ,
@@ -896,41 +874,19 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
896874 debug ! ( "cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})" ,
897875 hir_id, span, expr_ty) ;
898876
899- let promotable = self . rvalue_promotable_map . as_ref ( ) . map ( |m| m. contains ( & hir_id. local_id ) )
900- . unwrap_or ( false ) ;
901-
902- debug ! ( "cat_rvalue_node: promotable = {:?}" , promotable) ;
903-
904- // Always promote `[T; 0]` (even when e.g., borrowed mutably).
905- let promotable = match expr_ty. kind {
906- ty:: Array ( _, len) if len. try_eval_usize ( self . tcx , self . param_env ) == Some ( 0 ) => true ,
907- _ => promotable,
908- } ;
909-
910- debug ! ( "cat_rvalue_node: promotable = {:?} (2)" , promotable) ;
911-
912- // Compute maximum lifetime of this rvalue. This is 'static if
913- // we can promote to a constant, otherwise equal to enclosing temp
914- // lifetime.
915- let re = if promotable {
916- self . tcx . lifetimes . re_static
917- } else {
918- self . temporary_scope ( hir_id. local_id )
919- } ;
920- let ret = self . cat_rvalue ( hir_id, span, re, expr_ty) ;
877+ let ret = self . cat_rvalue ( hir_id, span, expr_ty) ;
921878 debug ! ( "cat_rvalue_node ret {:?}" , ret) ;
922879 ret
923880 }
924881
925882 pub fn cat_rvalue ( & self ,
926883 cmt_hir_id : hir:: HirId ,
927884 span : Span ,
928- temp_scope : ty:: Region < ' tcx > ,
929885 expr_ty : Ty < ' tcx > ) -> cmt_ < ' tcx > {
930886 let ret = cmt_ {
931887 hir_id : cmt_hir_id,
932888 span : span,
933- cat : Categorization :: Rvalue ( temp_scope ) ,
889+ cat : Categorization :: Rvalue ,
934890 mutbl : McDeclared ,
935891 ty : expr_ty,
936892 note : NoteNone
@@ -1378,9 +1334,9 @@ impl<'tcx> cmt_<'tcx> {
13781334 //! determines how long the value in `self` remains live.
13791335
13801336 match self . cat {
1381- Categorization :: Rvalue ( .. ) |
1337+ Categorization :: Rvalue |
13821338 Categorization :: StaticItem |
1383- Categorization :: ThreadLocal ( .. ) |
1339+ Categorization :: ThreadLocal |
13841340 Categorization :: Local ( ..) |
13851341 Categorization :: Deref ( _, UnsafePtr ( ..) ) |
13861342 Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
@@ -1411,8 +1367,8 @@ impl<'tcx> cmt_<'tcx> {
14111367 b. freely_aliasable ( )
14121368 }
14131369
1414- Categorization :: Rvalue ( .. ) |
1415- Categorization :: ThreadLocal ( .. ) |
1370+ Categorization :: Rvalue |
1371+ Categorization :: ThreadLocal |
14161372 Categorization :: Local ( ..) |
14171373 Categorization :: Upvar ( ..) |
14181374 Categorization :: Deref ( _, UnsafePtr ( ..) ) => { // yes, it's aliasable, but...
@@ -1459,10 +1415,10 @@ impl<'tcx> cmt_<'tcx> {
14591415 Categorization :: StaticItem => {
14601416 "static item" . into ( )
14611417 }
1462- Categorization :: ThreadLocal ( .. ) => {
1418+ Categorization :: ThreadLocal => {
14631419 "thread-local static item" . into ( )
14641420 }
1465- Categorization :: Rvalue ( .. ) => {
1421+ Categorization :: Rvalue => {
14661422 "non-place" . into ( )
14671423 }
14681424 Categorization :: Local ( vid) => {
0 commit comments