diff --git a/src/lists.rs b/src/lists.rs index 14b799622c9..c75206b5ce6 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -651,7 +651,7 @@ pub fn get_comment_end( if let Some(i) = block_open_index { match post_snippet.find('/') { Some(j) if j < i => block_open_index = None, - _ if i > 0 && &post_snippet[i - 1..i] == "/" => block_open_index = None, + _ if post_snippet[..i].chars().last() == Some('/') => block_open_index = None, _ => (), } } @@ -692,8 +692,13 @@ pub fn has_extra_newline(post_snippet: &str, comment_end: usize) -> bool { return false; } + let len_last = post_snippet[..comment_end] + .chars() + .last() + .unwrap() + .len_utf8(); // Everything from the separator to the next item. - let test_snippet = &post_snippet[comment_end - 1..]; + let test_snippet = &post_snippet[comment_end - len_last..]; let first_newline = test_snippet .find('\n') .unwrap_or_else(|| test_snippet.len()); diff --git a/tests/source/issue-2995.rs b/tests/source/issue-2995.rs new file mode 100644 index 00000000000..accf7c3a1ad --- /dev/null +++ b/tests/source/issue-2995.rs @@ -0,0 +1,7 @@ +fn issue_2995() { + // '\u{2028}' is inserted in the code below. + + [0, 
1]; + [0, 
/* */ 1]; + 
[
0
,
1
]
; +} diff --git a/tests/target/issue-2995.rs b/tests/target/issue-2995.rs new file mode 100644 index 00000000000..890da8def92 --- /dev/null +++ b/tests/target/issue-2995.rs @@ -0,0 +1,7 @@ +fn issue_2995() { + // '\u{2028}' is inserted in the code below. + + [0, 1]; + [0, /* */ 1]; + [0, 1]; +}