Skip to content

Commit 7a414de

Browse files
committed
store the span of the match expression, and use it for diagnostics
1 parent e85c871 commit 7a414de

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Diff for: compiler/rustc_middle/src/thir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,11 @@ pub enum ExprKind<'tcx> {
377377
},
378378
/// A `#[loop_match] loop { state = 'blk: { match state { ... } } }` expression.
379379
LoopMatch {
380+
/// The state variable that is updated, and also the scrutinee of the match
380381
state: ExprId,
381-
382382
region_scope: region::Scope,
383383
arms: Box<[ArmId]>,
384+
match_span: Span,
384385
},
385386
/// Special expression representing the `let` part of an `if let` or similar construct
386387
/// (including `if let` guards in match arms, and let-chains formed by `&&`).

Diff for: compiler/rustc_mir_build/src/builder/expr/into.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
245245
None
246246
})
247247
}
248-
ExprKind::LoopMatch { state, region_scope, ref arms } => {
248+
ExprKind::LoopMatch { state, region_scope, match_span, ref arms } => {
249249
// FIXME add diagram
250250

251251
let loop_block = this.cfg.start_new_block();
@@ -268,7 +268,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
268268
let scrutinee_place_builder =
269269
unpack!(body_block = this.as_place_builder(body_block, state));
270270
let scrutinee_span = this.thir.exprs[state].span;
271-
let match_start_span = scrutinee_span; // span.shrink_to_lo().to(scrutinee_span); FIXME
271+
let match_start_span = match_span.shrink_to_lo().to(scrutinee_span);
272272

273273
let mut patterns = Vec::with_capacity(arms.len());
274274
for &arm_id in arms.iter() {
@@ -311,8 +311,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
311311
scrutinee_span,
312312
arms,
313313
built_tree,
314-
// FIXME this should be the span of just the match
315-
this.source_info(expr_span),
314+
this.source_info(match_span),
316315
)
317316
},
318317
))

Diff for: compiler/rustc_mir_build/src/thir/cx/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
938938
},
939939

940940
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
941+
match_span: block_body_expr.span,
941942
}
942943
} else {
943944
let block_ty = self.typeck_results.node_type(body.hir_id);

Diff for: compiler/rustc_mir_build/src/thir/print.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,12 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
319319
self.print_expr(*body, depth_lvl + 2);
320320
print_indented!(self, ")", depth_lvl);
321321
}
322-
LoopMatch { state, region_scope, arms } => {
322+
LoopMatch { state, region_scope, match_span, arms } => {
323323
print_indented!(self, "LoopMatch (", depth_lvl);
324324
print_indented!(self, "state:", depth_lvl + 1);
325325
self.print_expr(*state, depth_lvl + 2);
326326
print_indented!(self, format!("region_scope: {:?}", region_scope), depth_lvl + 1);
327+
print_indented!(self, format!("match_span: {:?}", match_span), depth_lvl + 1);
327328

328329
print_indented!(self, "arms: [", depth_lvl + 1);
329330
for arm_id in arms.iter() {

0 commit comments

Comments
 (0)