@@ -21,62 +21,52 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
21
21
fn make_mirror < ' a > ( self , cx : & mut Cx < ' a , ' tcx > ) -> Block < ' tcx > {
22
22
// We have to eagerly translate the "spine" of the statements
23
23
// in order to get the lexical scoping correctly.
24
- let stmts = mirror_stmts ( cx, self . id , self . stmts . iter ( ) . enumerate ( ) ) ;
24
+ let stmts = mirror_stmts ( cx, self . id , & * self . stmts ) ;
25
25
Block {
26
26
extent : cx. tcx . region_maps . node_extent ( self . id ) ,
27
27
span : self . span ,
28
28
stmts : stmts,
29
- expr : self . expr . to_ref ( ) ,
29
+ expr : self . expr . to_ref ( )
30
30
}
31
31
}
32
32
}
33
33
34
- fn mirror_stmts < ' a , ' tcx : ' a , STMTS > ( cx : & mut Cx < ' a , ' tcx > ,
35
- block_id : ast:: NodeId ,
36
- mut stmts : STMTS )
37
- -> Vec < StmtRef < ' tcx > >
38
- where STMTS : Iterator < Item =( usize , & ' tcx hir:: Stmt ) >
34
+ fn mirror_stmts < ' a , ' tcx : ' a > ( cx : & mut Cx < ' a , ' tcx > ,
35
+ block_id : ast:: NodeId ,
36
+ stmts : & ' tcx [ hir:: Stmt ] )
37
+ -> Vec < StmtRef < ' tcx > >
39
38
{
40
39
let mut result = vec ! [ ] ;
41
- while let Some ( ( index, stmt) ) = stmts. next ( ) {
40
+ for ( index, stmt) in stmts. iter ( ) . enumerate ( ) {
42
41
match stmt. node {
43
42
hir:: StmtExpr ( ref expr, id) | hir:: StmtSemi ( ref expr, id) =>
44
- result. push (
45
- StmtRef :: Mirror (
46
- Box :: new ( Stmt { span : stmt. span ,
47
- kind : StmtKind :: Expr {
48
- scope : cx. tcx . region_maps . node_extent ( id) ,
49
- expr : expr. to_ref ( ) } } ) ) ) ,
50
-
51
- hir:: StmtDecl ( ref decl, id) => {
52
- match decl. node {
53
- hir:: DeclItem ( ..) => { /* ignore for purposes of the MIR */ }
54
- hir:: DeclLocal ( ref local) => {
55
- let remainder_extent = CodeExtentData :: Remainder ( BlockRemainder {
56
- block : block_id,
57
- first_statement_index : index as u32 ,
58
- } ) ;
59
- let remainder_extent =
60
- cx. tcx . region_maps . lookup_code_extent ( remainder_extent) ;
61
-
62
- // pull in all following statements, since
63
- // they are within the scope of this let:
64
- let following_stmts = mirror_stmts ( cx, block_id, stmts) ;
65
-
66
- let pattern = cx. irrefutable_pat ( & local. pat ) ;
67
- result. push ( StmtRef :: Mirror ( Box :: new ( Stmt {
68
- span : stmt. span ,
69
- kind : StmtKind :: Let {
70
- remainder_scope : remainder_extent,
71
- init_scope : cx. tcx . region_maps . node_extent ( id) ,
72
- pattern : pattern,
73
- initializer : local. init . to_ref ( ) ,
74
- stmts : following_stmts,
75
- } ,
76
- } ) ) ) ;
77
-
78
- return result;
43
+ result. push ( StmtRef :: Mirror ( Box :: new ( Stmt {
44
+ span : stmt. span ,
45
+ kind : StmtKind :: Expr {
46
+ scope : cx. tcx . region_maps . node_extent ( id) ,
47
+ expr : expr. to_ref ( )
79
48
}
49
+ } ) ) ) ,
50
+ hir:: StmtDecl ( ref decl, id) => match decl. node {
51
+ hir:: DeclItem ( ..) => { /* ignore for purposes of the MIR */ }
52
+ hir:: DeclLocal ( ref local) => {
53
+ let remainder_extent = CodeExtentData :: Remainder ( BlockRemainder {
54
+ block : block_id,
55
+ first_statement_index : index as u32 ,
56
+ } ) ;
57
+ let remainder_extent =
58
+ cx. tcx . region_maps . lookup_code_extent ( remainder_extent) ;
59
+
60
+ let pattern = cx. irrefutable_pat ( & local. pat ) ;
61
+ result. push ( StmtRef :: Mirror ( Box :: new ( Stmt {
62
+ span : stmt. span ,
63
+ kind : StmtKind :: Let {
64
+ remainder_scope : remainder_extent,
65
+ init_scope : cx. tcx . region_maps . node_extent ( id) ,
66
+ pattern : pattern,
67
+ initializer : local. init . to_ref ( ) ,
68
+ } ,
69
+ } ) ) ) ;
80
70
}
81
71
}
82
72
}
0 commit comments