@@ -2,7 +2,6 @@ use crate::build::matches::ArmHasGuard;
22use crate :: build:: ForGuard :: OutsideGuard ;
33use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
44use crate :: thir:: * ;
5- use rustc_hir as hir;
65use rustc_middle:: mir:: * ;
76use rustc_session:: lint:: builtin:: UNSAFE_OP_IN_UNSAFE_FN ;
87use rustc_session:: lint:: Level ;
@@ -13,7 +12,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1312 & mut self ,
1413 destination : Place < ' tcx > ,
1514 block : BasicBlock ,
16- ast_block : & ' tcx hir :: Block < ' tcx > ,
15+ ast_block : & Block < ' _ , ' tcx > ,
1716 source_info : SourceInfo ,
1817 ) -> BlockAnd < ( ) > {
1918 let Block {
@@ -24,7 +23,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2423 expr,
2524 targeted_by_break,
2625 safety_mode,
27- } = self . hir . mirror ( ast_block) ;
26+ } = * ast_block;
2827 self . in_opt_scope ( opt_destruction_scope. map ( |de| ( de, source_info) ) , move |this| {
2928 this. in_scope ( ( region_scope, source_info) , LintLevel :: Inherited , move |this| {
3029 if targeted_by_break {
@@ -50,8 +49,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5049 destination : Place < ' tcx > ,
5150 mut block : BasicBlock ,
5251 span : Span ,
53- stmts : Vec < StmtRef < ' tcx > > ,
54- expr : Option < ExprRef < ' tcx > > ,
52+ stmts : & [ Stmt < ' _ , ' tcx > ] ,
53+ expr : Option < & Expr < ' _ , ' tcx > > ,
5554 safety_mode : BlockSafety ,
5655 ) -> BlockAnd < ( ) > {
5756 let this = self ;
@@ -79,18 +78,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7978 this. update_source_scope_for_safety_mode ( span, safety_mode) ;
8079
8180 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 {
8482 match kind {
85- StmtKind :: Expr { scope, expr } => {
83+ & StmtKind :: Expr { scope, expr } => {
8684 this. block_context . push ( BlockFrame :: Statement { ignores_expr_result : true } ) ;
8785 unpack ! (
8886 block = this. in_opt_scope(
8987 opt_destruction_scope. map( |de| ( de, source_info) ) ,
9088 |this| {
9189 let si = ( scope, source_info) ;
9290 this. in_scope( si, LintLevel :: Inherited , |this| {
93- let expr = this. hir. mirror( expr) ;
9491 this. stmt_expr( block, expr, Some ( scope) )
9592 } )
9693 }
@@ -102,45 +99,44 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10299 this. block_context . push ( BlockFrame :: Statement { ignores_expr_result } ) ;
103100
104101 // 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) ) ;
106103 let_scope_stack. push ( remainder_scope) ;
107104
108105 // 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 ) ;
111107
112108 let visibility_scope =
113109 Some ( this. new_source_scope ( remainder_span, LintLevel :: Inherited , None ) ) ;
114110
115111 // Evaluate the initializer, if present.
116112 if let Some ( init) = initializer {
117- let initializer_span = init. span ( ) ;
113+ let initializer_span = init. span ;
118114
119115 unpack ! (
120116 block = this. in_opt_scope(
121117 opt_destruction_scope. map( |de| ( de, source_info) ) ,
122118 |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| {
125121 this. declare_bindings(
126122 visibility_scope,
127123 remainder_span,
128- & pattern,
124+ pattern,
129125 ArmHasGuard ( false ) ,
130126 Some ( ( None , initializer_span) ) ,
131127 ) ;
132- this. expr_into_pattern( block, pattern, init)
128+ this. expr_into_pattern( block, pattern. clone ( ) , init)
133129 } )
134130 }
135131 )
136132 ) ;
137133 } 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| {
140136 this. declare_bindings(
141137 visibility_scope,
142138 remainder_span,
143- & pattern,
139+ pattern,
144140 ArmHasGuard ( false ) ,
145141 None ,
146142 ) ;
@@ -171,18 +167,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
171167
172168 // Then, the block may have an optional trailing expression which is a “return” value
173169 // of the block, which is stored into `destination`.
174- let tcx = this. hir . tcx ( ) ;
170+ let tcx = this. tcx ;
175171 let destination_ty = destination. ty ( & this. local_decls , tcx) . ty ;
176172 if let Some ( expr) = expr {
177173 let tail_result_is_ignored =
178174 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 } ) ;
184177
185- unpack ! ( block = this. into ( destination, block, expr) ) ;
178+ unpack ! ( block = this. expr_into_dest ( destination, block, expr) ) ;
186179 let popped = this. block_context . pop ( ) ;
187180
188181 assert ! ( popped. map_or( false , |bf| bf. is_tail_expr( ) ) ) ;
@@ -194,13 +187,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
194187 if destination_ty. is_unit ( ) {
195188 // We only want to assign an implicit `()` as the return value of the block if the
196189 // 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 ) ;
198191 }
199192 }
200193 // Finally, we pop all the let scopes before exiting out from the scope of block
201194 // itself.
202195 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) ) ;
204197 }
205198 // Restore the original source scope.
206199 this. source_scope = outer_source_scope;
@@ -220,7 +213,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
220213 Safety :: Safe => { }
221214 // no longer treat `unsafe fn`s as `unsafe` contexts (see RFC #2585)
222215 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
224217 != Level :: Allow => { }
225218 _ => return ,
226219 }
0 commit comments