Skip to content

Commit 12ddaf9

Browse files
committed
Remove trim_newlines()
We call `trim_newlines()` after the `trim()`ed buffer, which is unnecessary.
1 parent 7c9686f commit 12ddaf9

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-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 {

0 commit comments

Comments
 (0)