Skip to content

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

Closed
@dtolnay

Description

@dtolnay
Member
// 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

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Apr 20, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Apr 20, 2024
added
B-unstableBlocker: Implemented in the nightly compiler and unstable.
requires-nightlyThis issue requires a nightly compiler in some way.
A-prettyArea: Pretty printing (including `-Z unpretty`)
and removed
B-unstableBlocker: Implemented in the nightly compiler and unstable.
on Apr 20, 2024
added a commit that references this issue on Apr 29, 2024

Rollup merge of rust-lang#124269 - scrabsha:sasha/fix-124206, r=dtolnay

f1c53da
added a commit that references this issue on Apr 29, 2024
e25491c
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-prettyArea: Pretty printing (including `-Z unpretty`)C-bugCategory: This is a bug.F-postfix_match`#![feature(postfix_match)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @dtolnay@saethlin@rustbot

      Issue actions

        AST pretty-printer produces invalid syntax for postfix match · Issue #124206 · rust-lang/rust