@@ -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
} ;
@@ -878,16 +866,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
878
866
ret
879
867
}
880
868
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
-
891
869
pub fn cat_rvalue_node ( & self ,
892
870
hir_id : hir:: HirId ,
893
871
span : Span ,
@@ -896,41 +874,19 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
896
874
debug ! ( "cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})" ,
897
875
hir_id, span, expr_ty) ;
898
876
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) ;
921
878
debug ! ( "cat_rvalue_node ret {:?}" , ret) ;
922
879
ret
923
880
}
924
881
925
882
pub fn cat_rvalue ( & self ,
926
883
cmt_hir_id : hir:: HirId ,
927
884
span : Span ,
928
- temp_scope : ty:: Region < ' tcx > ,
929
885
expr_ty : Ty < ' tcx > ) -> cmt_ < ' tcx > {
930
886
let ret = cmt_ {
931
887
hir_id : cmt_hir_id,
932
888
span : span,
933
- cat : Categorization :: Rvalue ( temp_scope ) ,
889
+ cat : Categorization :: Rvalue ,
934
890
mutbl : McDeclared ,
935
891
ty : expr_ty,
936
892
note : NoteNone
@@ -1378,9 +1334,9 @@ impl<'tcx> cmt_<'tcx> {
1378
1334
//! determines how long the value in `self` remains live.
1379
1335
1380
1336
match self . cat {
1381
- Categorization :: Rvalue ( .. ) |
1337
+ Categorization :: Rvalue |
1382
1338
Categorization :: StaticItem |
1383
- Categorization :: ThreadLocal ( .. ) |
1339
+ Categorization :: ThreadLocal |
1384
1340
Categorization :: Local ( ..) |
1385
1341
Categorization :: Deref ( _, UnsafePtr ( ..) ) |
1386
1342
Categorization :: Deref ( _, BorrowedPtr ( ..) ) |
@@ -1411,8 +1367,8 @@ impl<'tcx> cmt_<'tcx> {
1411
1367
b. freely_aliasable ( )
1412
1368
}
1413
1369
1414
- Categorization :: Rvalue ( .. ) |
1415
- Categorization :: ThreadLocal ( .. ) |
1370
+ Categorization :: Rvalue |
1371
+ Categorization :: ThreadLocal |
1416
1372
Categorization :: Local ( ..) |
1417
1373
Categorization :: Upvar ( ..) |
1418
1374
Categorization :: Deref ( _, UnsafePtr ( ..) ) => { // yes, it's aliasable, but...
@@ -1459,10 +1415,10 @@ impl<'tcx> cmt_<'tcx> {
1459
1415
Categorization :: StaticItem => {
1460
1416
"static item" . into ( )
1461
1417
}
1462
- Categorization :: ThreadLocal ( .. ) => {
1418
+ Categorization :: ThreadLocal => {
1463
1419
"thread-local static item" . into ( )
1464
1420
}
1465
- Categorization :: Rvalue ( .. ) => {
1421
+ Categorization :: Rvalue => {
1466
1422
"non-place" . into ( )
1467
1423
}
1468
1424
Categorization :: Local ( vid) => {
0 commit comments