@@ -87,7 +87,7 @@ use std::fmt;
8787use std:: hash:: { Hash , Hasher } ;
8888use rustc_data_structures:: sync:: Lrc ;
8989use std:: rc:: Rc ;
90- use util:: nodemap:: ItemLocalSet ;
90+ use util:: nodemap:: ItemLocalMap ;
9191
9292#[ derive( Clone , Debug , PartialEq ) ]
9393pub enum Categorization < ' tcx > {
@@ -295,7 +295,7 @@ pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
295295 pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
296296 pub region_scope_tree : & ' a region:: ScopeTree ,
297297 pub tables : & ' a ty:: TypeckTables < ' tcx > ,
298- rvalue_promotable_map : Option < Lrc < ItemLocalSet > > ,
298+ rvalue_promotable_map : Option < Lrc < ItemLocalMap < ty :: Promotability > > > ,
299299 infcx : Option < & ' a InferCtxt < ' a , ' gcx , ' tcx > > ,
300300}
301301
@@ -404,7 +404,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
404404 pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
405405 region_scope_tree : & ' a region:: ScopeTree ,
406406 tables : & ' a ty:: TypeckTables < ' tcx > ,
407- rvalue_promotable_map : Option < Lrc < ItemLocalSet > > )
407+ rvalue_promotable_map : Option < Lrc < ItemLocalMap < ty :: Promotability > > > )
408408 -> MemCategorizationContext < ' a , ' tcx , ' tcx > {
409409 MemCategorizationContext {
410410 tcx,
@@ -946,32 +946,35 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
946946 span,
947947 expr_ty,
948948 ) ;
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 ) ;
951955
952956 debug ! (
953957 "cat_rvalue_node: promotable = {:?}" ,
954- promotable ,
958+ promotability ,
955959 ) ;
956960
957961 // 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 ,
961965 } ;
962966
963967 debug ! (
964968 "cat_rvalue_node: promotable = {:?} (2)" ,
965- promotable ,
969+ promotability ,
966970 ) ;
967971
968972 // Compute maximum lifetime of this rvalue. This is 'static if
969973 // we can promote to a constant, otherwise equal to enclosing temp
970974 // 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 ) ,
975978 } ;
976979 let ret = self . cat_rvalue ( hir_id, span, re, expr_ty) ;
977980 debug ! ( "cat_rvalue_node ret {:?}" , ret) ;
0 commit comments