Address clippy lints

This commit is contained in:
Oliver Schneider 2017-11-30 09:22:00 +01:00
parent b8106eb2aa
commit 9667cc2484
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9
7 changed files with 18 additions and 21 deletions

View File

@ -165,7 +165,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
let all_in_one_line = !parent_rewrite_contains_newline
&& rewrites.iter().all(|s| !s.contains('\n'))
&& almost_total < one_line_budget;
let last_shape = if rewrites.len() == 0 {
let last_shape = if rewrites.is_empty() {
first_child_shape
} else {
other_child_shape

View File

@ -1424,7 +1424,7 @@ fn rewrite_match_arm(
/// - `&[small]`
fn is_short_pattern(pat: &ast::Pat, pat_str: &str) -> bool {
// We also require that the pattern is reasonably 'small' with its literal width.
pat_str.len() <= 20 && !pat_str.contains("\n") && is_short_pattern_inner(pat)
pat_str.len() <= 20 && !pat_str.contains('\n') && is_short_pattern_inner(pat)
}
fn is_short_pattern_inner(pat: &ast::Pat) -> bool {

View File

@ -30,7 +30,7 @@ pub fn append_newline(s: &mut StringBuffer) {
s.push_str("\n");
}
pub fn write_all_files<T>(file_map: &FileMap, out: &mut T, config: &Config) -> Result<(), io::Error>
pub fn write_all_files<T>(file_map: &[FileRecord], out: &mut T, config: &Config) -> Result<(), io::Error>
where
T: Write,
{

View File

@ -16,8 +16,8 @@ use std::fmt;
pub use config::ReportTactic;
const TO_DO_CHARS: &'static [char] = &['T', 'O', 'D', 'O'];
const FIX_ME_CHARS: &'static [char] = &['F', 'I', 'X', 'M', 'E'];
const TO_DO_CHARS: &[char] = &['T', 'O', 'D', 'O'];
const FIX_ME_CHARS: &[char] = &['F', 'I', 'X', 'M', 'E'];
// Enabled implementation detail is here because it is
// irrelevant outside the issues module

View File

@ -500,8 +500,8 @@ impl<'a> FmtVisitor<'a> {
let mut items: Vec<_> =
itemize_list_with(self.config.width_heuristics().struct_variant_width);
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains("\n"));
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains("\n"));
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains('\n'));
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains('\n'));
if has_multiline_variant && has_single_line_variant {
items = itemize_list_with(0);
}
@ -1308,7 +1308,7 @@ fn format_tuple_struct(
result.push(')');
} else {
let shape = Shape::indented(offset, context.config).sub_width(1)?;
let fields = &fields.iter().map(|field| field).collect::<Vec<_>>()[..];
let fields = &fields.iter().collect::<Vec<_>>()[..];
let one_line_width = context.config.width_heuristics().fn_call_width;
result = rewrite_call_inner(context, &result, fields, span, shape, one_line_width, false)?;
}
@ -1593,7 +1593,7 @@ pub fn rewrite_associated_type(
) -> Option<String> {
let prefix = format!("type {}", ident);
let type_bounds_str = if let Some(ref bounds) = ty_param_bounds_opt {
let type_bounds_str = if let Some(bounds) = ty_param_bounds_opt {
// 2 = ": ".len()
let shape = Shape::indented(indent, context.config).offset_left(prefix.len() + 2)?;
let bound_str = bounds
@ -2459,10 +2459,9 @@ pub fn wrap_generics_with_angle_brackets(
fn rewrite_trait_bounds(
context: &RewriteContext,
type_param_bounds: &ast::TyParamBounds,
bounds: &[ast::TyParamBound],
shape: Shape,
) -> Option<String> {
let bounds: &[_] = type_param_bounds;
if bounds.is_empty() {
return Some(String::new());

View File

@ -437,7 +437,7 @@ where
let mut formatted_comment = rewrite_post_comment(&mut item_max_width)?;
if !starts_with_newline(&comment) {
if !starts_with_newline(comment) {
let mut comment_alignment =
post_comment_alignment(item_max_width, inner_item.len());
if first_line_width(&formatted_comment) + last_line_width(&result)
@ -457,7 +457,7 @@ where
}
} else {
result.push('\n');
result.push_str(&indent_str);
result.push_str(indent_str);
}
if formatted_comment.contains('\n') {
item_max_width = None;
@ -594,7 +594,7 @@ where
let mut block_open_index = post_snippet.find("/*");
// check if it really is a block comment (and not `//*` or a nested comment)
if let Some(i) = block_open_index {
match post_snippet.find("/") {
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,
_ => (),
@ -620,15 +620,13 @@ where
(_, Some(j)) if j > separator_index => j + 1,
_ => post_snippet.len(),
}
} else {
} else if let Some(newline_index) = newline_index {
// Match arms may not have trailing comma. In any case, for match arms,
// we will assume that the post comment belongs to the next arm if they
// do not end with trailing comma.
if let Some(newline_index) = newline_index {
newline_index + 1
} else {
0
}
newline_index + 1
} else {
0
}
}
None => post_snippet

View File

@ -380,7 +380,7 @@ where
FunctionRetTy::Default(..) => String::new(),
};
let extendable = (!list_str.contains('\n') || list_str.is_empty()) && !output.contains("\n");
let extendable = (!list_str.contains('\n') || list_str.is_empty()) && !output.contains('\n');
let args = wrap_args_with_parens(
context,
&list_str,