Skip to content

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

Closed

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

Activity

  1. 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
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 20, 2024
  3. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    A-prettyArea: Pretty printing (including `-Z unpretty`)
    and removed
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    on Apr 20, 2024
  4. added a commit that references this issue on Apr 29, 2024
    f1c53da
  5. added a commit that references this issue on Apr 29, 2024
    e25491c
  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    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. When possible, use a F-* label instead.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions