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

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

Open
dtolnay opened this issue Apr 5, 2025 · 0 comments · May be fixed by #134847
Open

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

dtolnay opened this issue Apr 5, 2025 · 0 comments · May be fixed by #134847
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-coroutines `#![feature(coroutines)]` needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 5, 2025

#![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
@dtolnay dtolnay added the C-bug Category: This is a bug. label Apr 5, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 5, 2025
@dtolnay dtolnay linked a pull request Apr 5, 2025 that will close this issue
@dtolnay dtolnay added A-pretty Area: Pretty printing (including `-Z unpretty`) F-coroutines `#![feature(coroutines)]` labels Apr 5, 2025
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-coroutines `#![feature(coroutines)]` needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants