Skip to content

Commit b234486

Browse files
Rollup merge of rust-lang#149329 - Jarcho:for_question_ctxt, r=davidtwco
Mark match arms in try and for as being from desugarings. Some of the arms created by these desugarings have an expression which isn't marked as coming from the desugaring. e.g. try generates `Continue(val) => val` where the expression has the span of the original parameter (done for diagnostic purposes). Since the arm created just used that span they end up without a desugaring mark unnecessarily. This is only a minor annoyance with some work I'm doing in clippy.
2 parents 729b31c + 09f774d commit b234486

File tree

1 file changed

+11
-10
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+11
-10
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
966966
hir::ExprKind::Break(this.lower_loop_destination(None), Some(x_expr));
967967
this.arena.alloc(this.expr(gen_future_span, expr_break))
968968
});
969-
self.arm(ready_pat, break_x)
969+
self.arm(ready_pat, break_x, span)
970970
};
971971

972972
// `::std::task::Poll::Pending => {}`
973973
let pending_arm = {
974974
let pending_pat = self.pat_lang_item_variant(span, hir::LangItem::PollPending, &[]);
975975
let empty_block = self.expr_block_empty(span);
976-
self.arm(pending_pat, empty_block)
976+
self.arm(pending_pat, empty_block, span)
977977
};
978978

979979
let inner_match_stmt = {
@@ -1027,7 +1027,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10271027
});
10281028

10291029
// mut __awaitee => loop { ... }
1030-
let awaitee_arm = self.arm(awaitee_pat, loop_expr);
1030+
let awaitee_arm = self.arm(awaitee_pat, loop_expr, span);
10311031

10321032
// `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
10331033
let into_future_expr = match await_kind {
@@ -1817,7 +1817,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18171817
let break_expr =
18181818
self.with_loop_scope(loop_hir_id, |this| this.expr_break_alloc(for_span));
18191819
let pat = self.pat_none(for_span);
1820-
self.arm(pat, break_expr)
1820+
self.arm(pat, break_expr, for_span)
18211821
};
18221822

18231823
// Some(<pat>) => <body>,
@@ -1826,7 +1826,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18261826
let body_block =
18271827
self.with_loop_scope(loop_hir_id, |this| this.lower_block(body, false));
18281828
let body_expr = self.arena.alloc(self.expr_block(body_block));
1829-
self.arm(some_pat, body_expr)
1829+
self.arm(some_pat, body_expr, for_span)
18301830
};
18311831

18321832
// `mut iter`
@@ -1885,7 +1885,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18851885
let loop_expr = self.arena.alloc(hir::Expr { hir_id: loop_hir_id, kind, span: for_span });
18861886

18871887
// `mut iter => { ... }`
1888-
let iter_arm = self.arm(iter_pat, loop_expr);
1888+
let iter_arm = self.arm(iter_pat, loop_expr, for_span);
18891889

18901890
let match_expr = match loop_kind {
18911891
ForLoopKind::For => {
@@ -1930,7 +1930,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19301930
hir::LangItem::IntoAsyncIterIntoIter,
19311931
arena_vec![self; head],
19321932
);
1933-
let iter_arm = self.arm(async_iter_pat, inner_match_expr);
1933+
let iter_arm = self.arm(async_iter_pat, inner_match_expr, for_span);
19341934
self.arena.alloc(self.expr_match(
19351935
for_span,
19361936
iter,
@@ -1997,7 +1997,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19971997
let val_expr = self.expr_ident(span, val_ident, val_pat_nid);
19981998
self.lower_attrs(val_expr.hir_id, &attrs, span, Target::Expression);
19991999
let continue_pat = self.pat_cf_continue(unstable_span, val_pat);
2000-
self.arm(continue_pat, val_expr)
2000+
self.arm(continue_pat, val_expr, try_span)
20012001
};
20022002

20032003
// `ControlFlow::Break(residual) =>
@@ -2040,7 +2040,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20402040
self.lower_attrs(ret_expr.hir_id, &attrs, span, Target::Expression);
20412041

20422042
let break_pat = self.pat_cf_break(try_span, residual_local);
2043-
self.arm(break_pat, ret_expr)
2043+
self.arm(break_pat, ret_expr, try_span)
20442044
};
20452045

20462046
hir::ExprKind::Match(
@@ -2368,12 +2368,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
23682368
&mut self,
23692369
pat: &'hir hir::Pat<'hir>,
23702370
expr: &'hir hir::Expr<'hir>,
2371+
span: Span,
23712372
) -> hir::Arm<'hir> {
23722373
hir::Arm {
23732374
hir_id: self.next_id(),
23742375
pat,
23752376
guard: None,
2376-
span: self.lower_span(expr.span),
2377+
span: self.lower_span(span),
23772378
body: expr,
23782379
}
23792380
}

0 commit comments

Comments
 (0)