Errantly formatting multiline macro
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
I have this macro call here that is formatted by rustfmt as so.
$ rustfmt --check godot-macros/src/class/data_models/field_export.rs
Diff in /home/fp/3rd/gdext/godot-macros/src/class/data_models/field_export.rs at line 402:
}?;
let deprecation_warning = if *radians {
quote! {
- #export_func;
- ::godot::__deprecated::emit_deprecated_warning!(export_range_radians);
- }
+ #export_func;
+ ::godot::__deprecated::emit_deprecated_warning!(export_range_radians);
+ }
} else {
quote! { #export_func }
};
$ rustfmt --version
rustfmt 1.7.0-stable (129f3b9 2024-06-10)
You can see here that rustfmt wants to un-indent the macro contents and double indent the end bracket for some reason.
Here's aa MCVE for this issue. The important details are that the innermost expressions are within a curly bracket-delimited macro, which itself is within 3 levels of scope.
// correct formatting
fn bar() {
{
{
foo! {
export_func;
warning;
}
}
}
}
// rustfmt output
fn bar() {
{
{
foo! {
export_func;
warning;
}
}
}
}
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 issue with the three-level nested MCVE and rustfmt 1.7.0, comparing the shown expected and actual formatting. Trace the macro-formatting path responsible for curly-bracket-delimited macros, then add a regression test demonstrating that the macro contents and closing brace retain the intended indentation.
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
- Clearly specified
- Newbie friendliness
- 48/100