@@ -102,8 +102,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
102102/// generated via deriving here.
103103#[ derive( Clone , PartialEq , PartialOrd , Eq , Ord , Hash , Copy , RustcEncodable , RustcDecodable ) ]
104104pub struct Scope {
105- pub ( crate ) id : hir:: ItemLocalId ,
106- pub ( crate ) data : ScopeData ,
105+ pub id : hir:: ItemLocalId ,
106+ pub data : ScopeData ,
107107}
108108
109109impl fmt:: Debug for Scope {
@@ -172,48 +172,6 @@ impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
172172#[ cfg( not( stage0) ) ]
173173static ASSERT : ( ) = [ ( ) ] [ !( mem:: size_of :: < ScopeData > ( ) == 4 ) as usize ] ;
174174
175- #[ allow( non_snake_case) ]
176- impl Scope {
177- #[ inline]
178- pub fn data ( self ) -> ScopeData {
179- self . data
180- }
181-
182- #[ inline]
183- pub fn new ( id : hir:: ItemLocalId , data : ScopeData ) -> Self {
184- Scope { id, data }
185- }
186-
187- #[ inline]
188- pub fn Node ( id : hir:: ItemLocalId ) -> Self {
189- Self :: new ( id, ScopeData :: Node )
190- }
191-
192- #[ inline]
193- pub fn CallSite ( id : hir:: ItemLocalId ) -> Self {
194- Self :: new ( id, ScopeData :: CallSite )
195- }
196-
197- #[ inline]
198- pub fn Arguments ( id : hir:: ItemLocalId ) -> Self {
199- Self :: new ( id, ScopeData :: Arguments )
200- }
201-
202- #[ inline]
203- pub fn Destruction ( id : hir:: ItemLocalId ) -> Self {
204- Self :: new ( id, ScopeData :: Destruction )
205- }
206-
207- #[ inline]
208- pub fn Remainder (
209- id : hir:: ItemLocalId ,
210- first : FirstStatementIndex ,
211- ) -> Self {
212- Self :: new ( id, ScopeData :: Remainder ( first) )
213- }
214- }
215-
216-
217175impl Scope {
218176 /// Returns a item-local id associated with this scope.
219177 ///
@@ -244,7 +202,7 @@ impl Scope {
244202 return DUMMY_SP ;
245203 }
246204 let span = tcx. hir . span ( node_id) ;
247- if let ScopeData :: Remainder ( first_statement_index) = self . data ( ) {
205+ if let ScopeData :: Remainder ( first_statement_index) = self . data {
248206 if let Node :: Block ( ref blk) = tcx. hir . get ( node_id) {
249207 // Want span for scope starting after the
250208 // indexed statement and ending at end of
@@ -498,7 +456,7 @@ impl<'tcx> ScopeTree {
498456 }
499457
500458 // record the destruction scopes for later so we can query them
501- if let ScopeData :: Destruction = child. data ( ) {
459+ if let ScopeData :: Destruction = child. data {
502460 self . destruction_scopes . insert ( child. item_local_id ( ) , child) ;
503461 }
504462 }
@@ -578,10 +536,10 @@ impl<'tcx> ScopeTree {
578536 // if there's one. Static items, for instance, won't
579537 // have an enclosing scope, hence no scope will be
580538 // returned.
581- let mut id = Scope :: Node ( expr_id ) ;
539+ let mut id = Scope { id : expr_id , data : ScopeData :: Node } ;
582540
583541 while let Some ( & ( p, _) ) = self . parent_map . get ( & id) {
584- match p. data ( ) {
542+ match p. data {
585543 ScopeData :: Destruction => {
586544 debug ! ( "temporary_scope({:?}) = {:?} [enclosing]" ,
587545 expr_id, id) ;
@@ -637,7 +595,7 @@ impl<'tcx> ScopeTree {
637595 /// Returns the id of the innermost containing body
638596 pub fn containing_body ( & self , mut scope : Scope ) -> Option < hir:: ItemLocalId > {
639597 loop {
640- if let ScopeData :: CallSite = scope. data ( ) {
598+ if let ScopeData :: CallSite = scope. data {
641599 return Some ( scope. item_local_id ( ) ) ;
642600 }
643601
@@ -730,7 +688,7 @@ impl<'tcx> ScopeTree {
730688 self . root_body . unwrap ( ) . local_id
731689 } ) ;
732690
733- Scope :: CallSite ( scope )
691+ Scope { id : scope , data : ScopeData :: CallSite }
734692 }
735693
736694 /// Assuming that the provided region was defined within this `ScopeTree`,
@@ -750,7 +708,7 @@ impl<'tcx> ScopeTree {
750708
751709 let param_owner_id = tcx. hir . as_local_node_id ( param_owner) . unwrap ( ) ;
752710 let body_id = tcx. hir . body_owned_by ( param_owner_id) ;
753- Scope :: CallSite ( tcx. hir . body ( body_id) . value . hir_id . local_id )
711+ Scope { id : tcx. hir . body ( body_id) . value . hir_id . local_id , data : ScopeData :: CallSite }
754712 }
755713
756714 /// Checks whether the given scope contains a `yield`. If so,
@@ -854,7 +812,10 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk:
854812 // except for the first such subscope, which has the
855813 // block itself as a parent.
856814 visitor. enter_scope (
857- Scope :: Remainder ( blk. hir_id . local_id , FirstStatementIndex :: new ( i) )
815+ Scope {
816+ id : blk. hir_id . local_id ,
817+ data : ScopeData :: Remainder ( FirstStatementIndex :: new ( i) )
818+ }
858819 ) ;
859820 visitor. cx . var_parent = visitor. cx . parent ;
860821 }
@@ -879,7 +840,7 @@ fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: &
879840}
880841
881842fn resolve_pat < ' a , ' tcx > ( visitor : & mut RegionResolutionVisitor < ' a , ' tcx > , pat : & ' tcx hir:: Pat ) {
882- visitor. record_child_scope ( Scope :: Node ( pat. hir_id . local_id ) ) ;
843+ visitor. record_child_scope ( Scope { id : pat. hir_id . local_id , data : ScopeData :: Node } ) ;
883844
884845 // If this is a binding then record the lifetime of that binding.
885846 if let PatKind :: Binding ( ..) = pat. node {
@@ -1008,15 +969,15 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
1008969
1009970 if let hir:: ExprKind :: Yield ( ..) = expr. node {
1010971 // Mark this expr's scope and all parent scopes as containing `yield`.
1011- let mut scope = Scope :: Node ( expr. hir_id . local_id ) ;
972+ let mut scope = Scope { id : expr. hir_id . local_id , data : ScopeData :: Node } ;
1012973 loop {
1013974 visitor. scope_tree . yield_in_scope . insert ( scope,
1014975 ( expr. span , visitor. expr_and_pat_count ) ) ;
1015976
1016977 // Keep traversing up while we can.
1017978 match visitor. scope_tree . parent_map . get ( & scope) {
1018979 // Don't cross from closure bodies to their parent.
1019- Some ( & ( superscope, _) ) => match superscope. data ( ) {
980+ Some ( & ( superscope, _) ) => match superscope. data {
1020981 ScopeData :: CallSite => break ,
1021982 _ => scope = superscope
1022983 } ,
@@ -1280,9 +1241,9 @@ impl<'a, 'tcx> RegionResolutionVisitor<'a, 'tcx> {
12801241 // account for the destruction scope representing the scope of
12811242 // the destructors that run immediately after it completes.
12821243 if self . terminating_scopes . contains ( & id) {
1283- self . enter_scope ( Scope :: Destruction ( id ) ) ;
1244+ self . enter_scope ( Scope { id , data : ScopeData :: Destruction } ) ;
12841245 }
1285- self . enter_scope ( Scope :: Node ( id ) ) ;
1246+ self . enter_scope ( Scope { id , data : ScopeData :: Node } ) ;
12861247 }
12871248}
12881249
@@ -1315,8 +1276,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
13151276 }
13161277 self . cx . root_id = Some ( body. value . hir_id . local_id ) ;
13171278
1318- self . enter_scope ( Scope :: CallSite ( body. value . hir_id . local_id ) ) ;
1319- self . enter_scope ( Scope :: Arguments ( body. value . hir_id . local_id ) ) ;
1279+ self . enter_scope ( Scope { id : body. value . hir_id . local_id , data : ScopeData :: CallSite } ) ;
1280+ self . enter_scope ( Scope { id : body. value . hir_id . local_id , data : ScopeData :: Arguments } ) ;
13201281
13211282 // The arguments and `self` are parented to the fn.
13221283 self . cx . var_parent = self . cx . parent . take ( ) ;
0 commit comments