Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/formatting/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,18 @@ fn trim_tries(s: &str) -> String {
for (kind, rich_char) in CharClasses::new(s.chars()) {
match rich_char.get_char() {
'\n' => {
if result.is_empty() || !line_buffer.trim().is_empty() {
result.push_str(&line_buffer);
result.push('\n')
let last_new_line = result.rfind('\n').unwrap_or(0);
match result[..last_new_line].rfind('\n') {
// Remove the current line if it's blank and follows a line-style comment
Some(second_last_newline)
if result[second_last_newline + 1..]
.trim_start()
.starts_with("//")
&& line_buffer.trim().is_empty() => {}
_ => {
result.push_str(&line_buffer);
result.push('\n');
}
}
line_buffer.clear();
}
Expand Down
11 changes: 11 additions & 0 deletions tests/source/chains_with_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,14 @@ fn foo() {
? ? ?
.baz;
}

// #4012
pub fn foo2() {
let a = chain
.get()
/*


*/
.set();
}
11 changes: 11 additions & 0 deletions tests/target/chains_with_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,14 @@ fn foo() {
// comment
.baz;
}

// #4012
pub fn foo2() {
let a = chain
.get()
/*


*/
.set();
}