Semicolon-containing non-{} macro invocations inside a macro_rules! are indented incorrectly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Not entirely sure on the exact rules for when this happens. So far I've worked out that, at least for the test code below on the tested version of rustfmt (1.5.1-nightly 2022-08-01 fe33428):
- It doesn't happen if the invocation is
foo!{42;}(rustfmt emits expected indentation;foo![42;]shows the same behaviour asfoo!(42;)) - It doesn't happen if any of the
consts arelets instead (rustfmt doesn't format the surrounding macro at all) - It doesn't happen if the semicolon in the invocation is removed (rustfmt emits expected indentation)
Test code; this code is formatted exactly how rustfmt 1.5.1-nightly (2022-08-01 fe33428) formatted it in the playground:
macro_rules! foo {
($x:literal;) => {
$x
};
}
const TOP_PLAIN: usize = foo!(42;);
macro_rules! topmacro {
() => {
// <- expected indent level
const TOP_MACRO1: usize = foo!(42;);
};
() => {{
// <- expected indent level
const TOP_MACRO2: usize = foo!(42;);
}};
}
fn main() {
if true {
if true {
const NESTED_PLAIN: usize = foo!(42;);
macro_rules! nestedmacro {
() => {
// <- expected indent level
const NESTED_MACRO1: usize = foo!(42;);
};
() => {{
// <- expected indent level
const NESTED_MACRO2: usize = foo!(42;);
}};
}
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the formatting output from the supplied Rust macro_rules! example with the noted rustfmt version, focusing on semicolon-containing non-{} invocations and the affected indentation. Trace the formatter path for macro bodies and compare the output with the marked expected indentation. Done means the example is formatted correctly and a regression test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100