Failure when a single line comment is placed between an attribute and a struct field
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Notice the mixed tabs and spaces, mixed brace styling, internal error message.
Input:
pub fn create_thing() -> Thing
{
Thing
{
#[attribute]
//this comment's presence breaks rustfmt
field: 1,
}
}
Output (rustfmt fmt_bug.rs):
error[internal]: left behind trailing whitespace
--> fmt_bug.rs:6:6:1
|
6 |
|
|
warning: rustfmt has failed to format. See previous 1 errors.
pub fn create_thing() -> Thing {
Thing
{
#[attribute]
//this comment's presence breaks rustfmt
field: 1,
}
}
Expected:
pub fn create_thing() -> Thing {
Thing {
#[attribute]
//this comment's presence breaks rustfmt
field: 1,
}
}
Removing the empty line with whitespace fixes the error message, but the output is still malformed in the same way:
Input:
pub fn create_thing() -> Thing
{
Thing
{
#[attribute]
//this comment's presence breaks rustfmt
field: 1,
}
}
Output:
pub fn create_thing() -> Thing {
Thing
{
#[attribute]
//this comment's presence breaks rustfmt
field: 1,
}
}
With the comment removed, braces are correctly relocated and the empty line is collapsed.
Input:
pub fn create_thing() -> Thing
{
Thing
{
#[attribute]
field: 1,
}
}
Output:
pub fn create_thing() -> Thing {
Thing {
#[attribute]
field: 1,
}
}
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 repository file or test is named; begin by running rustfmt on the supplied reproducer and comparing the comment, attribute, brace, and whitespace cases. Trace the formatter path handling a single-line comment between an attribute and struct field, and consider the issue resolved when the expected formatting is produced without an internal error.
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