@@ -177,6 +177,14 @@ impl CodeExtentData {
177
177
}
178
178
179
179
impl CodeExtent {
180
+ #[ inline]
181
+ fn into_option ( self ) -> Option < CodeExtent > {
182
+ if self == ROOT_CODE_EXTENT {
183
+ None
184
+ } else {
185
+ Some ( self )
186
+ }
187
+ }
180
188
pub fn node_id ( & self , region_maps : & RegionMaps ) -> ast:: NodeId {
181
189
region_maps. code_extent_data ( * self ) . node_id ( )
182
190
}
@@ -325,7 +333,7 @@ impl RegionMaps {
325
333
// have (bogus) NodeId-s that overlap items created during
326
334
// inlining.
327
335
// We probably shouldn't be creating bogus code extents
328
- // through .
336
+ // though .
329
337
let idx = * o. get ( ) ;
330
338
if parent == DUMMY_CODE_EXTENT {
331
339
info ! ( "CodeExtent({}) = {:?} [parent={}] BOGUS!" ,
@@ -413,10 +421,7 @@ impl RegionMaps {
413
421
414
422
pub fn opt_encl_scope ( & self , id : CodeExtent ) -> Option < CodeExtent > {
415
423
//! Returns the narrowest scope that encloses `id`, if any.
416
- match self . scope_map . borrow ( ) [ id. 0 as usize ] {
417
- ROOT_CODE_EXTENT => None ,
418
- c => Some ( c)
419
- }
424
+ self . scope_map . borrow ( ) [ id. 0 as usize ] . into_option ( )
420
425
}
421
426
422
427
#[ allow( dead_code) ] // used in middle::cfg
@@ -445,32 +450,33 @@ impl RegionMaps {
445
450
None => { }
446
451
}
447
452
453
+ let scope_map : & [ CodeExtent ] = & self . scope_map . borrow ( ) ;
454
+ let code_extents: & [ CodeExtentData ] = & self . code_extents . borrow ( ) ;
455
+
448
456
// else, locate the innermost terminating scope
449
457
// if there's one. Static items, for instance, won't
450
458
// have an enclosing scope, hence no scope will be
451
459
// returned.
460
+ let expr_extent = self . node_extent ( expr_id) ;
452
461
// For some reason, the expr's scope itself is skipped here.
453
- let mut id = match self . opt_encl_scope ( self . node_extent ( expr_id ) ) {
462
+ let mut id = match scope_map [ expr_extent . 0 as usize ] . into_option ( ) {
454
463
Some ( i) => i,
455
- None => { return None ; }
464
+ _ => return None
456
465
} ;
457
466
458
- loop { match self . opt_encl_scope ( id) {
459
- Some ( p) => {
460
- match self . code_extent_data ( p) {
461
- CodeExtentData :: DestructionScope ( ..) => {
462
- debug ! ( "temporary_scope({:?}) = {:?} [enclosing]" ,
463
- expr_id, id) ;
464
- return Some ( id) ;
465
- }
466
- _ => id = p
467
+ while let Some ( p) = scope_map[ id. 0 as usize ] . into_option ( ) {
468
+ match code_extents[ p. 0 as usize ] {
469
+ CodeExtentData :: DestructionScope ( ..) => {
470
+ debug ! ( "temporary_scope({:?}) = {:?} [enclosing]" ,
471
+ expr_id, id) ;
472
+ return Some ( id) ;
467
473
}
474
+ _ => id = p
468
475
}
469
- None => {
470
- debug ! ( "temporary_scope({:?}) = None" , expr_id) ;
471
- return None ;
472
- }
473
- } }
476
+ }
477
+
478
+ debug ! ( "temporary_scope({:?}) = None" , expr_id) ;
479
+ return None ;
474
480
}
475
481
476
482
pub fn var_region ( & self , id : ast:: NodeId ) -> ty:: Region {
@@ -591,24 +597,20 @@ impl RegionMaps {
591
597
let mut i = 0 ;
592
598
while i < 32 {
593
599
buf[ i] = scope;
594
- let superscope = scope_map[ scope. 0 as usize ] ;
595
- if superscope == ROOT_CODE_EXTENT {
596
- return & buf[ ..i+1 ] ;
597
- } else {
598
- scope = superscope;
600
+ match scope_map[ scope. 0 as usize ] . into_option ( ) {
601
+ Some ( superscope) => scope = superscope,
602
+ _ => return & buf[ ..i+1 ]
599
603
}
600
604
i += 1 ;
601
605
}
602
606
603
607
* vec = Vec :: with_capacity ( 64 ) ;
604
- vec. extend ( ( * buf) . into_iter ( ) ) ;
608
+ vec. push_all ( buf) ;
605
609
loop {
606
610
vec. push ( scope) ;
607
- let superscope = scope_map[ scope. 0 as usize ] ;
608
- if superscope == ROOT_CODE_EXTENT {
609
- return & * vec;
610
- } else {
611
- scope = superscope;
611
+ match scope_map[ scope. 0 as usize ] . into_option ( ) {
612
+ Some ( superscope) => scope = superscope,
613
+ _ => return & * vec
612
614
}
613
615
}
614
616
}
0 commit comments