Skip to content

Commit 5842463

Browse files
committed
Run rustfmt
1 parent 81401dd commit 5842463

15 files changed

+219
-167
lines changed

clippy_lints/src/copies.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
223223
/// `if a { c } else if b { d } else { e }`.
224224
fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
225225
let mut conds = SmallVector::new();
226-
let mut blocks : SmallVector<&Block> = SmallVector::new();
226+
let mut blocks: SmallVector<&Block> = SmallVector::new();
227227

228228
while let ExprIf(ref cond, ref then_expr, ref else_expr) = expr.node {
229229
conds.push(&**cond);
@@ -315,10 +315,10 @@ fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Option<(&T, &T)>
315315
return None;
316316
} else if exprs.len() == 2 {
317317
return if eq(&exprs[0], &exprs[1]) {
318-
Some((&exprs[0], &exprs[1]))
319-
} else {
320-
None
321-
};
318+
Some((&exprs[0], &exprs[1]))
319+
} else {
320+
None
321+
};
322322
}
323323

324324
let mut map: HashMap<_, Vec<&_>> = HashMap::with_capacity(exprs.len());

clippy_lints/src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
4646
if let Some((ty, map, key)) = check_cond(cx, check) {
4747
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
4848
// we can give a better error message
49-
let sole_expr = {
49+
let sole_expr = {
5050
else_block.is_none() &&
5151
if let ExprBlock(ref then_block) = then_block.node {
5252
(then_block.expr.is_some() as usize) + then_block.stmts.len() == 1
53-
} else {
53+
} else {
5454
true
5555
}
5656
};

clippy_lints/src/eq_op.rs

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,24 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
5656
if is_valid_operator(op) {
5757
if SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
5858
span_lint(cx,
59-
EQ_OP,
60-
e.span,
61-
&format!("equal expressions as operands to `{}`", op.node.as_str()));
59+
EQ_OP,
60+
e.span,
61+
&format!("equal expressions as operands to `{}`", op.node.as_str()));
6262
} else {
6363
let trait_id = match op.node {
6464
BiAdd => cx.tcx.lang_items.add_trait(),
6565
BiSub => cx.tcx.lang_items.sub_trait(),
6666
BiMul => cx.tcx.lang_items.mul_trait(),
6767
BiDiv => cx.tcx.lang_items.div_trait(),
6868
BiRem => cx.tcx.lang_items.rem_trait(),
69-
BiAnd |
70-
BiOr => None,
69+
BiAnd | BiOr => None,
7170
BiBitXor => cx.tcx.lang_items.bitxor_trait(),
7271
BiBitAnd => cx.tcx.lang_items.bitand_trait(),
7372
BiBitOr => cx.tcx.lang_items.bitor_trait(),
7473
BiShl => cx.tcx.lang_items.shl_trait(),
7574
BiShr => cx.tcx.lang_items.shr_trait(),
76-
BiNe |
77-
BiEq => cx.tcx.lang_items.eq_trait(),
78-
BiLt |
79-
BiLe |
80-
BiGe |
81-
BiGt => cx.tcx.lang_items.ord_trait(),
75+
BiNe | BiEq => cx.tcx.lang_items.eq_trait(),
76+
BiLt | BiLe | BiGe | BiGt => cx.tcx.lang_items.ord_trait(),
8277
};
8378
if let Some(trait_id) = trait_id {
8479
#[allow(match_same_arms)]
@@ -90,57 +85,55 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
9085
(&ExprAddrOf(_, ref l), &ExprAddrOf(_, ref r)) => {
9186
if implements_trait(cx, cx.tables.expr_ty(l), trait_id, &[cx.tables.expr_ty(r)], None) {
9287
span_lint_and_then(cx,
93-
OP_REF,
94-
e.span,
95-
"taken reference of both operands, which is done automatically by the operator anyway",
96-
|db| {
97-
let lsnip = snippet(cx, l.span, "...").to_string();
98-
let rsnip = snippet(cx, r.span, "...").to_string();
99-
multispan_sugg(db,
100-
"use the values directly".to_string(),
101-
vec![(left.span, lsnip),
88+
OP_REF,
89+
e.span,
90+
"taken reference of both operands, which is done automatically \
91+
by the operator anyway",
92+
|db| {
93+
let lsnip = snippet(cx, l.span, "...").to_string();
94+
let rsnip = snippet(cx, r.span, "...").to_string();
95+
multispan_sugg(db,
96+
"use the values directly".to_string(),
97+
vec![(left.span, lsnip),
10298
(right.span, rsnip)]);
103-
}
104-
)
99+
})
105100
}
106-
}
101+
},
107102
// &foo == bar
108103
(&ExprAddrOf(_, ref l), _) => {
109-
if implements_trait(cx, cx.tables.expr_ty(l), trait_id, &[cx.tables.expr_ty(right)], None) {
110-
span_lint_and_then(cx,
111-
OP_REF,
112-
e.span,
113-
"taken reference of left operand",
114-
|db| {
115-
let lsnip = snippet(cx, l.span, "...").to_string();
116-
let rsnip = Sugg::hir(cx, right, "...").deref().to_string();
117-
multispan_sugg(db,
118-
"dereference the right operand instead".to_string(),
119-
vec![(left.span, lsnip),
104+
if implements_trait(cx,
105+
cx.tables.expr_ty(l),
106+
trait_id,
107+
&[cx.tables.expr_ty(right)],
108+
None) {
109+
span_lint_and_then(cx, OP_REF, e.span, "taken reference of left operand", |db| {
110+
let lsnip = snippet(cx, l.span, "...").to_string();
111+
let rsnip = Sugg::hir(cx, right, "...").deref().to_string();
112+
multispan_sugg(db,
113+
"dereference the right operand instead".to_string(),
114+
vec![(left.span, lsnip),
120115
(right.span, rsnip)]);
121-
}
122-
)
116+
})
123117
}
124-
}
118+
},
125119
// foo == &bar
126120
(_, &ExprAddrOf(_, ref r)) => {
127-
if implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[cx.tables.expr_ty(r)], None) {
128-
span_lint_and_then(cx,
129-
OP_REF,
130-
e.span,
131-
"taken reference of right operand",
132-
|db| {
133-
let lsnip = Sugg::hir(cx, left, "...").deref().to_string();
134-
let rsnip = snippet(cx, r.span, "...").to_string();
135-
multispan_sugg(db,
136-
"dereference the left operand instead".to_string(),
137-
vec![(left.span, lsnip),
121+
if implements_trait(cx,
122+
cx.tables.expr_ty(left),
123+
trait_id,
124+
&[cx.tables.expr_ty(r)],
125+
None) {
126+
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
127+
let lsnip = Sugg::hir(cx, left, "...").deref().to_string();
128+
let rsnip = snippet(cx, r.span, "...").to_string();
129+
multispan_sugg(db,
130+
"dereference the left operand instead".to_string(),
131+
vec![(left.span, lsnip),
138132
(right.span, rsnip)]);
139-
}
140-
)
133+
})
141134
}
142-
}
143-
_ => {}
135+
},
136+
_ => {},
144137
}
145138
}
146139
}

clippy_lints/src/formatting.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,19 @@ impl EarlyLintPass for Formatting {
100100
fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
101101
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
102102
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
103-
let eq_span = Span { lo: lhs.span.hi, hi: rhs.span.lo, ctxt: NO_EXPANSION };
103+
let eq_span = Span {
104+
lo: lhs.span.hi,
105+
hi: rhs.span.lo,
106+
ctxt: NO_EXPANSION,
107+
};
104108
if let ast::ExprKind::Unary(op, ref sub_rhs) = rhs.node {
105109
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
106110
let op = ast::UnOp::to_string(op);
107-
let eqop_span= Span { lo: lhs.span.hi, hi: sub_rhs.span.lo, ctxt: NO_EXPANSION };
111+
let eqop_span = Span {
112+
lo: lhs.span.hi,
113+
hi: sub_rhs.span.lo,
114+
ctxt: NO_EXPANSION,
115+
};
108116
if eq_snippet.ends_with('=') {
109117
span_note_and_lint(cx,
110118
SUSPICIOUS_ASSIGNMENT_FORMATTING,
@@ -127,7 +135,11 @@ fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
127135
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(then.span) {
128136
// this will be a span from the closing ‘}’ of the “then” block (excluding) to the
129137
// “if” of the “else if” block (excluding)
130-
let else_span = Span { lo: then.span.hi, hi: else_.span.lo, ctxt: NO_EXPANSION };
138+
let else_span = Span {
139+
lo: then.span.hi,
140+
hi: else_.span.lo,
141+
ctxt: NO_EXPANSION,
142+
};
131143

132144
// the snippet should look like " else \n " with maybe comments anywhere
133145
// it’s bad when there is a ‘\n’ after the “else”
@@ -154,9 +166,17 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
154166
for element in array {
155167
if let ast::ExprKind::Binary(ref op, ref lhs, _) = element.node {
156168
if !differing_macro_contexts(lhs.span, op.span) {
157-
let space_span = Span { lo: lhs.span.hi, hi: op.span.lo, ctxt: NO_EXPANSION };
169+
let space_span = Span {
170+
lo: lhs.span.hi,
171+
hi: op.span.lo,
172+
ctxt: NO_EXPANSION,
173+
};
158174
if let Some(space_snippet) = snippet_opt(cx, space_span) {
159-
let lint_span = Span { lo: lhs.span.hi, hi: lhs.span.hi, ctxt: NO_EXPANSION };
175+
let lint_span = Span {
176+
lo: lhs.span.hi,
177+
hi: lhs.span.hi,
178+
ctxt: NO_EXPANSION,
179+
};
160180
if space_snippet.contains('\n') {
161181
span_note_and_lint(cx,
162182
POSSIBLE_MISSING_COMMA,
@@ -174,10 +194,14 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
174194

175195
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for consecutive ifs.
176196
fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Expr) {
177-
if !differing_macro_contexts(first.span, second.span) && !in_macro(first.span) &&
178-
unsugar_if(first).is_some() && unsugar_if(second).is_some() {
197+
if !differing_macro_contexts(first.span, second.span) && !in_macro(first.span) && unsugar_if(first).is_some() &&
198+
unsugar_if(second).is_some() {
179199
// where the else would be
180-
let else_span = Span { lo: first.span.hi, hi: second.span.lo, ctxt: NO_EXPANSION };
200+
let else_span = Span {
201+
lo: first.span.hi,
202+
hi: second.span.lo,
203+
ctxt: NO_EXPANSION,
204+
};
181205

182206
if let Some(else_snippet) = snippet_opt(cx, else_span) {
183207
if !else_snippet.contains('\n') {

clippy_lints/src/lifetimes.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ enum RefLt {
8989
Named(Name),
9090
}
9191

92-
fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body: Option<BodyId>, generics: &'tcx Generics, span: Span) {
92+
fn check_fn_inner<'a, 'tcx>(
93+
cx: &LateContext<'a, 'tcx>,
94+
decl: &'tcx FnDecl,
95+
body: Option<BodyId>,
96+
generics: &'tcx Generics,
97+
span: Span
98+
) {
9399
if in_external_macro(cx, span) || has_where_lifetimes(cx, &generics.where_clause) {
94100
return;
95101
}
@@ -128,7 +134,7 @@ fn could_use_elision<'a, 'tcx: 'a>(
128134
func: &'tcx FnDecl,
129135
body: Option<BodyId>,
130136
named_lts: &'tcx [LifetimeDef],
131-
bounds_lts: Vec<&'tcx Lifetime>,
137+
bounds_lts: Vec<&'tcx Lifetime>
132138
) -> bool {
133139
// There are two scenarios where elision works:
134140
// * no output references, all input references have different LT
@@ -265,11 +271,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
265271
}
266272

267273
fn into_vec(self) -> Option<Vec<RefLt>> {
268-
if self.abort {
269-
None
270-
} else {
271-
Some(self.lts)
272-
}
274+
if self.abort { None } else { Some(self.lts) }
273275
}
274276

275277
fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) {
@@ -359,9 +361,11 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
359361
// and check that all lifetimes are allowed
360362
match visitor.into_vec() {
361363
None => return false,
362-
Some(lts) => for lt in lts {
363-
if !allowed_lts.contains(&lt) {
364-
return true;
364+
Some(lts) => {
365+
for lt in lts {
366+
if !allowed_lts.contains(&lt) {
367+
return true;
368+
}
365369
}
366370
},
367371
}

clippy_lints/src/loops.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
409409
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
410410
if let StmtSemi(ref expr, _) = stmt.node {
411411
if let ExprMethodCall(ref method, _, ref args) = expr.node {
412-
if args.len() == 1 && method.node == "collect" &&
413-
match_trait_method(cx, expr, &paths::ITERATOR) {
412+
if args.len() == 1 && method.node == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) {
414413
span_lint(cx,
415414
UNUSED_COLLECT,
416415
expr.span,

clippy_lints/src/misc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
499499
/// Test whether an expression is in a macro expansion (e.g. something generated by
500500
/// `#[derive(...)`] or the like).
501501
fn in_attributes_expansion(expr: &Expr) -> bool {
502-
expr.span.ctxt.outer().expn_info().map_or(false, |info| {
503-
matches!(info.callee.format, ExpnFormat::MacroAttribute(_))
504-
})
502+
expr.span.ctxt.outer().expn_info().map_or(false, |info| matches!(info.callee.format, ExpnFormat::MacroAttribute(_)))
505503
}
506504

507505
/// Test whether `def` is a variable defined outside a macro.

clippy_lints/src/needless_bool.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
7777
|db| { db.span_suggestion(e.span, "you can reduce it to", hint); });
7878
};
7979
if let ExprBlock(ref then_block) = then_block.node {
80-
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
81-
(RetBool(true), RetBool(true)) |
82-
(Bool(true), Bool(true)) => {
83-
span_lint(cx,
84-
NEEDLESS_BOOL,
85-
e.span,
86-
"this if-then-else expression will always return true");
87-
},
88-
(RetBool(false), RetBool(false)) |
89-
(Bool(false), Bool(false)) => {
90-
span_lint(cx,
91-
NEEDLESS_BOOL,
92-
e.span,
93-
"this if-then-else expression will always return false");
94-
},
95-
(RetBool(true), RetBool(false)) => reduce(true, false),
96-
(Bool(true), Bool(false)) => reduce(false, false),
97-
(RetBool(false), RetBool(true)) => reduce(true, true),
98-
(Bool(false), Bool(true)) => reduce(false, true),
99-
_ => (),
100-
}
80+
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
81+
(RetBool(true), RetBool(true)) |
82+
(Bool(true), Bool(true)) => {
83+
span_lint(cx,
84+
NEEDLESS_BOOL,
85+
e.span,
86+
"this if-then-else expression will always return true");
87+
},
88+
(RetBool(false), RetBool(false)) |
89+
(Bool(false), Bool(false)) => {
90+
span_lint(cx,
91+
NEEDLESS_BOOL,
92+
e.span,
93+
"this if-then-else expression will always return false");
94+
},
95+
(RetBool(true), RetBool(false)) => reduce(true, false),
96+
(Bool(true), Bool(false)) => reduce(false, false),
97+
(RetBool(false), RetBool(true)) => reduce(true, true),
98+
(Bool(false), Bool(true)) => reduce(false, true),
99+
_ => (),
100+
}
101101
} else {
102102
panic!("IfExpr 'then' node is not an ExprBlock");
103103
}

0 commit comments

Comments
 (0)