Add postfix match MatchSource to HIR
This commit is contained in:
parent
d4ba888787
commit
567c98b30f
4 changed files with 10 additions and 3 deletions
|
@ -181,10 +181,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
ExprKind::TryBlock(body) => self.lower_expr_try_block(body),
|
ExprKind::TryBlock(body) => self.lower_expr_try_block(body),
|
||||||
ExprKind::Match(expr, arms, _) => hir::ExprKind::Match(
|
ExprKind::Match(expr, arms, kind) => hir::ExprKind::Match(
|
||||||
self.lower_expr(expr),
|
self.lower_expr(expr),
|
||||||
self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))),
|
self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))),
|
||||||
hir::MatchSource::Normal,
|
match kind {
|
||||||
|
MatchKind::Prefix => hir::MatchSource::Normal,
|
||||||
|
MatchKind::Postfix => hir::MatchSource::Postfix,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
|
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
|
||||||
ExprKind::Closure(box Closure {
|
ExprKind::Closure(box Closure {
|
||||||
|
|
|
@ -2004,6 +2004,8 @@ pub enum LocalSource {
|
||||||
pub enum MatchSource {
|
pub enum MatchSource {
|
||||||
/// A `match _ { .. }`.
|
/// A `match _ { .. }`.
|
||||||
Normal,
|
Normal,
|
||||||
|
/// A `expr.match { .. }`.
|
||||||
|
Postfix,
|
||||||
/// A desugared `for _ in _ { .. }` loop.
|
/// A desugared `for _ in _ { .. }` loop.
|
||||||
ForLoopDesugar,
|
ForLoopDesugar,
|
||||||
/// A desugared `?` operator.
|
/// A desugared `?` operator.
|
||||||
|
@ -2020,6 +2022,7 @@ impl MatchSource {
|
||||||
use MatchSource::*;
|
use MatchSource::*;
|
||||||
match self {
|
match self {
|
||||||
Normal => "match",
|
Normal => "match",
|
||||||
|
Postfix => ".match",
|
||||||
ForLoopDesugar => "for",
|
ForLoopDesugar => "for",
|
||||||
TryDesugar(_) => "?",
|
TryDesugar(_) => "?",
|
||||||
AwaitDesugar => ".await",
|
AwaitDesugar => ".await",
|
||||||
|
|
|
@ -481,6 +481,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
||||||
// when the iterator is an uninhabited type. unreachable_code will trigger instead.
|
// when the iterator is an uninhabited type. unreachable_code will trigger instead.
|
||||||
hir::MatchSource::ForLoopDesugar if arms.len() == 1 => {}
|
hir::MatchSource::ForLoopDesugar if arms.len() == 1 => {}
|
||||||
hir::MatchSource::ForLoopDesugar
|
hir::MatchSource::ForLoopDesugar
|
||||||
|
| hir::MatchSource::Postfix
|
||||||
| hir::MatchSource::Normal
|
| hir::MatchSource::Normal
|
||||||
| hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report),
|
| hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report),
|
||||||
// Unreachable patterns in try and await expressions occur when one of
|
// Unreachable patterns in try and await expressions occur when one of
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl NonConstExpr {
|
||||||
Self::Match(TryDesugar(_)) => &[sym::const_try],
|
Self::Match(TryDesugar(_)) => &[sym::const_try],
|
||||||
|
|
||||||
// All other expressions are allowed.
|
// All other expressions are allowed.
|
||||||
Self::Loop(Loop | While) | Self::Match(Normal | FormatArgs) => &[],
|
Self::Loop(Loop | While) | Self::Match(Normal | Postfix | FormatArgs) => &[],
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(gates)
|
Some(gates)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue