@@ -79,12 +79,11 @@ use std::fmt;
79
79
use std:: hash:: { Hash , Hasher } ;
80
80
use rustc_data_structures:: fx:: FxIndexMap ;
81
81
use std:: rc:: Rc ;
82
- use crate :: util:: nodemap:: ItemLocalSet ;
83
82
84
83
#[ derive( Clone , Debug , PartialEq ) ]
85
84
pub 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
88
87
StaticItem ,
89
88
Upvar ( Upvar ) , // upvar referenced by closure env
90
89
Local ( hir:: HirId ) , // local variable
@@ -219,7 +218,6 @@ pub struct MemCategorizationContext<'a, 'tcx> {
219
218
pub upvars : Option < & ' tcx FxIndexMap < hir:: HirId , hir:: Upvar > > ,
220
219
pub region_scope_tree : & ' a region:: ScopeTree ,
221
220
pub tables : & ' a ty:: TypeckTables < ' tcx > ,
222
- rvalue_promotable_map : Option < & ' tcx ItemLocalSet > ,
223
221
infcx : Option < & ' a InferCtxt < ' a , ' tcx > > ,
224
222
}
225
223
@@ -335,15 +333,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
335
333
body_owner : DefId ,
336
334
region_scope_tree : & ' a region:: ScopeTree ,
337
335
tables : & ' a ty:: TypeckTables < ' tcx > ,
338
- rvalue_promotable_map : Option < & ' tcx ItemLocalSet > ,
339
336
) -> MemCategorizationContext < ' a , ' tcx > {
340
337
MemCategorizationContext {
341
338
tcx,
342
339
body_owner,
343
340
upvars : tcx. upvars ( body_owner) ,
344
341
region_scope_tree,
345
342
tables,
346
- rvalue_promotable_map,
347
343
infcx : None ,
348
344
param_env,
349
345
}
@@ -369,19 +365,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
369
365
) -> MemCategorizationContext < ' a , ' tcx > {
370
366
let tcx = infcx. tcx ;
371
367
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
-
378
368
MemCategorizationContext {
379
369
tcx,
380
370
body_owner,
381
371
upvars : tcx. upvars ( body_owner) ,
382
372
region_scope_tree,
383
373
tables,
384
- rvalue_promotable_map,
385
374
infcx : Some ( infcx) ,
386
375
param_env,
387
376
}
@@ -664,8 +653,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
664
653
. any ( |attr| attr. check_name ( sym:: thread_local) ) ;
665
654
666
655
let cat = if is_thread_local {
667
- let re = self . temporary_scope ( hir_id. local_id ) ;
668
- Categorization :: ThreadLocal ( re)
656
+ Categorization :: ThreadLocal
669
657
} else {
670
658
Categorization :: StaticItem
671
659
} ;
@@ -876,16 +864,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
876
864
ret
877
865
}
878
866
879
- /// Returns the lifetime of a temporary created by expr with id `id`.
880
- /// This could be `'static` if `id` is part of a constant expression.
881
- pub fn temporary_scope ( & self , id : hir:: ItemLocalId ) -> ty:: Region < ' tcx > {
882
- let scope = self . region_scope_tree . temporary_scope ( id) ;
883
- self . tcx . mk_region ( match scope {
884
- Some ( scope) => ty:: ReScope ( scope) ,
885
- None => ty:: ReStatic
886
- } )
887
- }
888
-
889
867
pub fn cat_rvalue_node ( & self ,
890
868
hir_id : hir:: HirId ,
891
869
span : Span ,
@@ -894,41 +872,19 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
894
872
debug ! ( "cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})" ,
895
873
hir_id, span, expr_ty) ;
896
874
897
- let promotable = self . rvalue_promotable_map . as_ref ( ) . map ( |m| m. contains ( & hir_id. local_id ) )
898
- . unwrap_or ( false ) ;
899
-
900
- debug ! ( "cat_rvalue_node: promotable = {:?}" , promotable) ;
901
-
902
- // Always promote `[T; 0]` (even when e.g., borrowed mutably).
903
- let promotable = match expr_ty. kind {
904
- ty:: Array ( _, len) if len. try_eval_usize ( self . tcx , self . param_env ) == Some ( 0 ) => true ,
905
- _ => promotable,
906
- } ;
907
-
908
- debug ! ( "cat_rvalue_node: promotable = {:?} (2)" , promotable) ;
909
-
910
- // Compute maximum lifetime of this rvalue. This is 'static if
911
- // we can promote to a constant, otherwise equal to enclosing temp
912
- // lifetime.
913
- let re = if promotable {
914
- self . tcx . lifetimes . re_static
915
- } else {
916
- self . temporary_scope ( hir_id. local_id )
917
- } ;
918
- let ret = self . cat_rvalue ( hir_id, span, re, expr_ty) ;
875
+ let ret = self . cat_rvalue ( hir_id, span, expr_ty) ;
919
876
debug ! ( "cat_rvalue_node ret {:?}" , ret) ;
920
877
ret
921
878
}
922
879
923
880
pub fn cat_rvalue ( & self ,
924
881
cmt_hir_id : hir:: HirId ,
925
882
span : Span ,
926
- temp_scope : ty:: Region < ' tcx > ,
927
883
expr_ty : Ty < ' tcx > ) -> cmt_ < ' tcx > {
928
884
let ret = cmt_ {
929
885
hir_id : cmt_hir_id,
930
886
span : span,
931
- cat : Categorization :: Rvalue ( temp_scope ) ,
887
+ cat : Categorization :: Rvalue ,
932
888
mutbl : McDeclared ,
933
889
ty : expr_ty,
934
890
note : NoteNone
@@ -1376,9 +1332,9 @@ impl<'tcx> cmt_<'tcx> {
1376
1332
//! determines how long the value in `self` remains live.
1377
1333
1378
1334
match self . cat {
1379
- Categorization :: Rvalue ( .. ) |
1335
+ Categorization :: Rvalue |
1380
1336
Categorization :: StaticItem |
1381
- Categorization :: ThreadLocal ( .. ) |
1337
+ Categorization :: ThreadLocal |
1382
1338
Categorization :: Local ( ..) |
1383
1339
Categorization :: Deref ( _, UnsafePtr ( ..) ) |
1384
1340
Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
@@ -1409,8 +1365,8 @@ impl<'tcx> cmt_<'tcx> {
1409
1365
b. freely_aliasable ( )
1410
1366
}
1411
1367
1412
- Categorization :: Rvalue ( .. ) |
1413
- Categorization :: ThreadLocal ( .. ) |
1368
+ Categorization :: Rvalue |
1369
+ Categorization :: ThreadLocal |
1414
1370
Categorization :: Local ( ..) |
1415
1371
Categorization :: Upvar ( ..) |
1416
1372
Categorization :: Deref ( _, UnsafePtr ( ..) ) => { // yes, it's aliasable, but...
@@ -1457,10 +1413,10 @@ impl<'tcx> cmt_<'tcx> {
1457
1413
Categorization :: StaticItem => {
1458
1414
"static item" . into ( )
1459
1415
}
1460
- Categorization :: ThreadLocal ( .. ) => {
1416
+ Categorization :: ThreadLocal => {
1461
1417
"thread-local static item" . into ( )
1462
1418
}
1463
- Categorization :: Rvalue ( .. ) => {
1419
+ Categorization :: Rvalue => {
1464
1420
"non-place" . into ( )
1465
1421
}
1466
1422
Categorization :: Local ( vid) => {
0 commit comments