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

Pretty print empty blocks as {} #91437

Merged
merged 1 commit into from
Dec 5, 2021
Merged

Pretty print empty blocks as {} #91437

merged 1 commit into from
Dec 5, 2021

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 1, 2021

Example:

macro_rules! p {
    ($e:expr) => {
        println!("{}", stringify!($e));
    };
    ($i:item) => {
        println!("{}", stringify!($i));
    };
}

fn main() {
    p!(if true {});
    p!(struct S {});
}

Before:

if true { }
struct S {
}

After:

if true {}
struct S {}

This affects dbg!, as well as ecosystem uses of stringify such as in anyhow::ensure!. Printing a { } in today's heavily rustfmt'd world comes out looking jarring/sloppy.

@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 1, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 1, 2021
@nagisa
Copy link
Member

nagisa commented Dec 5, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Dec 5, 2021

📌 Commit b516a8c has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2021
…askrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#90529 (Skip reborrows in AbstractConstBuilder)
 - rust-lang#91437 (Pretty print empty blocks as {})
 - rust-lang#91450 (Don't suggest types whose inner type is erroneous)
 - rust-lang#91535 (Stabilize `-Z emit-future-incompat` as `--json future-incompat`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a8f8f74 into rust-lang:master Dec 5, 2021
@bors
Copy link
Contributor

bors commented Dec 5, 2021

⌛ Testing commit b516a8c with merge 772d51f...

@rustbot rustbot added this to the 1.59.0 milestone Dec 5, 2021
@dtolnay dtolnay deleted the emptybrace branch December 5, 2021 18:37
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 28, 2021
…acrum

Add a test suite for stringify macro

This attempts to cover the behavior of `stringify!` on various interpolated syntax tree nodes.

The pretty printer has a history of unsightly whitespace (double spaces, missing spaces, spaces where there shouldn't be spaces) — rust-lang#91437, rust-lang#91562, rust-lang#91568. There are several such issues left; the test cases that I consider to be currently behaving incorrectly are marked with `// FIXME` in the PR.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 28, 2021
…acrum

Add a test suite for stringify macro

This attempts to cover the behavior of `stringify!` on various interpolated syntax tree nodes.

The pretty printer has a history of unsightly whitespace (double spaces, missing spaces, spaces where there shouldn't be spaces) — rust-lang#91437, rust-lang#91562, rust-lang#91568. There are several such issues left; the test cases that I consider to be currently behaving incorrectly are marked with `// FIXME` in the PR.
@dtolnay dtolnay added the A-pretty Area: Pretty printing (including `-Z unpretty`) label Dec 28, 2023
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`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants