@@ -2,7 +2,6 @@ use crate::build::matches::ArmHasGuard;
2
2
use crate :: build:: ForGuard :: OutsideGuard ;
3
3
use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
4
4
use crate :: thir:: * ;
5
- use rustc_hir as hir;
6
5
use rustc_middle:: mir:: * ;
7
6
use rustc_session:: lint:: builtin:: UNSAFE_OP_IN_UNSAFE_FN ;
8
7
use rustc_session:: lint:: Level ;
@@ -13,7 +12,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13
12
& mut self ,
14
13
destination : Place < ' tcx > ,
15
14
block : BasicBlock ,
16
- ast_block : & ' tcx hir :: Block < ' tcx > ,
15
+ ast_block : & Block < ' tcx > ,
17
16
source_info : SourceInfo ,
18
17
) -> BlockAnd < ( ) > {
19
18
let Block {
@@ -24,22 +23,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24
23
expr,
25
24
targeted_by_break,
26
25
safety_mode,
27
- } = self . hir . mirror ( ast_block) ;
26
+ } = ast_block;
28
27
self . in_opt_scope ( opt_destruction_scope. map ( |de| ( de, source_info) ) , move |this| {
29
- this. in_scope ( ( region_scope, source_info) , LintLevel :: Inherited , move |this| {
30
- if targeted_by_break {
31
- this. in_breakable_scope ( None , destination, span, |this| {
28
+ this. in_scope ( ( * region_scope, source_info) , LintLevel :: Inherited , move |this| {
29
+ if * targeted_by_break {
30
+ this. in_breakable_scope ( None , destination, * span, |this| {
32
31
Some ( this. ast_block_stmts (
33
32
destination,
34
33
block,
35
- span,
36
- stmts,
37
- expr,
38
- safety_mode,
34
+ * span,
35
+ & stmts,
36
+ expr. as_deref ( ) ,
37
+ * safety_mode,
39
38
) )
40
39
} )
41
40
} else {
42
- this. ast_block_stmts ( destination, block, span, stmts, expr, safety_mode)
41
+ this. ast_block_stmts (
42
+ destination,
43
+ block,
44
+ * span,
45
+ & stmts,
46
+ expr. as_deref ( ) ,
47
+ * safety_mode,
48
+ )
43
49
}
44
50
} )
45
51
} )
@@ -50,8 +56,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
50
56
destination : Place < ' tcx > ,
51
57
mut block : BasicBlock ,
52
58
span : Span ,
53
- stmts : Vec < StmtRef < ' tcx > > ,
54
- expr : Option < ExprRef < ' tcx > > ,
59
+ stmts : & [ Stmt < ' tcx > ] ,
60
+ expr : Option < & Expr < ' tcx > > ,
55
61
safety_mode : BlockSafety ,
56
62
) -> BlockAnd < ( ) > {
57
63
let this = self ;
@@ -79,19 +85,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
79
85
this. update_source_scope_for_safety_mode ( span, safety_mode) ;
80
86
81
87
let source_info = this. source_info ( span) ;
82
- for stmt in stmts {
83
- let Stmt { kind, opt_destruction_scope } = this. hir . mirror ( stmt) ;
88
+ for Stmt { kind, opt_destruction_scope } in stmts {
84
89
match kind {
85
90
StmtKind :: Expr { scope, expr } => {
86
91
this. block_context . push ( BlockFrame :: Statement { ignores_expr_result : true } ) ;
87
92
unpack ! (
88
93
block = this. in_opt_scope(
89
94
opt_destruction_scope. map( |de| ( de, source_info) ) ,
90
95
|this| {
91
- let si = ( scope, source_info) ;
96
+ let si = ( * scope, source_info) ;
92
97
this. in_scope( si, LintLevel :: Inherited , |this| {
93
- let expr = this. hir. mirror( expr) ;
94
- this. stmt_expr( block, expr, Some ( scope) )
98
+ this. stmt_expr( block, & expr, Some ( * scope) )
95
99
} )
96
100
}
97
101
)
@@ -102,7 +106,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
102
106
this. block_context . push ( BlockFrame :: Statement { ignores_expr_result } ) ;
103
107
104
108
// Enter the remainder scope, i.e., the bindings' destruction scope.
105
- this. push_scope ( ( remainder_scope, source_info) ) ;
109
+ this. push_scope ( ( * remainder_scope, source_info) ) ;
106
110
let_scope_stack. push ( remainder_scope) ;
107
111
108
112
// Declare the bindings, which may create a source scope.
@@ -114,29 +118,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
114
118
115
119
// Evaluate the initializer, if present.
116
120
if let Some ( init) = initializer {
117
- let initializer_span = init. span ( ) ;
121
+ let initializer_span = init. span ;
118
122
119
123
unpack ! (
120
124
block = this. in_opt_scope(
121
125
opt_destruction_scope. map( |de| ( de, source_info) ) ,
122
126
|this| {
123
- let scope = ( init_scope, source_info) ;
124
- this. in_scope( scope, lint_level, |this| {
127
+ let scope = ( * init_scope, source_info) ;
128
+ this. in_scope( scope, * lint_level, |this| {
125
129
this. declare_bindings(
126
130
visibility_scope,
127
131
remainder_span,
128
132
& pattern,
129
133
ArmHasGuard ( false ) ,
130
134
Some ( ( None , initializer_span) ) ,
131
135
) ;
132
- this. expr_into_pattern( block, pattern, init)
136
+ this. expr_into_pattern( block, pattern. clone ( ) , & init)
133
137
} )
134
138
}
135
139
)
136
140
) ;
137
141
} else {
138
- let scope = ( init_scope, source_info) ;
139
- unpack ! ( this. in_scope( scope, lint_level, |this| {
142
+ let scope = ( * init_scope, source_info) ;
143
+ unpack ! ( this. in_scope( scope, * lint_level, |this| {
140
144
this. declare_bindings(
141
145
visibility_scope,
142
146
remainder_span,
@@ -176,13 +180,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
176
180
if let Some ( expr) = expr {
177
181
let tail_result_is_ignored =
178
182
destination_ty. is_unit ( ) || this. block_context . currently_ignores_tail_results ( ) ;
179
- let span = match expr {
180
- ExprRef :: Thir ( expr) => expr. span ,
181
- ExprRef :: Mirror ( ref expr) => expr. span ,
182
- } ;
183
- this. block_context . push ( BlockFrame :: TailExpr { tail_result_is_ignored, span } ) ;
183
+ this. block_context
184
+ . push ( BlockFrame :: TailExpr { tail_result_is_ignored, span : expr. span } ) ;
184
185
185
- unpack ! ( block = this. into ( destination, block, expr) ) ;
186
+ unpack ! ( block = this. expr_into_dest ( destination, block, expr) ) ;
186
187
let popped = this. block_context . pop ( ) ;
187
188
188
189
assert ! ( popped. map_or( false , |bf| bf. is_tail_expr( ) ) ) ;
@@ -200,7 +201,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
200
201
// Finally, we pop all the let scopes before exiting out from the scope of block
201
202
// itself.
202
203
for scope in let_scope_stack. into_iter ( ) . rev ( ) {
203
- unpack ! ( block = this. pop_scope( ( scope, source_info) , block) ) ;
204
+ unpack ! ( block = this. pop_scope( ( * scope, source_info) , block) ) ;
204
205
}
205
206
// Restore the original source scope.
206
207
this. source_scope = outer_source_scope;
0 commit comments