Run rustfmt
diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs
index eac72e1..e094e8d 100644
--- a/clippy_lints/src/consts.rs
+++ b/clippy_lints/src/consts.rs
@@ -299,7 +299,7 @@
tcx: self.tcx,
tables: self.tcx.typeck_tables_of(def_id),
needed_resolution: false,
- substs,
+ substs: substs,
};
let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
self.tcx.mir_const_qualif(def_id);
diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs
index 57fdd3e..b2183ff 100644
--- a/clippy_lints/src/eq_op.rs
+++ b/clippy_lints/src/eq_op.rs
@@ -54,9 +54,9 @@
if let ExprBinary(ref op, ref left, ref right) = e.node {
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
span_lint(cx,
- EQ_OP,
- e.span,
- &format!("equal expressions as operands to `{}`", op.node.as_str()));
+ EQ_OP,
+ e.span,
+ &format!("equal expressions as operands to `{}`", op.node.as_str()));
return;
}
let (trait_id, requires_ref) = match op.node {
@@ -91,32 +91,30 @@
// either operator autorefs or both args are copyable
if (requires_ref || (lcpy && rcpy)) && implements_trait(cx, lty, trait_id, &[rty], None) {
span_lint_and_then(cx,
- OP_REF,
- e.span,
- "needlessly taken reference of both operands",
- |db| {
+ OP_REF,
+ e.span,
+ "needlessly taken reference of both operands",
+ |db| {
let lsnip = snippet(cx, l.span, "...").to_string();
let rsnip = snippet(cx, r.span, "...").to_string();
multispan_sugg(db,
- "use the values directly".to_string(),
- vec![(left.span, lsnip),
+ "use the values directly".to_string(),
+ vec![(left.span, lsnip),
(right.span, rsnip)]);
})
- } else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
- span_lint_and_then(cx,
- OP_REF,
- e.span,
- "needlessly taken reference of left operand",
- |db| {
+ } else if lcpy && !rcpy &&
+ implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
+ span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
let lsnip = snippet(cx, l.span, "...").to_string();
db.span_suggestion(left.span, "use the left value directly", lsnip);
})
- } else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
+ } else if !lcpy && rcpy &&
+ implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
span_lint_and_then(cx,
- OP_REF,
- e.span,
- "needlessly taken reference of right operand",
- |db| {
+ OP_REF,
+ e.span,
+ "needlessly taken reference of right operand",
+ |db| {
let rsnip = snippet(cx, r.span, "...").to_string();
db.span_suggestion(right.span, "use the right value directly", rsnip);
})
@@ -126,7 +124,8 @@
(&ExprAddrOf(_, ref l), _) => {
let lty = cx.tables.expr_ty(l);
let lcpy = is_copy(cx, lty, parent);
- if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
+ if (requires_ref || lcpy) &&
+ implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
let lsnip = snippet(cx, l.span, "...").to_string();
db.span_suggestion(left.span, "use the left value directly", lsnip);
@@ -137,7 +136,8 @@
(_, &ExprAddrOf(_, ref r)) => {
let rty = cx.tables.expr_ty(r);
let rcpy = is_copy(cx, rty, parent);
- if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
+ if (requires_ref || rcpy) &&
+ implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
let rsnip = snippet(cx, r.span, "...").to_string();
db.span_suggestion(right.span, "use the right value directly", rsnip);
diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs
index 222b912..148eb61 100644
--- a/clippy_lints/src/len_zero.rs
+++ b/clippy_lints/src/len_zero.rs
@@ -199,7 +199,8 @@
/// Check the inherent impl's items for an `is_empty(self)` method.
fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool {
- cx.tcx.inherent_impls(id)
+ cx.tcx
+ .inherent_impls(id)
.iter()
.any(|imp| cx.tcx.associated_items(*imp).any(|item| is_is_empty(cx, &item)))
}
diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs
index d524b08..076bf82 100644
--- a/clippy_lints/src/needless_continue.rs
+++ b/clippy_lints/src/needless_continue.rs
@@ -29,7 +29,7 @@
//! This lint is **warn** by default.
use rustc::lint::*;
use syntax::ast;
-use syntax::codemap::{original_sp,DUMMY_SP};
+use syntax::codemap::{original_sp, DUMMY_SP};
use std::borrow::Cow;
use utils::{in_macro, span_help_and_lint, snippet_block, snippet, trim_multiline};
@@ -163,7 +163,7 @@
* // region C
* }
* }
- */
+ * */
/// Given an expression, returns true if either of the following is true
///
@@ -181,10 +181,12 @@
fn is_first_block_stmt_continue(block: &ast::Block) -> bool {
block.stmts.get(0).map_or(false, |stmt| match stmt.node {
ast::StmtKind::Semi(ref e) |
- ast::StmtKind::Expr(ref e) => if let ast::ExprKind::Continue(_) = e.node {
- true
- } else {
- false
+ ast::StmtKind::Expr(ref e) => {
+ if let ast::ExprKind::Continue(_) = e.node {
+ true
+ } else {
+ false
+ }
},
_ => false,
})
@@ -192,12 +194,14 @@
/// If `expr` is a loop expression (while/while let/for/loop), calls `func` with
/// the AST object representing the loop block of `expr`.
-fn with_loop_block<F>(expr: &ast::Expr, mut func: F) where F: FnMut(&ast::Block) {
+fn with_loop_block<F>(expr: &ast::Expr, mut func: F)
+ where F: FnMut(&ast::Block)
+{
match expr.node {
- ast::ExprKind::While(_, ref loop_block, _) |
+ ast::ExprKind::While(_, ref loop_block, _) |
ast::ExprKind::WhileLet(_, _, ref loop_block, _) |
- ast::ExprKind::ForLoop( _, _, ref loop_block, _) |
- ast::ExprKind::Loop(ref loop_block, _) => func(loop_block),
+ ast::ExprKind::ForLoop(_, _, ref loop_block, _) |
+ ast::ExprKind::Loop(ref loop_block, _) => func(loop_block),
_ => {},
}
}
@@ -211,7 +215,8 @@
/// - The `else` expression.
///
fn with_if_expr<F>(stmt: &ast::Stmt, mut func: F)
- where F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr) {
+ where F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr)
+{
match stmt.node {
ast::StmtKind::Semi(ref e) |
ast::StmtKind::Expr(ref e) => {
@@ -219,7 +224,7 @@
func(e, cond, if_block, else_expr);
}
},
- _ => { },
+ _ => {},
}
}
@@ -249,45 +254,37 @@
const MSG_REDUNDANT_ELSE_BLOCK: &'static str = "This else block is redundant.\n";
-const MSG_ELSE_BLOCK_NOT_NEEDED: &'static str = "There is no need for an explicit `else` block for this `if` expression\n";
+const MSG_ELSE_BLOCK_NOT_NEEDED: &'static str = "There is no need for an explicit `else` block for this `if` \
+ expression\n";
-const DROP_ELSE_BLOCK_AND_MERGE_MSG: &'static str =
- "Consider dropping the else clause and merging the code that follows (in the loop) with the if block, like so:\n";
+const DROP_ELSE_BLOCK_AND_MERGE_MSG: &'static str = "Consider dropping the else clause and merging the code that \
+ follows (in the loop) with the if block, like so:\n";
-const DROP_ELSE_BLOCK_MSG: &'static str =
- "Consider dropping the else clause, and moving out the code in the else block, like so:\n";
+const DROP_ELSE_BLOCK_MSG: &'static str = "Consider dropping the else clause, and moving out the code in the else \
+ block, like so:\n";
-fn emit_warning<'a>(ctx: &EarlyContext,
- data: &'a LintData,
- header: &str,
- typ: LintType) {
+fn emit_warning<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str, typ: LintType) {
// snip is the whole *help* message that appears after the warning.
// message is the warning message.
// expr is the expression which the lint warning message refers to.
let (snip, message, expr) = match typ {
LintType::ContinueInsideElseBlock => {
- (suggestion_snippet_for_continue_inside_else(ctx, data, header),
- MSG_REDUNDANT_ELSE_BLOCK,
- data.else_expr)
+ (suggestion_snippet_for_continue_inside_else(ctx, data, header), MSG_REDUNDANT_ELSE_BLOCK, data.else_expr)
},
LintType::ContinueInsideThenBlock => {
- (suggestion_snippet_for_continue_inside_if(ctx, data, header),
- MSG_ELSE_BLOCK_NOT_NEEDED,
- data.if_expr)
- }
+ (suggestion_snippet_for_continue_inside_if(ctx, data, header), MSG_ELSE_BLOCK_NOT_NEEDED, data.if_expr)
+ },
};
span_help_and_lint(ctx, NEEDLESS_CONTINUE, expr.span, message, &snip);
}
-fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext,
- data: &'a LintData,
- header: &str) -> String {
+fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
let cond_code = snippet(ctx, data.if_cond.span, "..");
- let if_code = format!("if {} {{\n continue;\n}}\n", cond_code);
- /* ^^^^--- Four spaces of indentation. */
+ let if_code = format!("if {} {{\n continue;\n}}\n", cond_code);
+ /* ^^^^--- Four spaces of indentation. */
// region B
let else_code = snippet(ctx, data.else_expr.span, "..").into_owned();
let else_code = erode_block(&else_code);
@@ -300,12 +297,9 @@
ret
}
-fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext,
- data: &'a LintData,
- header: &str) -> String
-{
+fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
let cond_code = snippet(ctx, data.if_cond.span, "..");
- let mut if_code = format!("if {} {{\n", cond_code);
+ let mut if_code = format!("if {} {{\n", cond_code);
// Region B
let block_code = &snippet(ctx, data.if_block.span, "..").into_owned();
@@ -318,13 +312,12 @@
// These is the code in the loop block that follows the if/else construction
// we are complaining about. We want to pull all of this code into the
// `then` block of the `if` statement.
- let to_annex = data.block_stmts[data.stmt_idx+1..]
- .iter()
- .map(|stmt| {
- original_sp(stmt.span, DUMMY_SP)
- })
- .map(|span| snippet_block(ctx, span, "..").into_owned())
- .collect::<Vec<_>>().join("\n");
+ let to_annex = data.block_stmts[data.stmt_idx + 1..]
+ .iter()
+ .map(|stmt| original_sp(stmt.span, DUMMY_SP))
+ .map(|span| snippet_block(ctx, span, "..").into_owned())
+ .collect::<Vec<_>>()
+ .join("\n");
let mut ret = String::from(header);
@@ -336,24 +329,22 @@
}
fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
- with_loop_block(expr, |loop_block| {
- for (i, stmt) in loop_block.stmts.iter().enumerate() {
- with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
- let data = &LintData {
- stmt_idx: i,
- if_expr: if_expr,
- if_cond: cond,
- if_block: then_block,
- else_expr: else_expr,
- block_stmts: &loop_block.stmts,
- };
- if needless_continue_in_else(else_expr) {
- emit_warning(ctx, data, DROP_ELSE_BLOCK_AND_MERGE_MSG, LintType::ContinueInsideElseBlock);
- } else if is_first_block_stmt_continue(then_block) {
- emit_warning(ctx, data, DROP_ELSE_BLOCK_MSG, LintType::ContinueInsideThenBlock);
- }
- });
- }
+ with_loop_block(expr, |loop_block| for (i, stmt) in loop_block.stmts.iter().enumerate() {
+ with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
+ let data = &LintData {
+ stmt_idx: i,
+ if_expr: if_expr,
+ if_cond: cond,
+ if_block: then_block,
+ else_expr: else_expr,
+ block_stmts: &loop_block.stmts,
+ };
+ if needless_continue_in_else(else_expr) {
+ emit_warning(ctx, data, DROP_ELSE_BLOCK_AND_MERGE_MSG, LintType::ContinueInsideElseBlock);
+ } else if is_first_block_stmt_continue(then_block) {
+ emit_warning(ctx, data, DROP_ELSE_BLOCK_MSG, LintType::ContinueInsideThenBlock);
+ }
+ });
});
}
@@ -378,7 +369,7 @@
/// an empty string will be returned in that case.
pub fn erode_from_back(s: &str) -> String {
let mut ret = String::from(s);
- while ret.pop().map_or(false, |c| c != '}') { }
+ while ret.pop().map_or(false, |c| c != '}') {}
while let Some(c) = ret.pop() {
if !c.is_whitespace() {
ret.push(c);
@@ -409,10 +400,10 @@
///
pub fn erode_from_front(s: &str) -> String {
s.chars()
- .skip_while(|c| c.is_whitespace())
- .skip_while(|c| *c == '{')
- .skip_while(|c| *c == '\n')
- .collect::<String>()
+ .skip_while(|c| c.is_whitespace())
+ .skip_while(|c| *c == '{')
+ .skip_while(|c| *c == '\n')
+ .collect::<String>()
}
/// If `s` contains the code for a block, delimited by braces, this function
diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs
index 8d8dd18..f443ea1 100644
--- a/clippy_lints/src/needless_pass_by_value.rs
+++ b/clippy_lints/src/needless_pass_by_value.rs
@@ -284,16 +284,7 @@
}
}
- fn borrow(
- &mut self,
- _: NodeId,
- _: Span,
- _: mc::cmt<'tcx>,
- _: ty::Region,
- _: ty::BorrowKind,
- _: euv::LoanCause
- ) {
- }
+ fn borrow(&mut self, _: NodeId, _: Span, _: mc::cmt<'tcx>, _: ty::Region, _: ty::BorrowKind, _: euv::LoanCause) {}
fn mutate(&mut self, _: NodeId, _: Span, _: mc::cmt<'tcx>, _: euv::MutateMode) {}
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index 0f0d525..2c1043c 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -978,4 +978,3 @@
.infer_ctxt((), Reveal::All)
.enter(|infcx| ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes()))
}
-