@@ -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,22 +23,29 @@ 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| {
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| {
3231 Some ( this. ast_block_stmts (
3332 destination,
3433 block,
35- span,
36- stmts,
37- expr,
38- safety_mode,
34+ * span,
35+ & stmts,
36+ expr. as_deref ( ) ,
37+ * safety_mode,
3938 ) )
4039 } )
4140 } 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+ )
4349 }
4450 } )
4551 } )
@@ -50,8 +56,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5056 destination : Place < ' tcx > ,
5157 mut block : BasicBlock ,
5258 span : Span ,
53- stmts : Vec < StmtRef < ' tcx > > ,
54- expr : Option < ExprRef < ' tcx > > ,
59+ stmts : & [ Stmt < ' tcx > ] ,
60+ expr : Option < & Expr < ' tcx > > ,
5561 safety_mode : BlockSafety ,
5662 ) -> BlockAnd < ( ) > {
5763 let this = self ;
@@ -79,19 +85,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7985 this. update_source_scope_for_safety_mode ( span, safety_mode) ;
8086
8187 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 {
8489 match kind {
8590 StmtKind :: Expr { scope, expr } => {
8691 this. block_context . push ( BlockFrame :: Statement { ignores_expr_result : true } ) ;
8792 unpack ! (
8893 block = this. in_opt_scope(
8994 opt_destruction_scope. map( |de| ( de, source_info) ) ,
9095 |this| {
91- let si = ( scope, source_info) ;
96+ let si = ( * scope, source_info) ;
9297 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) )
9599 } )
96100 }
97101 )
@@ -102,7 +106,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
102106 this. block_context . push ( BlockFrame :: Statement { ignores_expr_result } ) ;
103107
104108 // 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) ) ;
106110 let_scope_stack. push ( remainder_scope) ;
107111
108112 // Declare the bindings, which may create a source scope.
@@ -114,29 +118,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
114118
115119 // Evaluate the initializer, if present.
116120 if let Some ( init) = initializer {
117- let initializer_span = init. span ( ) ;
121+ let initializer_span = init. span ;
118122
119123 unpack ! (
120124 block = this. in_opt_scope(
121125 opt_destruction_scope. map( |de| ( de, source_info) ) ,
122126 |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| {
125129 this. declare_bindings(
126130 visibility_scope,
127131 remainder_span,
128132 & pattern,
129133 ArmHasGuard ( false ) ,
130134 Some ( ( None , initializer_span) ) ,
131135 ) ;
132- this. expr_into_pattern( block, pattern, init)
136+ this. expr_into_pattern( block, pattern. clone ( ) , & init)
133137 } )
134138 }
135139 )
136140 ) ;
137141 } 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| {
140144 this. declare_bindings(
141145 visibility_scope,
142146 remainder_span,
@@ -176,13 +180,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
176180 if let Some ( expr) = expr {
177181 let tail_result_is_ignored =
178182 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 } ) ;
184185
185- unpack ! ( block = this. into ( destination, block, expr) ) ;
186+ unpack ! ( block = this. expr_into_dest ( destination, block, expr) ) ;
186187 let popped = this. block_context . pop ( ) ;
187188
188189 assert ! ( popped. map_or( false , |bf| bf. is_tail_expr( ) ) ) ;
@@ -200,7 +201,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
200201 // Finally, we pop all the let scopes before exiting out from the scope of block
201202 // itself.
202203 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) ) ;
204205 }
205206 // Restore the original source scope.
206207 this. source_scope = outer_source_scope;
0 commit comments