Skip to content

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

Closed
@dtolnay

Description

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

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

    No branches or pull requests

    Issue actions