Skip to content

Commit 567c98b

Browse files
committed
Add postfix match MatchSource to HIR
1 parent d4ba888 commit 567c98b

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
181181
)
182182
}),
183183
ExprKind::TryBlock(body) => self.lower_expr_try_block(body),
184-
ExprKind::Match(expr, arms, _) => hir::ExprKind::Match(
184+
ExprKind::Match(expr, arms, kind) => hir::ExprKind::Match(
185185
self.lower_expr(expr),
186186
self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))),
187-
hir::MatchSource::Normal,
187+
match kind {
188+
MatchKind::Prefix => hir::MatchSource::Normal,
189+
MatchKind::Postfix => hir::MatchSource::Postfix,
190+
},
188191
),
189192
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
190193
ExprKind::Closure(box Closure {

Diff for: compiler/rustc_hir/src/hir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,8 @@ pub enum LocalSource {
20042004
pub enum MatchSource {
20052005
/// A `match _ { .. }`.
20062006
Normal,
2007+
/// A `expr.match { .. }`.
2008+
Postfix,
20072009
/// A desugared `for _ in _ { .. }` loop.
20082010
ForLoopDesugar,
20092011
/// A desugared `?` operator.
@@ -2020,6 +2022,7 @@ impl MatchSource {
20202022
use MatchSource::*;
20212023
match self {
20222024
Normal => "match",
2025+
Postfix => ".match",
20232026
ForLoopDesugar => "for",
20242027
TryDesugar(_) => "?",
20252028
AwaitDesugar => ".await",

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
481481
// when the iterator is an uninhabited type. unreachable_code will trigger instead.
482482
hir::MatchSource::ForLoopDesugar if arms.len() == 1 => {}
483483
hir::MatchSource::ForLoopDesugar
484+
| hir::MatchSource::Postfix
484485
| hir::MatchSource::Normal
485486
| hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report),
486487
// Unreachable patterns in try and await expressions occur when one of

Diff for: compiler/rustc_passes/src/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl NonConstExpr {
4848
Self::Match(TryDesugar(_)) => &[sym::const_try],
4949

5050
// All other expressions are allowed.
51-
Self::Loop(Loop | While) | Self::Match(Normal | FormatArgs) => &[],
51+
Self::Loop(Loop | While) | Self::Match(Normal | Postfix | FormatArgs) => &[],
5252
};
5353

5454
Some(gates)

0 commit comments

Comments
 (0)