@@ -102,8 +102,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
102
102
/// generated via deriving here.
103
103
#[ derive( Clone , PartialEq , PartialOrd , Eq , Ord , Hash , Copy , RustcEncodable , RustcDecodable ) ]
104
104
pub struct Scope {
105
- pub ( crate ) id : hir:: ItemLocalId ,
106
- pub ( crate ) data : ScopeData ,
105
+ pub id : hir:: ItemLocalId ,
106
+ pub data : ScopeData ,
107
107
}
108
108
109
109
impl fmt:: Debug for Scope {
@@ -172,48 +172,6 @@ impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
172
172
#[ cfg( not( stage0) ) ]
173
173
static ASSERT : ( ) = [ ( ) ] [ !( mem:: size_of :: < ScopeData > ( ) == 4 ) as usize ] ;
174
174
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
-
217
175
impl Scope {
218
176
/// Returns a item-local id associated with this scope.
219
177
///
@@ -244,7 +202,7 @@ impl Scope {
244
202
return DUMMY_SP ;
245
203
}
246
204
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 {
248
206
if let Node :: Block ( ref blk) = tcx. hir . get ( node_id) {
249
207
// Want span for scope starting after the
250
208
// indexed statement and ending at end of
@@ -498,7 +456,7 @@ impl<'tcx> ScopeTree {
498
456
}
499
457
500
458
// 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 {
502
460
self . destruction_scopes . insert ( child. item_local_id ( ) , child) ;
503
461
}
504
462
}
@@ -578,10 +536,10 @@ impl<'tcx> ScopeTree {
578
536
// if there's one. Static items, for instance, won't
579
537
// have an enclosing scope, hence no scope will be
580
538
// returned.
581
- let mut id = Scope :: Node ( expr_id ) ;
539
+ let mut id = Scope { id : expr_id , data : ScopeData :: Node } ;
582
540
583
541
while let Some ( & ( p, _) ) = self . parent_map . get ( & id) {
584
- match p. data ( ) {
542
+ match p. data {
585
543
ScopeData :: Destruction => {
586
544
debug ! ( "temporary_scope({:?}) = {:?} [enclosing]" ,
587
545
expr_id, id) ;
@@ -637,7 +595,7 @@ impl<'tcx> ScopeTree {
637
595
/// Returns the id of the innermost containing body
638
596
pub fn containing_body ( & self , mut scope : Scope ) -> Option < hir:: ItemLocalId > {
639
597
loop {
640
- if let ScopeData :: CallSite = scope. data ( ) {
598
+ if let ScopeData :: CallSite = scope. data {
641
599
return Some ( scope. item_local_id ( ) ) ;
642
600
}
643
601
@@ -730,7 +688,7 @@ impl<'tcx> ScopeTree {
730
688
self . root_body . unwrap ( ) . local_id
731
689
} ) ;
732
690
733
- Scope :: CallSite ( scope )
691
+ Scope { id : scope , data : ScopeData :: CallSite }
734
692
}
735
693
736
694
/// Assuming that the provided region was defined within this `ScopeTree`,
@@ -750,7 +708,7 @@ impl<'tcx> ScopeTree {
750
708
751
709
let param_owner_id = tcx. hir . as_local_node_id ( param_owner) . unwrap ( ) ;
752
710
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 }
754
712
}
755
713
756
714
/// 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:
854
812
// except for the first such subscope, which has the
855
813
// block itself as a parent.
856
814
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
+ }
858
819
) ;
859
820
visitor. cx . var_parent = visitor. cx . parent ;
860
821
}
@@ -879,7 +840,7 @@ fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: &
879
840
}
880
841
881
842
fn 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 } ) ;
883
844
884
845
// If this is a binding then record the lifetime of that binding.
885
846
if let PatKind :: Binding ( ..) = pat. node {
@@ -1008,15 +969,15 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
1008
969
1009
970
if let hir:: ExprKind :: Yield ( ..) = expr. node {
1010
971
// 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 } ;
1012
973
loop {
1013
974
visitor. scope_tree . yield_in_scope . insert ( scope,
1014
975
( expr. span , visitor. expr_and_pat_count ) ) ;
1015
976
1016
977
// Keep traversing up while we can.
1017
978
match visitor. scope_tree . parent_map . get ( & scope) {
1018
979
// Don't cross from closure bodies to their parent.
1019
- Some ( & ( superscope, _) ) => match superscope. data ( ) {
980
+ Some ( & ( superscope, _) ) => match superscope. data {
1020
981
ScopeData :: CallSite => break ,
1021
982
_ => scope = superscope
1022
983
} ,
@@ -1280,9 +1241,9 @@ impl<'a, 'tcx> RegionResolutionVisitor<'a, 'tcx> {
1280
1241
// account for the destruction scope representing the scope of
1281
1242
// the destructors that run immediately after it completes.
1282
1243
if self . terminating_scopes . contains ( & id) {
1283
- self . enter_scope ( Scope :: Destruction ( id ) ) ;
1244
+ self . enter_scope ( Scope { id , data : ScopeData :: Destruction } ) ;
1284
1245
}
1285
- self . enter_scope ( Scope :: Node ( id ) ) ;
1246
+ self . enter_scope ( Scope { id , data : ScopeData :: Node } ) ;
1286
1247
}
1287
1248
}
1288
1249
@@ -1315,8 +1276,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
1315
1276
}
1316
1277
self . cx . root_id = Some ( body. value . hir_id . local_id ) ;
1317
1278
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 } ) ;
1320
1281
1321
1282
// The arguments and `self` are parented to the fn.
1322
1283
self . cx . var_parent = self . cx . parent . take ( ) ;
0 commit comments