close
Skip to content

fix: Improve prettify_macro_expansion()#22058

Open
A4-Tacks wants to merge 3 commits intorust-lang:masterfrom
A4-Tacks:pretty-macro-tokens
Open

fix: Improve prettify_macro_expansion()#22058
A4-Tacks wants to merge 3 commits intorust-lang:masterfrom
A4-Tacks:pretty-macro-tokens

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

  • Add basic tests for prettify_macro_expansion

Example

const _: () = {
    loop {break}
    foo()
};

Before this PR

const _:() = {
    loop{
        break
    }foo()
};

After this PR

const _: () = {
    loop {
        break
    }
    foo()
};

const _: () = {
    match 2 {
        tmp => foo!(),
    };
};

Before this PR

const _:() = {
    match 2 {
        tmp => foo!(),

        };
};

After this PR

const _: () = {
    match 2 {
        tmp => foo!(),
    };
};

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 16, 2026
@A4-Tacks A4-Tacks force-pushed the pretty-macro-tokens branch from 4284af4 to 0720578 Compare April 16, 2026 05:02
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@A4-Tacks A4-Tacks force-pushed the pretty-macro-tokens branch from 0720578 to e3cb51a Compare April 16, 2026 05:13
- Add basic tests for prettify_macro_expansion

Example
---
```rust
const _: () = {
    loop {break}
    foo()
};
```

**Before this PR**

```rust
const _:() = {
    loop{
        break
    }foo()
};
```

**After this PR**

```rust
const _: () = {
    loop {
        break
    }
    foo()
};
```

---

```rust
const _: () = {
    match 2 {
        tmp => foo!(),
    };
};
```

**Before this PR**

```rust
const _:() = {
    match 2 {
        tmp => foo!(),

        };
};
```

**After this PR**

```rust
const _: () = {
    match 2 {
        tmp => foo!(),
    };
};
```
@A4-Tacks A4-Tacks force-pushed the pretty-macro-tokens branch from e3cb51a to 398a9f8 Compare April 16, 2026 05:27
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Is there a real reason to improve this function? Where important, we pass its output to rustfmt. We only need it so that tokens won't be combined.

@A4-Tacks
Copy link
Copy Markdown
Member Author

Is there a real reason to improve this function?

Yes, when I use inline_macro, the old output often looks terrible

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Then we just should pass it to rustfmt there too.

@A4-Tacks
Copy link
Copy Markdown
Member Author

No, most of the time I use inline_macro to debug macros,
and rustfmt has poor support for formatting nested macros
And when developing macros, the expanded result may not be syntax correct, while rustfmt can only handle correct syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants