Newlines between commented code in call chains get removed
Closed this issue · 2 comments
AeonSolstice commented
fn main() {
let el = EventLoop::builder()
.with_msg_hook(|msg| {
let msg = msg as *const MSG;
if unsafe { (*msg).message == WM_NCCALCSIZE && (*msg).wParam.0 == 1 } {
return true;
}
false
})
.build()
.unwrap();
}
Using vscode I comment out the following to test something quickly, and save
fn main() {
let el = EventLoop::builder()
// .with_msg_hook(|msg| {
// let msg = msg as *const MSG;
// if unsafe { (*msg).message == WM_NCCALCSIZE && (*msg).wParam.0 == 1 } {
// return true;
// }
// false
// })
.build()
.unwrap();
}
Rustfmt produces the following output
fn main() {
let el = EventLoop::builder()
// .with_msg_hook(|msg| {
// let msg = msg as *const MSG;
// if unsafe { (*msg).message == WM_NCCALCSIZE && (*msg).wParam.0 == 1 } {
// return true;
// }
// false
// })
.build()
.unwrap();
}
I finish testing.
The commented code is still highlighted and I need to Ctrl-Z 2 times and save again to get my original, clear, code.
I would expect 2+(incl.) newlines to get reduced to 1, but single ones should be kept.
Commented section does not necessarily need to be code.
$rustfmt --version
rustfmt 1.7.1-stable (f6e511e 2024-10-15)
ding-young commented
I think this is caused in the following part.
Line 450 in 777e25a
rustfmt intentionally trims the try operator and then removes the resulting blank line (the try operator is checked elsewhere and reattached later). However, it appears that it mistakenly removes the blank line even when there isn’t a try operator. —just my guess, though.
Lines 1015 to 1038 in 777e25a