Skip to content

Postfix yield is pretty-printed with too many parentheses #139395

@dtolnay

Description

@dtolnay
#![feature(coroutines, gen_blocks)]

fn main() {
    let _ = gen { {}.yield.yield };
}

The output from rustc --edition=2024 -Zunpretty=expanded main.rs is:

#![feature(prelude_import)]
#![feature(coroutines, gen_blocks)]
#[prelude_import]
use std::prelude::rust_2024::*;
#[macro_use]
extern crate std;

fn main() { let _ = gen { ({}.yield).yield }; }

The correct output would have {}.yield.yield instead of ({}.yield).yield. The pretty-printer is inserting parentheses that do not need to be there, as if the inner yield were prefix yield: (yield {}).yield.

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (00095b3da 2025-04-03)
binary: rustc
commit-hash: 00095b3da4f23d9b3e7a809ac6a4e2b2530df84c
commit-date: 2025-04-03
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions