Indentation in cfg inside a macro increases on each fmt
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Each time the following macro is formatted, the text inside the cfg becomes increasingly indented.
Reproducible playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e4c809502358b19465decfbac2d40a08
Happens at on all versions I've tried — both current nightly (rustfmt 1.4.38-nightly (29b12480 2021-10-25)) and stable, (rustfmt 1.4.37-stable (09c42c45 2021-10-18))
Details
Given the input:
macro_rules! check_runtime_prefix {
($runtime_feat:literal, $runtime_crate:literal) => {
#[cfg(all(
any(feature = $runtime_feat, feature = $runtime_crate),
not(all(feature = $runtime_feat, feature = $runtime_crate)),
))]
compile_error!(concat!(
"Please enable the `",
$runtime_feat,
"` feature rather than enabling `",
$runtime_crate,
"` directly",
));
};
}
After formatting, the rest of the macro is unchanged, but the cfg block becomes
macro_rules! check_runtime_prefix {
($runtime_feat:literal, $runtime_crate:literal) => {
#[cfg(all(
any(feature = $runtime_feat, feature = $runtime_crate),
not(all(feature = $runtime_feat, feature = $runtime_crate)),
))]
compile_error!(<snip>);
};
}
After formatting again, the cfg block becomes
macro_rules! check_runtime_prefix {
($runtime_feat:literal, $runtime_crate:literal) => {
#[cfg(all(
any(feature = $runtime_feat, feature = $runtime_crate),
not(all(feature = $runtime_feat, feature = $runtime_crate)),
))]
compile_error!(<snip>);
};
}
Etc.
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
Start with the linked Rust Playground example and run rustfmt repeatedly on the provided macro. Compare the cfg block after each run and use the reproducer to define done: formatting should produce stable indentation instead of increasing it on every pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100