``#[rustfmt::skip]`` is ignored in struct impl.
Open
Nobody has claimed this yet.
A-comments
A-rustfmt::skip
I-poor-formatting
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Describe the bug
Using #[rustfmt::skip] to prevent damage to comments doesn’t work if the comment is
inside a struct impl.
To Reproduce
#[rustfmt::skip]
/** Comment.
Rustfmt skips this as expected. */
fn main() {
for _ in 1..Foo::getRandomNumber() {
println!("Hello, world!");
}
}
struct Foo;
impl Foo {
#[rustfmt::skip]
/** Comment.
Rustfmt unindents this despite the ::skip above. */
#[allow(non_snake_case)]
pub fn getRandomNumber() -> i32 { 4 }
}
Expected behavior
The comment on getRandomNumber() should be left alone.
Meta
- rustfmt version: 1.4.20-stable
- From where did you install rustfmt?: from the Fedora 32 repos.
- How do you run rustfmt: doesn’t matter, both
cargo fmtandrustfmtshow the same defect.
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
No source files or tests are named. Start by running the provided reproducer with rustfmt and trace how #[rustfmt::skip] is handled on methods inside an impl. Done means the comment on getRandomNumber remains unchanged and a regression test covers the case.
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
- 48/100