Skip to content

Commit e4b3cbb

Browse files
committed
Merge pull request #726 from Manishearth/fmt
Rustfmt everything
2 parents e256055 + bd45cfd commit e4b3cbb

18 files changed

+138
-204
lines changed

src/block_in_if_condition.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl LateLintPass for BlockInIfCondition {
9292
snippet_block(cx, then.span, "..")));
9393
}
9494
} else {
95-
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span,
96-
|e| e.span);
95+
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
9796
if in_macro(cx, span) || differing_macro_contexts(expr.span, span) {
9897
return;
9998
}

src/collapsible_if.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ fn check_if(cx: &LateContext, e: &Expr) {
7171
});
7272
}}
7373
} else if let Some(&Expr{ node: ExprIf(ref check_inner, ref content, None), span: sp, ..}) =
74-
single_stmt_of_block(then) {
74+
single_stmt_of_block(then) {
7575
if e.span.expn_id != sp.expn_id {
7676
return;
7777
}
78-
span_lint_and_then(cx,
79-
COLLAPSIBLE_IF,
80-
e.span,
81-
"this if statement can be collapsed", |db| {
82-
db.span_suggestion(e.span, "try",
78+
span_lint_and_then(cx, COLLAPSIBLE_IF, e.span, "this if statement can be collapsed", |db| {
79+
db.span_suggestion(e.span,
80+
"try",
8381
format!("if {} && {} {}",
8482
check_to_string(cx, check),
8583
check_to_string(cx, check_inner),

src/copies.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) {
9191
h.finish()
9292
};
9393

94-
let eq: &Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool {
95-
SpanlessEq::new(cx).eq_block(lhs, rhs)
96-
};
94+
let eq: &Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) };
9795

9896
if let Some((i, j)) = search_same(blocks, hash, eq) {
9997
span_note_and_lint(cx,

src/derive.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,7 @@ impl LateLintPass for Derive {
8787
}
8888

8989
/// Implementation of the `DERIVE_HASH_XOR_EQ` lint.
90-
fn check_hash_peq(
91-
cx: &LateContext,
92-
span: Span,
93-
trait_ref: &TraitRef,
94-
ty: ty::Ty,
95-
hash_is_automatically_derived: bool
96-
) {
90+
fn check_hash_peq(cx: &LateContext, span: Span, trait_ref: &TraitRef, ty: ty::Ty, hash_is_automatically_derived: bool) {
9791
if_let_chain! {[
9892
match_path(&trait_ref.path, &HASH_PATH),
9993
let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait()
@@ -143,9 +137,7 @@ fn check_hash_peq(
143137
}
144138

145139
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
146-
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>,
147-
item: &Item,
148-
trait_ref: &TraitRef, ty: ty::Ty<'tcx>) {
140+
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: ty::Ty<'tcx>) {
149141
if match_path(&trait_ref.path, &CLONE_TRAIT_PATH) {
150142
let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, item.id);
151143
let subst_ty = ty.subst(cx.tcx, &parameter_environment.free_substs);

src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl LateLintPass for HashMapLint {
4848
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
4949
// we can give a better error message
5050
let sole_expr = else_block.is_none() &&
51-
if then_block.expr.is_some() { 1 } else { 0 } + then_block.stmts.len() == 1;
51+
((then_block.expr.is_some() as usize) + then_block.stmts.len() == 1);
5252

5353
let mut visitor = InsertVisitor {
5454
cx: cx,

src/enum_variants.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ fn var2str(var: &Variant) -> InternedString {
3131
var.node.name.name.as_str()
3232
}
3333

34-
/*
35-
FIXME: waiting for https://github.com/rust-lang/rust/pull/31700
36-
fn partial_match(pre: &str, name: &str) -> usize {
37-
// skip(1) to ensure that the prefix never takes the whole variant name
38-
pre.chars().zip(name.chars().rev().skip(1).rev()).take_while(|&(l, r)| l == r).count()
39-
}
40-
41-
fn partial_rmatch(post: &str, name: &str) -> usize {
42-
// skip(1) to ensure that the postfix never takes the whole variant name
43-
post.chars().rev().zip(name.chars().skip(1).rev()).take_while(|&(l, r)| l == r).count()
44-
}*/
34+
// FIXME: waiting for https://github.com/rust-lang/rust/pull/31700
35+
// fn partial_match(pre: &str, name: &str) -> usize {
36+
// // skip(1) to ensure that the prefix never takes the whole variant name
37+
// pre.chars().zip(name.chars().rev().skip(1).rev()).take_while(|&(l, r)| l == r).count()
38+
// }
39+
//
40+
// fn partial_rmatch(post: &str, name: &str) -> usize {
41+
// // skip(1) to ensure that the postfix never takes the whole variant name
42+
// post.chars().rev().zip(name.chars().skip(1).rev()).take_while(|&(l, r)| l == r).count()
43+
// }
4544

4645
fn partial_match(pre: &str, name: &str) -> usize {
4746
let mut name_iter = name.chars();
@@ -99,7 +98,8 @@ impl EarlyLintPass for EnumVariantNames {
9998
item.span,
10099
&format!("All variants have the same {}fix: `{}`", what, value),
101100
&format!("remove the {}fixes and use full paths to \
102-
the variants instead of glob imports", what));
101+
the variants instead of glob imports",
102+
what));
103103
}
104104
}
105105
}

src/formatting.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
9696
span_note_and_lint(cx,
9797
SUSPICIOUS_ASSIGNMENT_FORMATTING,
9898
eqop_span,
99-
&format!("this looks like you are trying to use `.. {op}= ..`, but you really are doing `.. = ({op} ..)`", op=op),
99+
&format!("this looks like you are trying to use `.. {op}= ..`, but you \
100+
really are doing `.. = ({op} ..)`",
101+
op = op),
100102
eqop_span,
101-
&format!("to remove this lint, use either `{op}=` or `= {op}`", op=op));
103+
&format!("to remove this lint, use either `{op}=` or `= {op}`", op = op));
102104
}
103105
}
104106
}
@@ -109,9 +111,7 @@ fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
109111
/// Implementation of the SUSPICIOUS_ELSE_FORMATTING lint for weird `else if`.
110112
fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
111113
if let Some((then, &Some(ref else_))) = unsugar_if(expr) {
112-
if unsugar_if(else_).is_some() &&
113-
!differing_macro_contexts(then.span, else_.span) &&
114-
!in_macro(cx, then.span) {
114+
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(cx, then.span) {
115115
// this will be a span from the closing ‘}’ of the “then” block (excluding) to the
116116
// “if” of the “else if” block (excluding)
117117
let else_span = mk_sp(then.span.hi, else_.span.lo);
@@ -127,7 +127,8 @@ fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
127127
else_span,
128128
"this is an `else if` but the formatting might hide it",
129129
else_span,
130-
"to remove this lint, remove the `else` or remove the new line between `else` and `if`");
130+
"to remove this lint, remove the `else` or remove the new line between `else` \
131+
and `if`");
131132
}
132133
}
133134
}
@@ -136,10 +137,8 @@ fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
136137

137138
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for consecutive ifs.
138139
fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Expr) {
139-
if !differing_macro_contexts(first.span, second.span) &&
140-
!in_macro(cx, first.span) &&
141-
unsugar_if(first).is_some() &&
142-
unsugar_if(second).is_some() {
140+
if !differing_macro_contexts(first.span, second.span) && !in_macro(cx, first.span) &&
141+
unsugar_if(first).is_some() && unsugar_if(second).is_some() {
143142
// where the else would be
144143
let else_span = mk_sp(first.span.hi, second.span.lo);
145144

@@ -150,14 +149,15 @@ fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Exp
150149
else_span,
151150
"this looks like an `else if` but the `else` is missing",
152151
else_span,
153-
"to remove this lint, add the missing `else` or add a new line before the second `if`");
152+
"to remove this lint, add the missing `else` or add a new line before the second \
153+
`if`");
154154
}
155155
}
156156
}
157157
}
158158

159159
/// Match `if` or `else if` expressions and return the `then` and `else` block.
160-
fn unsugar_if(expr: &ast::Expr) -> Option<(&P<ast::Block>, &Option<P<ast::Expr>>)>{
160+
fn unsugar_if(expr: &ast::Expr) -> Option<(&P<ast::Block>, &Option<P<ast::Expr>>)> {
161161
match expr.node {
162162
ast::ExprKind::If(_, ref then, ref else_) |
163163
ast::ExprKind::IfLet(_, _, ref then, ref else_) => Some((then, else_)),

src/len_zero.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,11 @@ fn check_cmp(cx: &LateContext, span: Span, left: &Expr, right: &Expr, op: &str)
155155
fn check_len_zero(cx: &LateContext, span: Span, name: &Name, args: &[P<Expr>], lit: &Lit, op: &str) {
156156
if let Spanned{node: LitKind::Int(0, _), ..} = *lit {
157157
if name.as_str() == "len" && args.len() == 1 && has_is_empty(cx, &args[0]) {
158-
span_lint_and_then(cx,
159-
LEN_ZERO,
160-
span,
161-
"length comparison to zero",
162-
|db| {
163-
db.span_suggestion(span,
164-
"consider using `is_empty`",
165-
format!("{}{}.is_empty()",
166-
op,
167-
snippet(cx, args[0].span, "_")));
168-
});
158+
span_lint_and_then(cx, LEN_ZERO, span, "length comparison to zero", |db| {
159+
db.span_suggestion(span,
160+
"consider using `is_empty`",
161+
format!("{}{}.is_empty()", op, snippet(cx, args[0].span, "_")));
162+
});
169163
}
170164
}
171165
}

src/loops.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex
370370
span_lint(cx,
371371
NEEDLESS_RANGE_LOOP,
372372
expr.span,
373-
&format!("the loop variable `{}` is used to index `{}`. \
374-
Consider using `for ({}, item) in {}.iter().enumerate(){}{}` or similar iterators",
375-
ident.node.name,
376-
indexed,
377-
ident.node.name,
378-
indexed,
379-
take,
380-
skip));
373+
&format!("the loop variable `{}` is used to index `{}`. Consider using `for ({}, \
374+
item) in {}.iter().enumerate(){}{}` or similar iterators",
375+
ident.node.name,
376+
indexed,
377+
ident.node.name,
378+
indexed,
379+
take,
380+
skip));
381381
} else {
382382
let repl = if starts_at_zero && take.is_empty() {
383383
format!("&{}", indexed)
@@ -390,9 +390,9 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex
390390
expr.span,
391391
&format!("the loop variable `{}` is only used to index `{}`. \
392392
Consider using `for item in {}` or similar iterators",
393-
ident.node.name,
394-
indexed,
395-
repl));
393+
ident.node.name,
394+
indexed,
395+
repl));
396396
}
397397
}
398398
}
@@ -447,9 +447,7 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
447447
"consider using the following if \
448448
you are attempting to iterate \
449449
over this range in reverse",
450-
format!("({}..{}).rev()` ",
451-
stop_snippet,
452-
start_snippet));
450+
format!("({}..{}).rev()` ", stop_snippet, start_snippet));
453451
});
454452
} else if eq {
455453
// if they are equal, it's also problematic - this loop
@@ -744,6 +742,7 @@ impl<'v, 't> Visitor<'v> for VarUsedAfterLoopVisitor<'v, 't> {
744742

745743
/// Return true if the type of expr is one that provides IntoIterator impls
746744
/// for &T and &mut T, such as Vec.
745+
#[cfg_attr(rustfmt, rustfmt_skip)]
747746
fn is_ref_iterable_type(cx: &LateContext, e: &Expr) -> bool {
748747
// no walk_ptrs_ty: calling iter() on a reference can make sense because it
749748
// will allow further borrows afterwards

src/map_clone.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use rustc::lint::*;
22
use rustc_front::hir::*;
33
use utils::{CLONE_PATH, OPTION_PATH};
4-
use utils::{
5-
is_adjusted, match_path, match_trait_method, match_type, snippet, span_help_and_lint,
6-
walk_ptrs_ty, walk_ptrs_ty_depth
7-
};
4+
use utils::{is_adjusted, match_path, match_trait_method, match_type, snippet, span_help_and_lint, walk_ptrs_ty,
5+
walk_ptrs_ty_depth};
86

97
/// **What it does:** This lint checks for mapping clone() over an iterator.
108
///

src/matches.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ impl LateLintPass for MatchPass {
134134
}
135135
}
136136

137+
#[cfg_attr(rustfmt, rustfmt_skip)]
137138
fn check_single_match(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
138139
if arms.len() == 2 &&
139-
arms[0].pats.len() == 1 && arms[0].guard.is_none() &&
140-
arms[1].pats.len() == 1 && arms[1].guard.is_none() {
140+
arms[0].pats.len() == 1 && arms[0].guard.is_none() &&
141+
arms[1].pats.len() == 1 && arms[1].guard.is_none() {
141142
let els = if is_unit_expr(&arms[1].body) {
142143
None
143144
} else if let ExprBlock(_) = arms[1].body.node {
@@ -167,28 +168,28 @@ fn check_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm],
167168
lint,
168169
expr.span,
169170
"you seem to be trying to use match for destructuring a single pattern. \
170-
Consider using `if let`", |db| {
171-
db.span_suggestion(expr.span, "try this",
172-
format!("if let {} = {} {}{}",
173-
snippet(cx, arms[0].pats[0].span, ".."),
174-
snippet(cx, ex.span, ".."),
175-
expr_block(cx, &arms[0].body, None, ".."),
176-
els_str));
177-
});
171+
Consider using `if let`",
172+
|db| {
173+
db.span_suggestion(expr.span,
174+
"try this",
175+
format!("if let {} = {} {}{}",
176+
snippet(cx, arms[0].pats[0].span, ".."),
177+
snippet(cx, ex.span, ".."),
178+
expr_block(cx, &arms[0].body, None, ".."),
179+
els_str));
180+
});
178181
}
179182
}
180183

181184
fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, ty: ty::Ty, els: Option<&Expr>) {
182185
// list of candidate Enums we know will never get any more members
183-
let candidates = &[
184-
(&COW_PATH, "Borrowed"),
185-
(&COW_PATH, "Cow::Borrowed"),
186-
(&COW_PATH, "Cow::Owned"),
187-
(&COW_PATH, "Owned"),
188-
(&OPTION_PATH, "None"),
189-
(&RESULT_PATH, "Err"),
190-
(&RESULT_PATH, "Ok"),
191-
];
186+
let candidates = &[(&COW_PATH, "Borrowed"),
187+
(&COW_PATH, "Cow::Borrowed"),
188+
(&COW_PATH, "Cow::Owned"),
189+
(&COW_PATH, "Owned"),
190+
(&OPTION_PATH, "None"),
191+
(&RESULT_PATH, "Err"),
192+
(&RESULT_PATH, "Ok")];
192193

193194
let path = match arms[1].pats[0].node {
194195
PatKind::TupleStruct(ref path, Some(ref inner)) => {

src/methods.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ fn lint_clone_double_ref(cx: &LateContext, expr: &Expr, arg: &Expr) {
565565
let ty = cx.tcx.expr_ty(arg);
566566
if let ty::TyRef(_, ty::TypeAndMut { ty: ref inner, .. }) = ty.sty {
567567
if let ty::TyRef(..) = inner.sty {
568-
let mut db = span_lint(cx, CLONE_DOUBLE_REF, expr.span,
568+
let mut db = span_lint(cx,
569+
CLONE_DOUBLE_REF,
570+
expr.span,
569571
"using `clone` on a double-reference; \
570572
this will copy the reference instead of cloning \
571573
the inner type");
@@ -583,10 +585,7 @@ fn lint_extend(cx: &LateContext, expr: &Expr, args: &MethodArgs) {
583585
}
584586
let arg_ty = cx.tcx.expr_ty(&args[1]);
585587
if let Some((span, r)) = derefs_to_slice(cx, &args[1], &arg_ty) {
586-
span_lint(cx,
587-
EXTEND_FROM_SLICE,
588-
expr.span,
589-
"use of `extend` to extend a Vec by a slice")
588+
span_lint(cx, EXTEND_FROM_SLICE, expr.span, "use of `extend` to extend a Vec by a slice")
590589
.span_suggestion(expr.span,
591590
"try this",
592591
format!("{}.extend_from_slice({}{})",

0 commit comments

Comments
 (0)