rustfmt
rustfmt copied to clipboard
version Two no longer able to format code
fn f() {}
fn main() {
f(0, 1,); // f()
//~^ error: this function takes 0 arguments but 2 arguments were supplied
}
with version = "Two"
it looks like rustfmt does no longer know that the comment on line 5 exists, it thus flags " " as
error[internal]: left behind trailing whitespace
--> /tmp/im/a.rs:5:5:1
|
5 |
| ^^^^
|
which it isnt because there is a comment after the indentation (unless it tries to remove the entire comment which is spooky as well)
rustfmt 1.7.0-nightly (d2d24e3 2024-05-03)
@ytmimi I want to highlight this one for discussion and review as I wonder if this may be related to the v2/2024 behavior that avoids trailing comment alignment and I want to ensure we don't have any known bugs there.
It appears to me as if rustfmt is, for whatever reason, attempting to capture the white space between the semi and the trailing comment and just dumping that whitespace on a newline. If this is some odd edge case then that's a bit better, but hopefully not a source of concern for the 2024 style edition
When I run cargo run --bin rustfmt on the latest commit d5f1200ed6a8e375f963e0c59a8bee45c0018c55 this is what I get.
Input:
fn main() {
f(0, 1,); // f()
//~^ error: this function takes 0 arguments but 2 arguments were supplied
}
Output:
fn main() {
f(0, 1); // f()
//~^ error: this function takes 0 arguments but 2 arguments were supplied
}
A little odd to me that we're adding an indented newline between the comments.
@calebcartwright I think this might have more to do with how we handle CommentStyle::Custom comments. The following input isn't formatted strangely.
input
fn main() {
f(0, 1,); // f()
// ~^ error: this function takes 0 arguments but 2 arguments were supplied
}
output
fn main() {
f(0, 1); // f()
// ~^ error: this function takes 0 arguments but 2 arguments were supplied
}
@calebcartwright @matthiaskrgr looking through the issue tracker this seems like a duplicate of #5391 and #5868
i don't know if my issue is related, but i've been getting this with one of my projects, here's the relevant code snippet:
if let GradientType::Custom = state.options.gradient_type {
let to_remove: Vec<_> = state.options.gradient_colors.iter_mut().enumerate().filter_map(|(i, color)| ui.horizontal(|ui| {
let changed = ui.color_edit_button_srgb(color).changed();
if ui.button("Delete").clicked() {
options_edited = true;
Some(i)
} else {
options_edited |= changed;
None
}
}).inner).collect();
// <- this line has whitespace that rustfmt chokes on
for i in to_remove {
state.options.gradient_colors.remove(i);
}