Skip to content

Commit

Permalink
Unrolled build for rust-lang#124269
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#124269 - scrabsha:sasha/fix-124206, r=dtolnay

Pretty-print parenthesis around binary in postfix match

Fixes rust-lang#124206.
  • Loading branch information
rust-timer authored Apr 29, 2024
2 parents e27af29 + c8ff8a4 commit e25491c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl<'a> State<'a> {
self.space();
}
MatchKind::Postfix => {
self.print_expr_as_cond(expr);
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
self.word_nbsp(".match");
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/pretty/postfix-match/precedence.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![feature(prelude_import)]
#![no_std]
#![feature(postfix_match)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;

use std::ops::Add;

//@ pretty-mode:expanded
//@ pp-exact:precedence.pp

macro_rules! repro { ($e:expr) => { $e.match { _ => {} } }; }

struct Struct {}

impl Add<Struct> for usize {
type Output = ();
fn add(self, _: Struct) -> () { () }
}
pub fn main() {
let a;
(
{ 1 } + 1).match {
_ => {}
};
(4 as usize).match { _ => {} };
(return).match { _ => {} };
(a = 42).match { _ => {} };
(|| {}).match { _ => {} };
(42..101).match { _ => {} };
(1 + Struct {}).match { _ => {} };
}
34 changes: 34 additions & 0 deletions tests/pretty/postfix-match/precedence.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![feature(postfix_match)]

use std::ops::Add;

//@ pretty-mode:expanded
//@ pp-exact:precedence.pp

macro_rules! repro {
($e:expr) => {
$e.match {
_ => {}
}
};
}

struct Struct {}

impl Add<Struct> for usize {
type Output = ();
fn add(self, _: Struct) -> () {
()
}
}
pub fn main() {
let a;

repro!({ 1 } + 1);
repro!(4 as usize);
repro!(return);
repro!(a = 42);
repro!(|| {});
repro!(42..101);
repro!(1 + Struct {});
}
File renamed without changes.

0 comments on commit e25491c

Please sign in to comment.