@@ -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,7 +23,7 @@ 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
28
this. in_scope ( ( region_scope, source_info) , LintLevel :: Inherited , move |this| {
30
29
if targeted_by_break {
@@ -50,8 +49,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
50
49
destination : Place < ' tcx > ,
51
50
mut block : BasicBlock ,
52
51
span : Span ,
53
- stmts : Vec < StmtRef < ' tcx > > ,
54
- expr : Option < ExprRef < ' tcx > > ,
52
+ stmts : & [ Stmt < ' _ , ' tcx > ] ,
53
+ expr : Option < & Expr < ' _ , ' tcx > > ,
55
54
safety_mode : BlockSafety ,
56
55
) -> BlockAnd < ( ) > {
57
56
let this = self ;
@@ -79,18 +78,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
79
78
this. update_source_scope_for_safety_mode ( span, safety_mode) ;
80
79
81
80
let source_info = this. source_info ( span) ;
82
- for stmt in stmts {
83
- let Stmt { kind, opt_destruction_scope } = this. hir . mirror ( stmt) ;
81
+ for Stmt { kind, opt_destruction_scope } in stmts {
84
82
match kind {
85
- StmtKind :: Expr { scope, expr } => {
83
+ & StmtKind :: Expr { scope, expr } => {
86
84
this. block_context . push ( BlockFrame :: Statement { ignores_expr_result : true } ) ;
87
85
unpack ! (
88
86
block = this. in_opt_scope(
89
87
opt_destruction_scope. map( |de| ( de, source_info) ) ,
90
88
|this| {
91
89
let si = ( scope, source_info) ;
92
90
this. in_scope( si, LintLevel :: Inherited , |this| {
93
- let expr = this. hir. mirror( expr) ;
94
91
this. stmt_expr( block, expr, Some ( scope) )
95
92
} )
96
93
}
@@ -102,45 +99,44 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
102
99
this. block_context . push ( BlockFrame :: Statement { ignores_expr_result } ) ;
103
100
104
101
// Enter the remainder scope, i.e., the bindings' destruction scope.
105
- this. push_scope ( ( remainder_scope, source_info) ) ;
102
+ this. push_scope ( ( * remainder_scope, source_info) ) ;
106
103
let_scope_stack. push ( remainder_scope) ;
107
104
108
105
// Declare the bindings, which may create a source scope.
109
- let remainder_span =
110
- remainder_scope. span ( this. hir . tcx ( ) , & this. hir . region_scope_tree ) ;
106
+ let remainder_span = remainder_scope. span ( this. tcx , this. region_scope_tree ) ;
111
107
112
108
let visibility_scope =
113
109
Some ( this. new_source_scope ( remainder_span, LintLevel :: Inherited , None ) ) ;
114
110
115
111
// Evaluate the initializer, if present.
116
112
if let Some ( init) = initializer {
117
- let initializer_span = init. span ( ) ;
113
+ let initializer_span = init. span ;
118
114
119
115
unpack ! (
120
116
block = this. in_opt_scope(
121
117
opt_destruction_scope. map( |de| ( de, source_info) ) ,
122
118
|this| {
123
- let scope = ( init_scope, source_info) ;
124
- this. in_scope( scope, lint_level, |this| {
119
+ let scope = ( * init_scope, source_info) ;
120
+ this. in_scope( scope, * lint_level, |this| {
125
121
this. declare_bindings(
126
122
visibility_scope,
127
123
remainder_span,
128
- & pattern,
124
+ pattern,
129
125
ArmHasGuard ( false ) ,
130
126
Some ( ( None , initializer_span) ) ,
131
127
) ;
132
- this. expr_into_pattern( block, pattern, init)
128
+ this. expr_into_pattern( block, pattern. clone ( ) , init)
133
129
} )
134
130
}
135
131
)
136
132
) ;
137
133
} else {
138
- let scope = ( init_scope, source_info) ;
139
- unpack ! ( this. in_scope( scope, lint_level, |this| {
134
+ let scope = ( * init_scope, source_info) ;
135
+ unpack ! ( this. in_scope( scope, * lint_level, |this| {
140
136
this. declare_bindings(
141
137
visibility_scope,
142
138
remainder_span,
143
- & pattern,
139
+ pattern,
144
140
ArmHasGuard ( false ) ,
145
141
None ,
146
142
) ;
@@ -171,18 +167,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
171
167
172
168
// Then, the block may have an optional trailing expression which is a “return” value
173
169
// of the block, which is stored into `destination`.
174
- let tcx = this. hir . tcx ( ) ;
170
+ let tcx = this. tcx ;
175
171
let destination_ty = destination. ty ( & this. local_decls , tcx) . ty ;
176
172
if let Some ( expr) = expr {
177
173
let tail_result_is_ignored =
178
174
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 } ) ;
175
+ this. block_context
176
+ . push ( BlockFrame :: TailExpr { tail_result_is_ignored, span : expr. span } ) ;
184
177
185
- unpack ! ( block = this. into ( destination, block, expr) ) ;
178
+ unpack ! ( block = this. expr_into_dest ( destination, block, expr) ) ;
186
179
let popped = this. block_context . pop ( ) ;
187
180
188
181
assert ! ( popped. map_or( false , |bf| bf. is_tail_expr( ) ) ) ;
@@ -194,13 +187,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
194
187
if destination_ty. is_unit ( ) {
195
188
// We only want to assign an implicit `()` as the return value of the block if the
196
189
// block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.)
197
- this. cfg . push_assign_unit ( block, source_info, destination, this. hir . tcx ( ) ) ;
190
+ this. cfg . push_assign_unit ( block, source_info, destination, this. tcx ) ;
198
191
}
199
192
}
200
193
// Finally, we pop all the let scopes before exiting out from the scope of block
201
194
// itself.
202
195
for scope in let_scope_stack. into_iter ( ) . rev ( ) {
203
- unpack ! ( block = this. pop_scope( ( scope, source_info) , block) ) ;
196
+ unpack ! ( block = this. pop_scope( ( * scope, source_info) , block) ) ;
204
197
}
205
198
// Restore the original source scope.
206
199
this. source_scope = outer_source_scope;
@@ -220,7 +213,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
220
213
Safety :: Safe => { }
221
214
// no longer treat `unsafe fn`s as `unsafe` contexts (see RFC #2585)
222
215
Safety :: FnUnsafe
223
- if self . hir . tcx ( ) . lint_level_at_node ( UNSAFE_OP_IN_UNSAFE_FN , hir_id) . 0
216
+ if self . tcx . lint_level_at_node ( UNSAFE_OP_IN_UNSAFE_FN , hir_id) . 0
224
217
!= Level :: Allow => { }
225
218
_ => return ,
226
219
}
0 commit comments