Skip to content

Commit 0f24bc0

Browse files
authored
Merge pull request #2330 from topecongiro/issue-2329
Issue 2329
2 parents d3c2523 + 12ddaf9 commit 0f24bc0

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_co
3434
format_defaultness, format_mutability, format_unsafety, format_visibility,
3535
is_attributes_extendable, last_line_contains_single_line_comment,
3636
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
37-
stmt_expr, trim_newlines, trimmed_last_line_width};
37+
stmt_expr, trimmed_last_line_width};
3838
use vertical::rewrite_with_alignment;
3939
use visitor::FmtVisitor;
4040

@@ -674,7 +674,7 @@ pub fn format_impl(
674674

675675
result.push('\n');
676676
result.push_str(&inner_indent_str);
677-
result.push_str(trim_newlines(visitor.buffer.to_string().trim()));
677+
result.push_str(visitor.buffer.to_string().trim());
678678
result.push('\n');
679679
result.push_str(&outer_indent_str);
680680
}
@@ -1073,7 +1073,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
10731073

10741074
result.push('\n');
10751075
result.push_str(&inner_indent_str);
1076-
result.push_str(trim_newlines(visitor.buffer.to_string().trim()));
1076+
result.push_str(visitor.buffer.to_string().trim());
10771077
result.push('\n');
10781078
result.push_str(&outer_indent_str);
10791079
} else if result.contains('\n') {

src/utils.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,6 @@ pub fn count_newlines(input: &str) -> usize {
254254
input.chars().filter(|&c| c == '\n').count()
255255
}
256256

257-
#[inline]
258-
pub fn trim_newlines(input: &str) -> &str {
259-
match input.find(|c| c != '\n' && c != '\r') {
260-
Some(start) => {
261-
let end = input.rfind(|c| c != '\n' && c != '\r').unwrap_or(0) + 1;
262-
&input[start..end]
263-
}
264-
None => "",
265-
}
266-
}
267-
268257
// Macro for deriving implementations of Serialize/Deserialize for enums
269258
#[macro_export]
270259
macro_rules! impl_enum_serialize_and_deserialize {

tests/target/issue-2329.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Comments with characters which must be represented by multibyte.
2+
3+
// フー
4+
use foo;
5+
// バー
6+
use bar;
7+
8+
impl MyStruct {
9+
// コメント
10+
fn f1() {} // こんにちは
11+
fn f2() {} // ありがとう
12+
// コメント
13+
}
14+
15+
trait MyTrait {
16+
// コメント
17+
fn f1() {} // こんにちは
18+
fn f2() {} // ありがとう
19+
// コメント
20+
}
21+
22+
fn main() {
23+
// コメント
24+
let x = 1; // X
25+
println!(
26+
"x = {}", // xの値
27+
x, // X
28+
);
29+
// コメント
30+
}

0 commit comments

Comments
 (0)