@@ -87,7 +87,7 @@ use std::fmt;
87
87
use std:: hash:: { Hash , Hasher } ;
88
88
use rustc_data_structures:: sync:: Lrc ;
89
89
use std:: rc:: Rc ;
90
- use util:: nodemap:: ItemLocalSet ;
90
+ use util:: nodemap:: ItemLocalMap ;
91
91
92
92
#[ derive( Clone , Debug , PartialEq ) ]
93
93
pub enum Categorization < ' tcx > {
@@ -295,7 +295,7 @@ pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
295
295
pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
296
296
pub region_scope_tree : & ' a region:: ScopeTree ,
297
297
pub tables : & ' a ty:: TypeckTables < ' tcx > ,
298
- rvalue_promotable_map : Option < Lrc < ItemLocalSet > > ,
298
+ rvalue_promotable_map : Option < Lrc < ItemLocalMap < ty :: Promotability > > > ,
299
299
infcx : Option < & ' a InferCtxt < ' a , ' gcx , ' tcx > > ,
300
300
}
301
301
@@ -404,7 +404,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
404
404
pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
405
405
region_scope_tree : & ' a region:: ScopeTree ,
406
406
tables : & ' a ty:: TypeckTables < ' tcx > ,
407
- rvalue_promotable_map : Option < Lrc < ItemLocalSet > > )
407
+ rvalue_promotable_map : Option < Lrc < ItemLocalMap < ty :: Promotability > > > )
408
408
-> MemCategorizationContext < ' a , ' tcx , ' tcx > {
409
409
MemCategorizationContext {
410
410
tcx,
@@ -946,32 +946,35 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
946
946
span,
947
947
expr_ty,
948
948
) ;
949
- let promotable = self . rvalue_promotable_map . as_ref ( ) . map ( |m| m. contains ( & hir_id. local_id ) )
950
- . unwrap_or ( false ) ;
949
+ use ty:: Promotability :: * ;
950
+ let promotability = self
951
+ . rvalue_promotable_map
952
+ . as_ref ( )
953
+ . and_then ( |m| m. get ( & hir_id. local_id ) . cloned ( ) )
954
+ . unwrap_or ( NotPromotable ) ;
951
955
952
956
debug ! (
953
957
"cat_rvalue_node: promotable = {:?}" ,
954
- promotable ,
958
+ promotability ,
955
959
) ;
956
960
957
961
// Always promote `[T; 0]` (even when e.g. borrowed mutably).
958
- let promotable = match expr_ty. sty {
959
- ty:: TyArray ( _, len) if len. assert_usize ( self . tcx ) == Some ( 0 ) => true ,
960
- _ => promotable ,
962
+ let promotability = match expr_ty. sty {
963
+ ty:: TyArray ( _, len) if len. assert_usize ( self . tcx ) == Some ( 0 ) => Promotable ,
964
+ _ => promotability ,
961
965
} ;
962
966
963
967
debug ! (
964
968
"cat_rvalue_node: promotable = {:?} (2)" ,
965
- promotable ,
969
+ promotability ,
966
970
) ;
967
971
968
972
// Compute maximum lifetime of this rvalue. This is 'static if
969
973
// we can promote to a constant, otherwise equal to enclosing temp
970
974
// lifetime.
971
- let re = if promotable {
972
- self . tcx . types . re_static
973
- } else {
974
- self . temporary_scope ( hir_id. local_id )
975
+ let re = match promotability {
976
+ Promotable | NotInspectable => self . tcx . types . re_static ,
977
+ NotPromotable => self . temporary_scope ( hir_id. local_id ) ,
975
978
} ;
976
979
let ret = self . cat_rvalue ( hir_id, span, re, expr_ty) ;
977
980
debug ! ( "cat_rvalue_node ret {:?}" , ret) ;
0 commit comments