From 2b11d84119d78d92af8bcbd2688770c9d530c830 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Wed, 25 Nov 2015 15:39:15 +0900 Subject: [PATCH] Apply Clippy --- src/chains.rs | 2 +- src/expr.rs | 2 +- src/items.rs | 8 ++++---- src/lib.rs | 4 ++-- src/lists.rs | 2 +- src/missed_spans.rs | 7 ++++--- src/visitor.rs | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index 9e85b22da02..952c7f1e08e 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -168,7 +168,7 @@ fn is_block_expr(expr: &ast::Expr, repr: &str) -> bool { } } -fn pop_expr_chain<'a>(expr: &'a ast::Expr) -> Option<&'a ast::Expr> { +fn pop_expr_chain(expr: &ast::Expr) -> Option<&ast::Expr> { match expr.node { ast::Expr_::ExprMethodCall(_, _, ref expressions) => Some(&expressions[0]), ast::Expr_::ExprTupField(ref subexpr, _) | diff --git a/src/expr.rs b/src/expr.rs index 6a34257eca3..040c83488a7 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1008,7 +1008,7 @@ fn rewrite_guard(context: &RewriteContext, // the arm (excludes offset). pattern_width: usize) -> Option { - if let &Some(ref guard) = guard { + if let Some(ref guard) = *guard { // First try to fit the guard string on the same line as the pattern. // 4 = ` if `, 5 = ` => {` let overhead = pattern_width + 4 + 5; diff --git a/src/items.rs b/src/items.rs index 6ca82721689..01847f80d38 100644 --- a/src/items.rs +++ b/src/items.rs @@ -465,7 +465,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - if polarity == ast::ImplPolarity::Negative { result.push_str("!"); } - if let &Some(ref trait_ref) = trait_ref { + if let Some(ref trait_ref) = *trait_ref { let budget = try_opt!(context.config.max_width.checked_sub(result.len())); let indent = offset + result.len(); result.push_str(&*try_opt!(trait_ref.rewrite(context, budget, indent))); @@ -496,7 +496,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - BraceStyle::AlwaysNextLine => result.push('\n'), BraceStyle::PreferSameLine => result.push(' '), BraceStyle::SameLineWhere => { - if where_clause_str.len() > 0 { + if !where_clause_str.is_empty() { result.push('\n') } else { result.push(' ') @@ -720,7 +720,7 @@ fn format_tuple_struct(context: &RewriteContext, result.push_str(&body); result.push(')'); - if where_clause_str.len() > 0 && !where_clause_str.contains('\n') && + if !where_clause_str.is_empty() && !where_clause_str.contains('\n') && (result.contains('\n') || context.block_indent.width() + result.len() + where_clause_str.len() + 1 > context.config.max_width) { @@ -1052,7 +1052,7 @@ fn rewrite_fn_base(context: &RewriteContext, let indent = match context.config.fn_return_indent { ReturnIndent::WithWhereClause => indent + 4, // Aligning with non-existent args looks silly. - _ if arg_str.len() == 0 => { + _ if arg_str.is_empty() => { force_new_line_for_brace = true; indent + 4 } diff --git a/src/lib.rs b/src/lib.rs index dd065a9939c..ad3e3b27e2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -410,7 +410,7 @@ pub fn format_string(input: String, config: &Config, mode: WriteMode) -> FileMap visitor.buffer.push_str("\n"); file_map.insert(path.to_owned(), visitor.buffer); - return file_map; + file_map } pub fn format(file: &Path, config: &Config, mode: WriteMode) -> FileMap { @@ -427,7 +427,7 @@ pub fn format(file: &Path, config: &Config, mode: WriteMode) -> FileMap { // newlines so we must add one on for each file. This is sad. filemap::append_newlines(&mut file_map); - return file_map; + file_map } // args are the arguments passed on the command line, generally passed through diff --git a/src/lists.rs b/src/lists.rs index 5bd2845c0e5..4dd2e5d1dce 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -191,7 +191,7 @@ pub fn definitive_tactic<'t, I, T>(items: I, // Format a list of commented items into a string. // TODO: add unit tests -pub fn write_list<'b, I, T>(items: I, formatting: &ListFormatting<'b>) -> Option +pub fn write_list(items: I, formatting: &ListFormatting) -> Option where I: IntoIterator, T: AsRef { diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 0da0f3ebb33..c123a9bc81b 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -94,9 +94,10 @@ impl<'a> FmtVisitor<'a> { fn replace_chars(string: &str) -> String { string.chars() .map(|ch| { - match ch.is_whitespace() { - true => ch, - false => 'X', + if ch.is_whitespace() { + ch + } else { + 'X' } }) .collect() diff --git a/src/visitor.rs b/src/visitor.rs index 7d50a6da61b..98a706adc41 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -415,7 +415,7 @@ impl<'a> FmtVisitor<'a> { let outers: Vec<_> = attrs.iter() .filter(|a| a.node.style == ast::AttrStyle::Outer) - .map(|a| a.clone()) + .cloned() .collect(); if outers.is_empty() { return false;