Skip to content

Commit 202509b

Browse files
authored
Rollup merge of #123395 - compiler-errors:postfix-matches-fixes-2, r=petrochenkov
More postfix match fixes These affect diagnostics only, as far as I can tell. I'm too lazy to come up with UI tests, but I could be convinced otherwise. Specifically, I think changing the precedence computation actually doesn't change anything, but tweaking `contains_exterior_struct_lit` does mean that some diagnostics will begin parenthesizing `S {}.match {}`.
2 parents 5f74403 + 4cb5643 commit 202509b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_ast/src/ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,8 @@ impl Expr {
12761276
ExprKind::While(..) => ExprPrecedence::While,
12771277
ExprKind::ForLoop { .. } => ExprPrecedence::ForLoop,
12781278
ExprKind::Loop(..) => ExprPrecedence::Loop,
1279-
ExprKind::Match(..) => ExprPrecedence::Match,
1279+
ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match,
1280+
ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch,
12801281
ExprKind::Closure(..) => ExprPrecedence::Closure,
12811282
ExprKind::Block(..) => ExprPrecedence::Block,
12821283
ExprKind::TryBlock(..) => ExprPrecedence::TryBlock,

compiler/rustc_ast/src/util/parser.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ pub enum ExprPrecedence {
281281
ForLoop,
282282
Loop,
283283
Match,
284+
PostfixMatch,
284285
ConstBlock,
285286
Block,
286287
TryBlock,
@@ -334,7 +335,8 @@ impl ExprPrecedence {
334335
| ExprPrecedence::InlineAsm
335336
| ExprPrecedence::Mac
336337
| ExprPrecedence::FormatArgs
337-
| ExprPrecedence::OffsetOf => PREC_POSTFIX,
338+
| ExprPrecedence::OffsetOf
339+
| ExprPrecedence::PostfixMatch => PREC_POSTFIX,
338340

339341
// Never need parens
340342
ExprPrecedence::Array
@@ -390,7 +392,8 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
390392
| ast::ExprKind::Cast(x, _)
391393
| ast::ExprKind::Type(x, _)
392394
| ast::ExprKind::Field(x, _)
393-
| ast::ExprKind::Index(x, _, _) => {
395+
| ast::ExprKind::Index(x, _, _)
396+
| ast::ExprKind::Match(x, _, ast::MatchKind::Postfix) => {
394397
// &X { y: 1 }, X { y: 1 }.y
395398
contains_exterior_struct_lit(x)
396399
}

0 commit comments

Comments
 (0)