Remove trim_newlines()
We call `trim_newlines()` after the `trim()`ed buffer, which is unnecessary.
This commit is contained in:
parent
7c9686f349
commit
12ddaf93e2
2 changed files with 3 additions and 14 deletions
|
|
@ -34,7 +34,7 @@ use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_co
|
|||
format_defaultness, format_mutability, format_unsafety, format_visibility,
|
||||
is_attributes_extendable, last_line_contains_single_line_comment,
|
||||
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
|
||||
stmt_expr, trim_newlines, trimmed_last_line_width};
|
||||
stmt_expr, trimmed_last_line_width};
|
||||
use vertical::rewrite_with_alignment;
|
||||
use visitor::FmtVisitor;
|
||||
|
||||
|
|
@ -674,7 +674,7 @@ pub fn format_impl(
|
|||
|
||||
result.push('\n');
|
||||
result.push_str(&inner_indent_str);
|
||||
result.push_str(trim_newlines(visitor.buffer.to_string().trim()));
|
||||
result.push_str(visitor.buffer.to_string().trim());
|
||||
result.push('\n');
|
||||
result.push_str(&outer_indent_str);
|
||||
}
|
||||
|
|
@ -1073,7 +1073,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
|
|||
|
||||
result.push('\n');
|
||||
result.push_str(&inner_indent_str);
|
||||
result.push_str(trim_newlines(visitor.buffer.to_string().trim()));
|
||||
result.push_str(visitor.buffer.to_string().trim());
|
||||
result.push('\n');
|
||||
result.push_str(&outer_indent_str);
|
||||
} else if result.contains('\n') {
|
||||
|
|
|
|||
11
src/utils.rs
11
src/utils.rs
|
|
@ -254,17 +254,6 @@ pub fn count_newlines(input: &str) -> usize {
|
|||
input.chars().filter(|&c| c == '\n').count()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn trim_newlines(input: &str) -> &str {
|
||||
match input.find(|c| c != '\n' && c != '\r') {
|
||||
Some(start) => {
|
||||
let end = input.rfind(|c| c != '\n' && c != '\r').unwrap_or(0) + 1;
|
||||
&input[start..end]
|
||||
}
|
||||
None => "",
|
||||
}
|
||||
}
|
||||
|
||||
// Macro for deriving implementations of Serialize/Deserialize for enums
|
||||
#[macro_export]
|
||||
macro_rules! impl_enum_serialize_and_deserialize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue