Skip to content

Commit 1522a49

Browse files
committed
Run rustfmt
1 parent 5295fe4 commit 1522a49

File tree

6 files changed

+85
-103
lines changed

6 files changed

+85
-103
lines changed

clippy_lints/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
299299
tcx: self.tcx,
300300
tables: self.tcx.typeck_tables_of(def_id),
301301
needed_resolution: false,
302-
substs,
302+
substs: substs,
303303
};
304304
let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
305305
self.tcx.mir_const_qualif(def_id);

clippy_lints/src/eq_op.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
5454
if let ExprBinary(ref op, ref left, ref right) = e.node {
5555
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
5656
span_lint(cx,
57-
EQ_OP,
58-
e.span,
59-
&format!("equal expressions as operands to `{}`", op.node.as_str()));
57+
EQ_OP,
58+
e.span,
59+
&format!("equal expressions as operands to `{}`", op.node.as_str()));
6060
return;
6161
}
6262
let (trait_id, requires_ref) = match op.node {
@@ -91,32 +91,30 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
9191
// either operator autorefs or both args are copyable
9292
if (requires_ref || (lcpy && rcpy)) && implements_trait(cx, lty, trait_id, &[rty], None) {
9393
span_lint_and_then(cx,
94-
OP_REF,
95-
e.span,
96-
"needlessly taken reference of both operands",
97-
|db| {
94+
OP_REF,
95+
e.span,
96+
"needlessly taken reference of both operands",
97+
|db| {
9898
let lsnip = snippet(cx, l.span, "...").to_string();
9999
let rsnip = snippet(cx, r.span, "...").to_string();
100100
multispan_sugg(db,
101-
"use the values directly".to_string(),
102-
vec![(left.span, lsnip),
101+
"use the values directly".to_string(),
102+
vec![(left.span, lsnip),
103103
(right.span, rsnip)]);
104104
})
105-
} else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
106-
span_lint_and_then(cx,
107-
OP_REF,
108-
e.span,
109-
"needlessly taken reference of left operand",
110-
|db| {
105+
} else if lcpy && !rcpy &&
106+
implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
107+
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
111108
let lsnip = snippet(cx, l.span, "...").to_string();
112109
db.span_suggestion(left.span, "use the left value directly", lsnip);
113110
})
114-
} else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
111+
} else if !lcpy && rcpy &&
112+
implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
115113
span_lint_and_then(cx,
116-
OP_REF,
117-
e.span,
118-
"needlessly taken reference of right operand",
119-
|db| {
114+
OP_REF,
115+
e.span,
116+
"needlessly taken reference of right operand",
117+
|db| {
120118
let rsnip = snippet(cx, r.span, "...").to_string();
121119
db.span_suggestion(right.span, "use the right value directly", rsnip);
122120
})
@@ -126,7 +124,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
126124
(&ExprAddrOf(_, ref l), _) => {
127125
let lty = cx.tables.expr_ty(l);
128126
let lcpy = is_copy(cx, lty, parent);
129-
if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
127+
if (requires_ref || lcpy) &&
128+
implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)], None) {
130129
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
131130
let lsnip = snippet(cx, l.span, "...").to_string();
132131
db.span_suggestion(left.span, "use the left value directly", lsnip);
@@ -137,7 +136,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
137136
(_, &ExprAddrOf(_, ref r)) => {
138137
let rty = cx.tables.expr_ty(r);
139138
let rcpy = is_copy(cx, rty, parent);
140-
if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
139+
if (requires_ref || rcpy) &&
140+
implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty], None) {
141141
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
142142
let rsnip = snippet(cx, r.span, "...").to_string();
143143
db.span_suggestion(right.span, "use the right value directly", rsnip);

clippy_lints/src/len_zero.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
199199

200200
/// Check the inherent impl's items for an `is_empty(self)` method.
201201
fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool {
202-
cx.tcx.inherent_impls(id)
202+
cx.tcx
203+
.inherent_impls(id)
203204
.iter()
204205
.any(|imp| cx.tcx.associated_items(*imp).any(|item| is_is_empty(cx, &item)))
205206
}

clippy_lints/src/needless_continue.rs

+59-68
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
//! This lint is **warn** by default.
3030
use rustc::lint::*;
3131
use syntax::ast;
32-
use syntax::codemap::{original_sp,DUMMY_SP};
32+
use syntax::codemap::{original_sp, DUMMY_SP};
3333
use std::borrow::Cow;
3434

3535
use utils::{in_macro, span_help_and_lint, snippet_block, snippet, trim_multiline};
@@ -163,7 +163,7 @@ impl EarlyLintPass for NeedlessContinue {
163163
* // region C
164164
* }
165165
* }
166-
*/
166+
* */
167167

168168
/// Given an expression, returns true if either of the following is true
169169
///
@@ -181,23 +181,27 @@ fn needless_continue_in_else(else_expr: &ast::Expr) -> bool {
181181
fn is_first_block_stmt_continue(block: &ast::Block) -> bool {
182182
block.stmts.get(0).map_or(false, |stmt| match stmt.node {
183183
ast::StmtKind::Semi(ref e) |
184-
ast::StmtKind::Expr(ref e) => if let ast::ExprKind::Continue(_) = e.node {
185-
true
186-
} else {
187-
false
184+
ast::StmtKind::Expr(ref e) => {
185+
if let ast::ExprKind::Continue(_) = e.node {
186+
true
187+
} else {
188+
false
189+
}
188190
},
189191
_ => false,
190192
})
191193
}
192194

193195
/// If `expr` is a loop expression (while/while let/for/loop), calls `func` with
194196
/// the AST object representing the loop block of `expr`.
195-
fn with_loop_block<F>(expr: &ast::Expr, mut func: F) where F: FnMut(&ast::Block) {
197+
fn with_loop_block<F>(expr: &ast::Expr, mut func: F)
198+
where F: FnMut(&ast::Block)
199+
{
196200
match expr.node {
197-
ast::ExprKind::While(_, ref loop_block, _) |
201+
ast::ExprKind::While(_, ref loop_block, _) |
198202
ast::ExprKind::WhileLet(_, _, ref loop_block, _) |
199-
ast::ExprKind::ForLoop( _, _, ref loop_block, _) |
200-
ast::ExprKind::Loop(ref loop_block, _) => func(loop_block),
203+
ast::ExprKind::ForLoop(_, _, ref loop_block, _) |
204+
ast::ExprKind::Loop(ref loop_block, _) => func(loop_block),
201205
_ => {},
202206
}
203207
}
@@ -211,15 +215,16 @@ fn with_loop_block<F>(expr: &ast::Expr, mut func: F) where F: FnMut(&ast::Block)
211215
/// - The `else` expression.
212216
///
213217
fn with_if_expr<F>(stmt: &ast::Stmt, mut func: F)
214-
where F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr) {
218+
where F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr)
219+
{
215220
match stmt.node {
216221
ast::StmtKind::Semi(ref e) |
217222
ast::StmtKind::Expr(ref e) => {
218223
if let ast::ExprKind::If(ref cond, ref if_block, Some(ref else_expr)) = e.node {
219224
func(e, cond, if_block, else_expr);
220225
}
221226
},
222-
_ => { },
227+
_ => {},
223228
}
224229
}
225230

@@ -249,45 +254,37 @@ struct LintData<'a> {
249254

250255
const MSG_REDUNDANT_ELSE_BLOCK: &'static str = "This else block is redundant.\n";
251256

252-
const MSG_ELSE_BLOCK_NOT_NEEDED: &'static str = "There is no need for an explicit `else` block for this `if` expression\n";
257+
const MSG_ELSE_BLOCK_NOT_NEEDED: &'static str = "There is no need for an explicit `else` block for this `if` \
258+
expression\n";
253259

254-
const DROP_ELSE_BLOCK_AND_MERGE_MSG: &'static str =
255-
"Consider dropping the else clause and merging the code that follows (in the loop) with the if block, like so:\n";
260+
const DROP_ELSE_BLOCK_AND_MERGE_MSG: &'static str = "Consider dropping the else clause and merging the code that \
261+
follows (in the loop) with the if block, like so:\n";
256262

257-
const DROP_ELSE_BLOCK_MSG: &'static str =
258-
"Consider dropping the else clause, and moving out the code in the else block, like so:\n";
263+
const DROP_ELSE_BLOCK_MSG: &'static str = "Consider dropping the else clause, and moving out the code in the else \
264+
block, like so:\n";
259265

260266

261-
fn emit_warning<'a>(ctx: &EarlyContext,
262-
data: &'a LintData,
263-
header: &str,
264-
typ: LintType) {
267+
fn emit_warning<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str, typ: LintType) {
265268

266269
// snip is the whole *help* message that appears after the warning.
267270
// message is the warning message.
268271
// expr is the expression which the lint warning message refers to.
269272
let (snip, message, expr) = match typ {
270273
LintType::ContinueInsideElseBlock => {
271-
(suggestion_snippet_for_continue_inside_else(ctx, data, header),
272-
MSG_REDUNDANT_ELSE_BLOCK,
273-
data.else_expr)
274+
(suggestion_snippet_for_continue_inside_else(ctx, data, header), MSG_REDUNDANT_ELSE_BLOCK, data.else_expr)
274275
},
275276
LintType::ContinueInsideThenBlock => {
276-
(suggestion_snippet_for_continue_inside_if(ctx, data, header),
277-
MSG_ELSE_BLOCK_NOT_NEEDED,
278-
data.if_expr)
279-
}
277+
(suggestion_snippet_for_continue_inside_if(ctx, data, header), MSG_ELSE_BLOCK_NOT_NEEDED, data.if_expr)
278+
},
280279
};
281280
span_help_and_lint(ctx, NEEDLESS_CONTINUE, expr.span, message, &snip);
282281
}
283282

284-
fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext,
285-
data: &'a LintData,
286-
header: &str) -> String {
283+
fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
287284
let cond_code = snippet(ctx, data.if_cond.span, "..");
288285

289-
let if_code = format!("if {} {{\n continue;\n}}\n", cond_code);
290-
/* ^^^^--- Four spaces of indentation. */
286+
let if_code = format!("if {} {{\n continue;\n}}\n", cond_code);
287+
/* ^^^^--- Four spaces of indentation. */
291288
// region B
292289
let else_code = snippet(ctx, data.else_expr.span, "..").into_owned();
293290
let else_code = erode_block(&else_code);
@@ -300,12 +297,9 @@ fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext,
300297
ret
301298
}
302299

303-
fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext,
304-
data: &'a LintData,
305-
header: &str) -> String
306-
{
300+
fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
307301
let cond_code = snippet(ctx, data.if_cond.span, "..");
308-
let mut if_code = format!("if {} {{\n", cond_code);
302+
let mut if_code = format!("if {} {{\n", cond_code);
309303

310304
// Region B
311305
let block_code = &snippet(ctx, data.if_block.span, "..").into_owned();
@@ -318,13 +312,12 @@ fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext,
318312
// These is the code in the loop block that follows the if/else construction
319313
// we are complaining about. We want to pull all of this code into the
320314
// `then` block of the `if` statement.
321-
let to_annex = data.block_stmts[data.stmt_idx+1..]
322-
.iter()
323-
.map(|stmt| {
324-
original_sp(stmt.span, DUMMY_SP)
325-
})
326-
.map(|span| snippet_block(ctx, span, "..").into_owned())
327-
.collect::<Vec<_>>().join("\n");
315+
let to_annex = data.block_stmts[data.stmt_idx + 1..]
316+
.iter()
317+
.map(|stmt| original_sp(stmt.span, DUMMY_SP))
318+
.map(|span| snippet_block(ctx, span, "..").into_owned())
319+
.collect::<Vec<_>>()
320+
.join("\n");
328321

329322
let mut ret = String::from(header);
330323

@@ -336,24 +329,22 @@ fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext,
336329
}
337330

338331
fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
339-
with_loop_block(expr, |loop_block| {
340-
for (i, stmt) in loop_block.stmts.iter().enumerate() {
341-
with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
342-
let data = &LintData {
343-
stmt_idx: i,
344-
if_expr: if_expr,
345-
if_cond: cond,
346-
if_block: then_block,
347-
else_expr: else_expr,
348-
block_stmts: &loop_block.stmts,
349-
};
350-
if needless_continue_in_else(else_expr) {
351-
emit_warning(ctx, data, DROP_ELSE_BLOCK_AND_MERGE_MSG, LintType::ContinueInsideElseBlock);
352-
} else if is_first_block_stmt_continue(then_block) {
353-
emit_warning(ctx, data, DROP_ELSE_BLOCK_MSG, LintType::ContinueInsideThenBlock);
354-
}
355-
});
356-
}
332+
with_loop_block(expr, |loop_block| for (i, stmt) in loop_block.stmts.iter().enumerate() {
333+
with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
334+
let data = &LintData {
335+
stmt_idx: i,
336+
if_expr: if_expr,
337+
if_cond: cond,
338+
if_block: then_block,
339+
else_expr: else_expr,
340+
block_stmts: &loop_block.stmts,
341+
};
342+
if needless_continue_in_else(else_expr) {
343+
emit_warning(ctx, data, DROP_ELSE_BLOCK_AND_MERGE_MSG, LintType::ContinueInsideElseBlock);
344+
} else if is_first_block_stmt_continue(then_block) {
345+
emit_warning(ctx, data, DROP_ELSE_BLOCK_MSG, LintType::ContinueInsideThenBlock);
346+
}
347+
});
357348
});
358349
}
359350

@@ -378,7 +369,7 @@ fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
378369
/// an empty string will be returned in that case.
379370
pub fn erode_from_back(s: &str) -> String {
380371
let mut ret = String::from(s);
381-
while ret.pop().map_or(false, |c| c != '}') { }
372+
while ret.pop().map_or(false, |c| c != '}') {}
382373
while let Some(c) = ret.pop() {
383374
if !c.is_whitespace() {
384375
ret.push(c);
@@ -409,10 +400,10 @@ pub fn erode_from_back(s: &str) -> String {
409400
///
410401
pub fn erode_from_front(s: &str) -> String {
411402
s.chars()
412-
.skip_while(|c| c.is_whitespace())
413-
.skip_while(|c| *c == '{')
414-
.skip_while(|c| *c == '\n')
415-
.collect::<String>()
403+
.skip_while(|c| c.is_whitespace())
404+
.skip_while(|c| *c == '{')
405+
.skip_while(|c| *c == '\n')
406+
.collect::<String>()
416407
}
417408

418409
/// If `s` contains the code for a block, delimited by braces, this function

clippy_lints/src/needless_pass_by_value.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,7 @@ impl<'a, 'tcx: 'a> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
284284
}
285285
}
286286

287-
fn borrow(
288-
&mut self,
289-
_: NodeId,
290-
_: Span,
291-
_: mc::cmt<'tcx>,
292-
_: ty::Region,
293-
_: ty::BorrowKind,
294-
_: euv::LoanCause
295-
) {
296-
}
287+
fn borrow(&mut self, _: NodeId, _: Span, _: mc::cmt<'tcx>, _: ty::Region, _: ty::BorrowKind, _: euv::LoanCause) {}
297288

298289
fn mutate(&mut self, _: NodeId, _: Span, _: mc::cmt<'tcx>, _: euv::MutateMode) {}
299290

clippy_lints/src/utils/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -978,4 +978,3 @@ pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> Opti
978978
.infer_ctxt((), Reveal::All)
979979
.enter(|infcx| ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes()))
980980
}
981-

0 commit comments

Comments
 (0)