Skip to content

Commit 4f3d142

Browse files
authored
Merge pull request #990 from Manishearth/rustfmt
Cleanup
2 parents e683231 + dd99a88 commit 4f3d142

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+431
-489
lines changed

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,16 @@ name = "cargo-clippy"
2323
test = false
2424

2525
[dependencies]
26-
regex-syntax = "0.3.0"
2726
regex_macros = { version = "0.1.33", optional = true }
28-
semver = "0.2.1"
29-
toml = "0.1"
30-
unicode-normalization = "0.1"
31-
quine-mc_cluskey = "0.2.2"
3227
# begin automatic update
3328
clippy_lints = { version = "0.0.75", path = "clippy_lints" }
3429
# end automatic update
35-
rustc-serialize = "0.3"
3630

3731
[dev-dependencies]
3832
compiletest_rs = "0.2.0"
3933
lazy_static = "0.1.15"
4034
regex = "0.1.56"
35+
rustc-serialize = "0.3"
4136

4237
[features]
4338
debugging = []

clippy_lints/src/arithmetic.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare_restriction_lint! {
3838

3939
#[derive(Copy, Clone, Default)]
4040
pub struct Arithmetic {
41-
span: Option<Span>
41+
span: Option<Span>,
4242
}
4343

4444
impl LintPass for Arithmetic {
@@ -49,48 +49,36 @@ impl LintPass for Arithmetic {
4949

5050
impl LateLintPass for Arithmetic {
5151
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
52-
if let Some(_) = self.span { return; }
52+
if let Some(_) = self.span {
53+
return;
54+
}
5355
match expr.node {
5456
hir::ExprBinary(ref op, ref l, ref r) => {
5557
match op.node {
56-
hir::BiAnd | hir::BiOr | hir::BiBitAnd |
57-
hir::BiBitOr | hir::BiBitXor | hir::BiShl | hir::BiShr |
58-
hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe |
59-
hir::BiGt => return,
60-
_ => ()
58+
hir::BiAnd | hir::BiOr | hir::BiBitAnd | hir::BiBitOr | hir::BiBitXor | hir::BiShl |
59+
hir::BiShr | hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => return,
60+
_ => (),
6161
}
6262
let (l_ty, r_ty) = (cx.tcx.expr_ty(l), cx.tcx.expr_ty(r));
6363
if l_ty.is_integral() && r_ty.is_integral() {
64-
span_lint(cx,
65-
INTEGER_ARITHMETIC,
66-
expr.span,
67-
"integer arithmetic detected");
64+
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
6865
self.span = Some(expr.span);
6966
} else if l_ty.is_floating_point() && r_ty.is_floating_point() {
70-
span_lint(cx,
71-
FLOAT_ARITHMETIC,
72-
expr.span,
73-
"floating-point arithmetic detected");
67+
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
7468
self.span = Some(expr.span);
7569
}
76-
},
70+
}
7771
hir::ExprUnary(hir::UnOp::UnNeg, ref arg) => {
7872
let ty = cx.tcx.expr_ty(arg);
7973
if ty.is_integral() {
80-
span_lint(cx,
81-
INTEGER_ARITHMETIC,
82-
expr.span,
83-
"integer arithmetic detected");
74+
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
8475
self.span = Some(expr.span);
8576
} else if ty.is_floating_point() {
86-
span_lint(cx,
87-
FLOAT_ARITHMETIC,
88-
expr.span,
89-
"floating-point arithmetic detected");
77+
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
9078
self.span = Some(expr.span);
9179
}
92-
},
93-
_ => ()
80+
}
81+
_ => (),
9482
}
9583
}
9684

clippy_lints/src/array_indexing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ impl LateLintPass for ArrayIndexing {
7979
// Index is a constant range
8080
if let Some(range) = utils::unsugar_range(index) {
8181
let start = range.start
82-
.map(|start| eval_const_expr_partial(cx.tcx, start, ExprTypeChecked, None))
83-
.map(|v| v.ok());
82+
.map(|start| eval_const_expr_partial(cx.tcx, start, ExprTypeChecked, None))
83+
.map(|v| v.ok());
8484
let end = range.end
85-
.map(|end| eval_const_expr_partial(cx.tcx, end, ExprTypeChecked, None))
86-
.map(|v| v.ok());
85+
.map(|end| eval_const_expr_partial(cx.tcx, end, ExprTypeChecked, None))
86+
.map(|v| v.ok());
8787

8888
if let Some((start, end)) = to_const_range(start, end, range.limits, size) {
8989
if start > size || end > size {

clippy_lints/src/assign_ops.rs

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,24 @@ impl LateLintPass for AssignOps {
5151
match expr.node {
5252
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
5353
if let (Some(l), Some(r)) = (snippet_opt(cx, lhs.span), snippet_opt(cx, rhs.span)) {
54-
span_lint_and_then(cx,
55-
ASSIGN_OPS,
56-
expr.span,
57-
"assign operation detected",
58-
|db| {
59-
match rhs.node {
60-
hir::ExprBinary(op2, _, _) if op2 != op => {
61-
db.span_suggestion(expr.span,
62-
"replace it with",
63-
format!("{} = {} {} ({})", l, l, op.node.as_str(), r));
64-
},
65-
_ => {
66-
db.span_suggestion(expr.span,
67-
"replace it with",
68-
format!("{} = {} {} {}", l, l, op.node.as_str(), r));
69-
}
70-
}
71-
});
54+
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {
55+
match rhs.node {
56+
hir::ExprBinary(op2, _, _) if op2 != op => {
57+
db.span_suggestion(expr.span,
58+
"replace it with",
59+
format!("{} = {} {} ({})", l, l, op.node.as_str(), r));
60+
}
61+
_ => {
62+
db.span_suggestion(expr.span,
63+
"replace it with",
64+
format!("{} = {} {} {}", l, l, op.node.as_str(), r));
65+
}
66+
}
67+
});
7268
} else {
73-
span_lint(cx,
74-
ASSIGN_OPS,
75-
expr.span,
76-
"assign operation detected");
69+
span_lint(cx, ASSIGN_OPS, expr.span, "assign operation detected");
7770
}
78-
},
71+
}
7972
hir::ExprAssign(ref assignee, ref e) => {
8073
if let hir::ExprBinary(op, ref l, ref r) = e.node {
8174
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
@@ -104,28 +97,32 @@ impl LateLintPass for AssignOps {
10497
}
10598
}
10699
}
107-
if ops!(op.node, cx, ty, rty, Add:BiAdd,
108-
Sub:BiSub,
109-
Mul:BiMul,
110-
Div:BiDiv,
111-
Rem:BiRem,
112-
And:BiAnd,
113-
Or:BiOr,
114-
BitAnd:BiBitAnd,
115-
BitOr:BiBitOr,
116-
BitXor:BiBitXor,
117-
Shr:BiShr,
118-
Shl:BiShl
119-
) {
120-
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) {
100+
if ops!(op.node,
101+
cx,
102+
ty,
103+
rty,
104+
Add: BiAdd,
105+
Sub: BiSub,
106+
Mul: BiMul,
107+
Div: BiDiv,
108+
Rem: BiRem,
109+
And: BiAnd,
110+
Or: BiOr,
111+
BitAnd: BiBitAnd,
112+
BitOr: BiBitOr,
113+
BitXor: BiBitXor,
114+
Shr: BiShr,
115+
Shl: BiShl) {
116+
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span),
117+
snippet_opt(cx, rhs.span)) {
121118
span_lint_and_then(cx,
122119
ASSIGN_OP_PATTERN,
123120
expr.span,
124121
"manual implementation of an assign operation",
125122
|db| {
126123
db.span_suggestion(expr.span,
127-
"replace it with",
128-
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
124+
"replace it with",
125+
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
129126
});
130127
} else {
131128
span_lint(cx,
@@ -142,17 +139,16 @@ impl LateLintPass for AssignOps {
142139
// a = b commutative_op a
143140
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) {
144141
match op.node {
145-
hir::BiAdd | hir::BiMul |
146-
hir::BiAnd | hir::BiOr |
147-
hir::BiBitXor | hir::BiBitAnd | hir::BiBitOr => {
142+
hir::BiAdd | hir::BiMul | hir::BiAnd | hir::BiOr | hir::BiBitXor | hir::BiBitAnd |
143+
hir::BiBitOr => {
148144
lint(assignee, l);
149-
},
150-
_ => {},
145+
}
146+
_ => {}
151147
}
152148
}
153149
}
154-
},
155-
_ => {},
150+
}
151+
_ => {}
156152
}
157153
}
158154
}

clippy_lints/src/bit_mask.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,11 @@ impl LateLintPass for BitMask {
9191
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
9292
if let ExprBinary(ref cmp, ref left, ref right) = e.node {
9393
if cmp.node.is_comparison() {
94-
fetch_int_literal(cx, right).map_or_else(|| {
95-
fetch_int_literal(cx, left).map_or((), |cmp_val| {
96-
check_compare(cx,
97-
right,
98-
invert_cmp(cmp.node),
99-
cmp_val,
100-
&e.span)
101-
})
102-
},
103-
|cmp_opt| check_compare(cx, left, cmp.node, cmp_opt, &e.span))
94+
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
95+
check_compare(cx, left, cmp.node, cmp_opt, &e.span)
96+
} else if let Some(cmp_val) = fetch_int_literal(cx, left) {
97+
check_compare(cx, right, invert_cmp(cmp.node), cmp_val, &e.span)
98+
}
10499
}
105100
}
106101
}

clippy_lints/src/booleans.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
322322
let simplified_stats = terminal_stats(suggestion);
323323
let mut improvement = false;
324324
for i in 0..32 {
325-
// ignore any "simplifications" that end up requiring a terminal more often than in the original expression
325+
// ignore any "simplifications" that end up requiring a terminal more often
326+
// than in the original expression
326327
if stats.terminals[i] < simplified_stats.terminals[i] {
327328
continue 'simplified;
328329
}
@@ -332,17 +333,18 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
332333
e.span,
333334
"this boolean expression contains a logic bug",
334335
|db| {
335-
db.span_help(h2q.terminals[i].span,
336-
"this expression can be optimized out by applying \
337-
boolean operations to the outer expression");
338-
db.span_suggestion(e.span,
339-
"it would look like the following",
340-
suggest(self.0, suggestion, &h2q.terminals));
341-
});
336+
db.span_help(h2q.terminals[i].span,
337+
"this expression can be optimized out by applying boolean operations to the \
338+
outer expression");
339+
db.span_suggestion(e.span,
340+
"it would look like the following",
341+
suggest(self.0, suggestion, &h2q.terminals));
342+
});
342343
// don't also lint `NONMINIMAL_BOOL`
343344
return;
344345
}
345-
// if the number of occurrences of a terminal decreases or any of the stats decreases while none increases
346+
// if the number of occurrences of a terminal decreases or any of the stats
347+
// decreases while none increases
346348
improvement |= (stats.terminals[i] > simplified_stats.terminals[i]) ||
347349
(stats.negations > simplified_stats.negations &&
348350
stats.ops == simplified_stats.ops) ||
@@ -358,12 +360,10 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
358360
e.span,
359361
"this boolean expression can be simplified",
360362
|db| {
361-
for suggestion in &improvements {
362-
db.span_suggestion(e.span,
363-
"try",
364-
suggest(self.0, suggestion, &h2q.terminals));
365-
}
366-
});
363+
for suggestion in &improvements {
364+
db.span_suggestion(e.span, "try", suggest(self.0, suggestion, &h2q.terminals));
365+
}
366+
});
367367
}
368368
}
369369
}

clippy_lints/src/cyclomatic_complexity.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use utils::{in_macro, LimitStack, span_help_and_lint, paths, match_type};
1313

1414
/// **What it does:** This lint checks for methods with high cyclomatic complexity
1515
///
16-
/// **Why is this bad?** Methods of high cyclomatic complexity tend to be badly readable. Also LLVM will usually optimize small methods better.
16+
/// **Why is this bad?** Methods of high cyclomatic complexity tend to be badly readable. Also LLVM
17+
/// will usually optimize small methods better.
1718
///
1819
/// **Known problems:** Sometimes it's hard to find a way to reduce the complexity
1920
///
@@ -69,7 +70,7 @@ impl CyclomaticComplexity {
6970
returns / 2
7071
};
7172

72-
if cc + divergence < match_arms + short_circuits {
73+
if cc + divergence < match_arms + short_circuits {
7374
report_cc_bug(cx, cc, match_arms, divergence, short_circuits, ret_adjust, span);
7475
} else {
7576
let mut rust_cc = cc + divergence - match_arms - short_circuits;
@@ -117,7 +118,7 @@ impl LateLintPass for CyclomaticComplexity {
117118
}
118119
}
119120

120-
struct CCHelper<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
121+
struct CCHelper<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
121122
match_arms: u64,
122123
divergence: u64,
123124
returns: u64,
@@ -176,8 +177,9 @@ fn report_cc_bug(cx: &LateContext, cc: u64, narms: u64, div: u64, shorts: u64, r
176177
if cx.current_level(CYCLOMATIC_COMPLEXITY) != Level::Allow {
177178
cx.sess().span_note_without_error(span,
178179
&format!("Clippy encountered a bug calculating cyclomatic complexity \
179-
(hide this message with `#[allow(cyclomatic_complexity)]`): cc \
180-
= {}, arms = {}, div = {}, shorts = {}, returns = {}. Please file a bug report.",
180+
(hide this message with `#[allow(cyclomatic_complexity)]`): \
181+
cc = {}, arms = {}, div = {}, shorts = {}, returns = {}. \
182+
Please file a bug report.",
181183
cc,
182184
narms,
183185
div,

clippy_lints/src/derive.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ impl LateLintPass for Derive {
8484
}
8585

8686
/// Implementation of the `DERIVE_HASH_XOR_EQ` lint.
87-
fn check_hash_peq<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, span: Span, trait_ref: &TraitRef, ty: ty::Ty<'tcx>, hash_is_automatically_derived: bool) {
87+
fn check_hash_peq<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, span: Span, trait_ref: &TraitRef, ty: ty::Ty<'tcx>,
88+
hash_is_automatically_derived: bool) {
8889
if_let_chain! {[
8990
match_path(&trait_ref.path, &paths::HASH),
9091
let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait()
@@ -137,7 +138,8 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
137138

138139
// Some types are not Clone by default but could be cloned `by hand` if necessary
139140
match ty.sty {
140-
TypeVariants::TyEnum(def, substs) | TypeVariants::TyStruct(def, substs) => {
141+
TypeVariants::TyEnum(def, substs) |
142+
TypeVariants::TyStruct(def, substs) => {
141143
for variant in &def.variants {
142144
for field in &variant.fields {
143145
match field.ty(cx.tcx, substs).sty {

clippy_lints/src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn check_doc(cx: &EarlyContext, valid_idents: &[String], docs: &[(&str, Span
108108
/// First byte of the current potential match
109109
current_word_begin: usize,
110110
/// List of lines and their associated span
111-
docs: &'a[(&'a str, Span)],
111+
docs: &'a [(&'a str, Span)],
112112
/// Index of the current line we are parsing
113113
line: usize,
114114
/// Whether we are in a link

0 commit comments

Comments
 (0)