|
3 | 3 | use crate::build::expr::category::{Category, RvalueFunc};
|
4 | 4 | use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
5 | 5 | use crate::hair::*;
|
6 |
| -use rustc_middle::mir::*; |
7 |
| -use rustc_middle::ty::{self, CanonicalUserTypeAnnotation}; |
8 | 6 | use rustc_data_structures::fx::FxHashMap;
|
9 | 7 | use rustc_hir as hir;
|
| 8 | +use rustc_middle::mir::*; |
| 9 | +use rustc_middle::ty::{self, CanonicalUserTypeAnnotation}; |
10 | 10 | use rustc_span::symbol::sym;
|
11 | 11 |
|
12 | 12 | use rustc_target::spec::abi::Abi;
|
@@ -139,31 +139,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
139 | 139 | // Start the loop.
|
140 | 140 | this.cfg.goto(block, source_info, loop_block);
|
141 | 141 |
|
142 |
| - this.in_breakable_scope( |
143 |
| - Some(loop_block), |
144 |
| - exit_block, |
145 |
| - destination.clone(), |
146 |
| - move |this| { |
147 |
| - // conduct the test, if necessary |
148 |
| - let body_block = this.cfg.start_new_block(); |
149 |
| - let diverge_cleanup = this.diverge_cleanup(); |
150 |
| - this.cfg.terminate( |
151 |
| - loop_block, |
152 |
| - source_info, |
153 |
| - TerminatorKind::FalseUnwind { |
154 |
| - real_target: body_block, |
155 |
| - unwind: Some(diverge_cleanup), |
156 |
| - }, |
157 |
| - ); |
158 |
| - |
159 |
| - // The “return” value of the loop body must always be an unit. We therefore |
160 |
| - // introduce a unit temporary as the destination for the loop body. |
161 |
| - let tmp = this.get_unit_temp(); |
162 |
| - // Execute the body, branching back to the test. |
163 |
| - let body_block_end = unpack!(this.into(tmp, body_block, body)); |
164 |
| - this.cfg.goto(body_block_end, source_info, loop_block); |
165 |
| - }, |
166 |
| - ); |
| 142 | + this.in_breakable_scope(Some(loop_block), exit_block, destination, move |this| { |
| 143 | + // conduct the test, if necessary |
| 144 | + let body_block = this.cfg.start_new_block(); |
| 145 | + let diverge_cleanup = this.diverge_cleanup(); |
| 146 | + this.cfg.terminate( |
| 147 | + loop_block, |
| 148 | + source_info, |
| 149 | + TerminatorKind::FalseUnwind { |
| 150 | + real_target: body_block, |
| 151 | + unwind: Some(diverge_cleanup), |
| 152 | + }, |
| 153 | + ); |
| 154 | + |
| 155 | + // The “return” value of the loop body must always be an unit. We therefore |
| 156 | + // introduce a unit temporary as the destination for the loop body. |
| 157 | + let tmp = this.get_unit_temp(); |
| 158 | + // Execute the body, branching back to the test. |
| 159 | + let body_block_end = unpack!(this.into(tmp, body_block, body)); |
| 160 | + this.cfg.goto(body_block_end, source_info, loop_block); |
| 161 | + }); |
167 | 162 | exit_block.unit()
|
168 | 163 | }
|
169 | 164 | ExprKind::Call { ty, fun, args, from_hir_call } => {
|
@@ -278,26 +273,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
278 | 273 |
|
279 | 274 | let field_names = this.hir.all_fields(adt_def, variant_index);
|
280 | 275 |
|
281 |
| - let fields = |
282 |
| - if let Some(FruInfo { base, field_types }) = base { |
283 |
| - let base = unpack!(block = this.as_place(block, base)); |
284 |
| - |
285 |
| - // MIR does not natively support FRU, so for each |
286 |
| - // base-supplied field, generate an operand that |
287 |
| - // reads it from the base. |
288 |
| - field_names |
289 |
| - .into_iter() |
290 |
| - .zip(field_types.into_iter()) |
291 |
| - .map(|(n, ty)| match fields_map.get(&n) { |
292 |
| - Some(v) => v.clone(), |
293 |
| - None => this.consume_by_copy_or_move( |
294 |
| - this.hir.tcx().mk_place_field(base.clone(), n, ty), |
295 |
| - ), |
296 |
| - }) |
297 |
| - .collect() |
298 |
| - } else { |
299 |
| - field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect() |
300 |
| - }; |
| 276 | + let fields = if let Some(FruInfo { base, field_types }) = base { |
| 277 | + let base = unpack!(block = this.as_place(block, base)); |
| 278 | + |
| 279 | + // MIR does not natively support FRU, so for each |
| 280 | + // base-supplied field, generate an operand that |
| 281 | + // reads it from the base. |
| 282 | + field_names |
| 283 | + .into_iter() |
| 284 | + .zip(field_types.into_iter()) |
| 285 | + .map(|(n, ty)| match fields_map.get(&n) { |
| 286 | + Some(v) => v.clone(), |
| 287 | + None => this.consume_by_copy_or_move( |
| 288 | + this.hir.tcx().mk_place_field(base, n, ty), |
| 289 | + ), |
| 290 | + }) |
| 291 | + .collect() |
| 292 | + } else { |
| 293 | + field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect() |
| 294 | + }; |
301 | 295 |
|
302 | 296 | let inferred_ty = expr.ty;
|
303 | 297 | let user_ty = user_ty.map(|ty| {
|
|
0 commit comments