Skip to content
Closed
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
10 changes: 9 additions & 1 deletion src/formatting/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,15 @@ pub(crate) fn recover_comment_removed(
let snippet = context.snippet(span);
let includes_comment = contains_comment(snippet);
if snippet != new && includes_comment && changed_comment_content(snippet, &new) {
Some(snippet.to_owned())
/* Trim white spaces at end of lines */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Trim white spaces at end of lines */
/* Trim whitespace at end of lines */

let mut c = String::from("");
for line in snippet.to_owned().split('\n') {
if c != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if c != "" {
if !c.is_empty() {

c.push('\n')
};
c.push_str(line.trim_end());
}
Some(c.to_owned())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c is already a String, is to_owned needed?

} else {
Some(new)
}
Expand Down
21 changes: 21 additions & 0 deletions tests/source/issue-2896.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,24 @@ fn main() {
}
}).unwrap();
}



/*******************************************************************************************
* Added test cases for related issues that are supposed to be solved by Pull request #4391
* ******************************************************************************************/

// ** Note the extra blank at the end of the 2nd line
fn main() {
if 0 == 1
/* x */ as i32 {} }

// ** Note the extra blank at the end of the 2nd line
fn main() {
if 0 == ' '
as i32 {} }

// ** Note the extra blank at the end of the 3rd line
fn main() {
if 0 == ' ' /* x */
as i32 {} }