Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST pretty-printer produces invalid syntax for postfix match #124206

Closed
dtolnay opened this issue Apr 20, 2024 · 0 comments · Fixed by #124269
Closed

AST pretty-printer produces invalid syntax for postfix match #124206

dtolnay opened this issue Apr 20, 2024 · 0 comments · Fixed by #124269
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-postfix_match `#![feature(postfix_match)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 20, 2024

// main.rs

#![feature(postfix_match)]

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

fn main() {
    repro!({ 1 } + 1);
}

As of current nightly, rustc -Zunpretty=expanded main.rs produces this:

#![feature(prelude_import)]
#![no_std]
// main.rs

#![feature(postfix_match)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;

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

fn main() { { 1 } + 1.match { _ => {} }; }

which is not valid Rust syntax.

error: leading `+` is not supported
  --> <anon>:13:19
   |
13 | fn main() { { 1 } + 1.match { _ => {} }; }
   |                   ^ unexpected `+`
   |
help: parentheses are required to parse this as an expression
   |
13 | fn main() { ({ 1 }) + 1.match { _ => {} }; }
   |             +     +

The correct output would contain ({ 1 } + 1).match { _ => {} }.

F-postfix_match `#![feature(postfix_match)]` tracking issue: #121618

@dtolnay dtolnay added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. F-postfix_match `#![feature(postfix_match)]` labels Apr 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 20, 2024
@dtolnay dtolnay added B-unstable Blocker: Implemented in the nightly compiler and unstable. requires-nightly This issue requires a nightly compiler in some way. A-pretty Area: Pretty printing (including `-Z unpretty`) and removed B-unstable Blocker: Implemented in the nightly compiler and unstable. labels Apr 20, 2024
@bors bors closed this as completed in f1c53da Apr 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 29, 2024
Rollup merge of rust-lang#124269 - scrabsha:sasha/fix-124206, r=dtolnay

Pretty-print parenthesis around binary in postfix match

Fixes rust-lang#124206.
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-postfix_match `#![feature(postfix_match)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants