This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
compiler/rustc_ast_pretty/src/pprust/state
rfc-2011-nicer-assert-messages Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,10 @@ impl<'a> State<'a> {
244244 ( & ast:: ExprKind :: Let { .. } , _) if !parser:: needs_par_as_let_scrutinee ( prec) => {
245245 parser:: PREC_FORCE_PAREN
246246 }
247+ // For a binary expression like `(match () { _ => a }) OP b`, the parens are required
248+ // otherwise the parser would interpret `match () { _ => a }` as a statement,
249+ // with the remaining `OP b` not making sense. So we force parens.
250+ ( & ast:: ExprKind :: Match ( ..) , _) => parser:: PREC_FORCE_PAREN ,
247251 _ => left_prec,
248252 } ;
249253
Original file line number Diff line number Diff line change 1+ // run-pass
2+
3+ macro_rules! stringify_item {
4+ ( $item: item) => {
5+ stringify!( $item)
6+ } ;
7+ }
8+
9+ macro_rules! repro {
10+ ( $expr: expr) => {
11+ stringify_item! {
12+ pub fn repro( ) -> bool {
13+ $expr
14+ }
15+ }
16+ } ;
17+ }
18+
19+ fn main ( ) {
20+ assert_eq ! (
21+ repro!( match ( ) { ( ) => true } | true ) ,
22+ "pub fn repro() -> bool { (match () { () => true, }) | true }"
23+ ) ;
24+ }
Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ fn main() {
164164 // mac call
165165
166166 // match
167- [ match elem { _ => elem } == 3 ] => "Assertion failed: match elem { _ => elem, } == 3"
167+ [ match elem { _ => elem } == 3 ] => "Assertion failed: ( match elem { _ => elem, }) == 3"
168168
169169 // ret
170170 [ ( || { return elem; } ) ( ) == 3 ] => "Assertion failed: (|| { return elem; })() == 3"
You can’t perform that action at this time.
0 commit comments