rustfmt shifts macro body 4 indent levels to the right for no reason
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Version:
$ cargo fmt --version
rustfmt 1.6.0-nightly (1065d87 2023-07-09)
Config:
edition = "2021"
version = "Two"
max_width = 110
newline_style = "Unix"
use_small_heuristics = "Max"
tab_spaces = 2
imports_granularity = "Crate"
use_field_init_shorthand = true
use_try_shorthand = true
spaces_around_ranges = true
overflow_delimited_expr = true
I have this code:
macro dst_port($name:ident, $node:expr, $lock_dst_node:expr, $port_id:expr, $dst_node_id:expr) {
macro $name() {
// TODO: Assign to val instead of re-reading on every access, since it's not overwritten before all reads are done
$node.ports[$port_id]
}
}
after running rustfmt, it shifted the inner macro body 4 indent levels (4*2 spaces) to the right for no reason!:
macro dst_port($name:ident, $node:expr, $lock_dst_node:expr, $port_id:expr, $dst_node_id:expr) {
macro $name() {
// TODO: Assign to val instead of re-reading on every access, since it's not overwritten before all reads are done
$node.ports[$port_id]
}
}
Note: This doesn't happen when the comment is shorter like:
macro dst_port($name:ident, $node:expr, $lock_dst_node:expr, $port_id:expr, $dst_node_id:expr) {
macro $name() {
// TODO: Assign to val instead of re-reading on every access
$node.ports[$port_id]
}
}
It also doesn't happen when the original long comment is before the inner macro like:
macro dst_port($name:ident, $node:expr, $lock_dst_node:expr, $port_id:expr, $dst_node_id:expr) {
// TODO: Assign to val instead of re-reading on every access, since it's not overwritten before all reads are done
macro $name() {
$node.ports[$port_id]
}
}
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 difference with the supplied rustfmt version, configuration, and nested-macro input, then compare it with the shorter-comment cases. Trace the formatting path responsible for comments inside nested macros. Done means the long-comment example no longer gains four indentation levels and the related behavior is covered by a regression test.
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