File tree 3 files changed +29
-1
lines changed
compiler/rustc_ast_pretty/src/pprust/state
rfc-2011-nicer-assert-messages
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> {
244
244
( & ast:: ExprKind :: Let { .. } , _) if !parser:: needs_par_as_let_scrutinee ( prec) => {
245
245
parser:: PREC_FORCE_PAREN
246
246
}
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 ,
247
251
_ => left_prec,
248
252
} ;
249
253
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() {
164
164
// mac call
165
165
166
166
// match
167
- [ match elem { _ => elem } == 3 ] => "Assertion failed: match elem { _ => elem, } == 3"
167
+ [ match elem { _ => elem } == 3 ] => "Assertion failed: ( match elem { _ => elem, }) == 3"
168
168
169
169
// ret
170
170
[ ( || { return elem; } ) ( ) == 3 ] => "Assertion failed: (|| { return elem; })() == 3"
You can’t perform that action at this time.
0 commit comments