Skip to content

Commit 75ae789

Browse files
committed
Run rustfmt
1 parent a4198c1 commit 75ae789

40 files changed

+356
-291
lines changed

clippy_lints/src/assign_ops.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ impl LateLintPass for AssignOps {
9494
expr.span,
9595
"variable appears on both sides of an assignment operation",
9696
|db| {
97-
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span),
98-
snippet_opt(cx, rhs.span)) {
99-
db.span_suggestion(expr.span,
100-
"replace it with",
101-
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
102-
}
103-
});
97+
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span),
98+
snippet_opt(cx, rhs.span)) {
99+
db.span_suggestion(expr.span,
100+
"replace it with",
101+
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
102+
}
103+
});
104104
};
105105
// lhs op= l op r
106106
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, l) {
@@ -162,13 +162,13 @@ impl LateLintPass for AssignOps {
162162
expr.span,
163163
"manual implementation of an assign operation",
164164
|db| {
165-
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span),
166-
snippet_opt(cx, rhs.span)) {
167-
db.span_suggestion(expr.span,
168-
"replace it with",
169-
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
170-
}
171-
});
165+
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span),
166+
snippet_opt(cx, rhs.span)) {
167+
db.span_suggestion(expr.span,
168+
"replace it with",
169+
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
170+
}
171+
});
172172
}
173173
};
174174
// a = a op b
@@ -182,12 +182,12 @@ impl LateLintPass for AssignOps {
182182
hir::BiBitOr => {
183183
lint(assignee, l);
184184
}
185-
_ => {}
185+
_ => (),
186186
}
187187
}
188188
}
189189
}
190-
_ => {}
190+
_ => (),
191191
}
192192
}
193193
}

clippy_lints/src/attrs.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,23 @@ impl LateLintPass for AttrPass {
121121
}
122122
if let Some(mut sugg) = snippet_opt(cx, attr.span) {
123123
if sugg.len() > 1 {
124-
span_lint_and_then(cx, USELESS_ATTRIBUTE, attr.span,
124+
span_lint_and_then(cx,
125+
USELESS_ATTRIBUTE,
126+
attr.span,
125127
"useless lint attribute",
126128
|db| {
127129
sugg.insert(1, '!');
128130
db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg);
129131
});
130132
}
131133
}
132-
},
133-
_ => {},
134+
}
135+
_ => (),
134136
}
135137
}
136138
}
137-
},
138-
_ => {},
139+
}
140+
_ => (),
139141
}
140142
}
141143

clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
323323
let mut simplified = expr.simplify();
324324
for simple in Bool::Not(Box::new(expr.clone())).simplify() {
325325
match simple {
326-
Bool::Not(_) | Bool::True | Bool::False => {}
326+
Bool::Not(_) | Bool::True | Bool::False => (),
327327
_ => simplified.push(Bool::Not(Box::new(simple.clone()))),
328328
}
329329
let simple_negated = simple_negate(simple);

clippy_lints/src/collapsible_if.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ fn expr_block(block: &ast::Block) -> Option<&ast::Expr> {
151151

152152
if let (Some(stmt), None) = (it.next(), it.next()) {
153153
match stmt.node {
154-
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(expr),
154+
ast::StmtKind::Expr(ref expr) |
155+
ast::StmtKind::Semi(ref expr) => Some(expr),
155156
_ => None,
156157
}
157158
} else {

clippy_lints/src/consts.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ impl PartialOrd for Constant {
151151
(&Constant::Int(l), &Constant::Int(r)) => Some(l.cmp(&r)),
152152
(&Constant::Float(ref ls, _), &Constant::Float(ref rs, _)) => {
153153
match (ls.parse::<f64>(), rs.parse::<f64>()) {
154-
(Ok(ref l), Ok(ref r)) => match (l.partial_cmp(r), l.is_sign_positive() == r.is_sign_positive()) {
155-
// Check for comparison of -0.0 and 0.0
156-
(Some(Ordering::Equal), false) => None,
157-
(x, _) => x
158-
},
154+
(Ok(ref l), Ok(ref r)) => {
155+
match (l.partial_cmp(r), l.is_sign_positive() == r.is_sign_positive()) {
156+
// Check for comparison of -0.0 and 0.0
157+
(Some(Ordering::Equal), false) => None,
158+
(x, _) => x,
159+
}
160+
}
159161
_ => None,
160162
}
161163
}

clippy_lints/src/doc.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,15 @@ pub fn strip_doc_comment_decoration((comment, span): (&str, Span)) -> Vec<(&str,
7272
}
7373

7474
if comment.starts_with("/*") {
75-
return comment[3..comment.len() - 2].lines().map(|line| {
76-
let offset = line.as_ptr() as usize - comment.as_ptr() as usize;
77-
debug_assert_eq!(offset as u32 as usize, offset);
78-
79-
(
80-
line,
81-
Span {
82-
lo: span.lo + BytePos(offset as u32),
83-
..span
84-
}
85-
)
86-
}).collect();
75+
return comment[3..comment.len() - 2]
76+
.lines()
77+
.map(|line| {
78+
let offset = line.as_ptr() as usize - comment.as_ptr() as usize;
79+
debug_assert_eq!(offset as u32 as usize, offset);
80+
81+
(line, Span { lo: span.lo + BytePos(offset as u32), ..span })
82+
})
83+
.collect();
8784
}
8885

8986
panic!("not a doc-comment: {}", comment);

clippy_lints/src/entry.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ impl LateLintPass for HashMapLint {
7878
}
7979
}
8080

81-
fn check_cond<'a, 'tcx, 'b>(cx: &'a LateContext<'a, 'tcx>, check: &'b Expr) -> Option<(&'static str, &'b Expr, &'b Expr)> {
81+
fn check_cond<'a, 'tcx, 'b>(cx: &'a LateContext<'a, 'tcx>, check: &'b Expr)
82+
-> Option<(&'static str, &'b Expr, &'b Expr)> {
8283
if_let_chain! {[
8384
let ExprMethodCall(ref name, _, ref params) = check.node,
8485
params.len() >= 2,

clippy_lints/src/enum_variants.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ pub struct EnumVariantNames {
7878

7979
impl EnumVariantNames {
8080
pub fn new(threshold: u64) -> EnumVariantNames {
81-
EnumVariantNames { modules: Vec::new(), threshold: threshold }
81+
EnumVariantNames {
82+
modules: Vec::new(),
83+
threshold: threshold,
84+
}
8285
}
8386
}
8487

@@ -200,7 +203,10 @@ impl EarlyLintPass for EnumVariantNames {
200203
if !mod_camel.is_empty() {
201204
if mod_name == &item_name {
202205
if let ItemKind::Mod(..) = item.node {
203-
span_lint(cx, MODULE_INCEPTION, item.span, "module has the same name as its containing module");
206+
span_lint(cx,
207+
MODULE_INCEPTION,
208+
item.span,
209+
"module has the same name as its containing module");
204210
}
205211
}
206212
if item.vis == Visibility::Public {

clippy_lints/src/escape.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn is_non_trait_box(ty: ty::Ty) -> bool {
4747
}
4848
}
4949

50-
struct EscapeDelegate<'a, 'tcx: 'a+'gcx, 'gcx: 'a> {
50+
struct EscapeDelegate<'a, 'tcx: 'a + 'gcx, 'gcx: 'a> {
5151
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
5252
set: NodeSet,
5353
infcx: &'a InferCtxt<'a, 'gcx, 'gcx>,
@@ -91,7 +91,7 @@ impl LateLintPass for Pass {
9191
}
9292
}
9393

94-
impl<'a, 'tcx: 'a+'gcx, 'gcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx, 'gcx> {
94+
impl<'a, 'tcx: 'a + 'gcx, 'gcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx, 'gcx> {
9595
fn consume(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, mode: ConsumeMode) {
9696
if let Categorization::Local(lid) = cmt.cat {
9797
if self.set.contains(&lid) {
@@ -188,7 +188,7 @@ impl<'a, 'tcx: 'a+'gcx, 'gcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx, 'g
188188
fn mutate(&mut self, _: NodeId, _: Span, _: cmt<'tcx>, _: MutateMode) {}
189189
}
190190

191-
impl<'a, 'tcx: 'a+'gcx, 'gcx: 'a> EscapeDelegate<'a, 'tcx, 'gcx> {
191+
impl<'a, 'tcx: 'a + 'gcx, 'gcx: 'a> EscapeDelegate<'a, 'tcx, 'gcx> {
192192
fn is_large_box(&self, ty: ty::Ty<'gcx>) -> bool {
193193
// Large types need to be boxed to avoid stack
194194
// overflows.
@@ -200,7 +200,7 @@ impl<'a, 'tcx: 'a+'gcx, 'gcx: 'a> EscapeDelegate<'a, 'tcx, 'gcx> {
200200
} else {
201201
false
202202
}
203-
},
203+
}
204204
_ => false,
205205
}
206206
}

clippy_lints/src/eval_order_dependence.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ impl LateLintPass for EvalOrderDependence {
6060
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
6161
// Find a write to a local variable.
6262
match expr.node {
63-
ExprAssign(ref lhs, _) | ExprAssignOp(_, ref lhs, _) => {
63+
ExprAssign(ref lhs, _) |
64+
ExprAssignOp(_, ref lhs, _) => {
6465
if let ExprPath(None, ref path) = lhs.node {
6566
if path.segments.len() == 1 {
6667
let var = cx.tcx.expect_def(lhs.id).def_id();
@@ -74,19 +75,20 @@ impl LateLintPass for EvalOrderDependence {
7475
}
7576
}
7677
}
77-
_ => {}
78+
_ => (),
7879
}
7980
}
8081
fn check_stmt(&mut self, cx: &LateContext, stmt: &Stmt) {
8182
match stmt.node {
82-
StmtExpr(ref e, _) | StmtSemi(ref e, _) => DivergenceVisitor(cx).maybe_walk_expr(e),
83+
StmtExpr(ref e, _) |
84+
StmtSemi(ref e, _) => DivergenceVisitor(cx).maybe_walk_expr(e),
8385
StmtDecl(ref d, _) => {
8486
if let DeclLocal(ref local) = d.node {
8587
if let Local { init: Some(ref e), .. } = **local {
8688
DivergenceVisitor(cx).visit_expr(e);
8789
}
8890
}
89-
},
91+
}
9092
}
9193
}
9294
}
@@ -96,7 +98,7 @@ struct DivergenceVisitor<'a, 'tcx: 'a>(&'a LateContext<'a, 'tcx>);
9698
impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
9799
fn maybe_walk_expr(&mut self, e: &Expr) {
98100
match e.node {
99-
ExprClosure(..) => {},
101+
ExprClosure(..) => (),
100102
ExprMatch(ref e, ref arms, _) => {
101103
self.visit_expr(e);
102104
for arm in arms {
@@ -111,12 +113,7 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
111113
}
112114
}
113115
fn report_diverging_sub_expr(&mut self, e: &Expr) {
114-
span_lint(
115-
self.0,
116-
DIVERGING_SUB_EXPRESSION,
117-
e.span,
118-
"sub-expression diverges",
119-
);
116+
span_lint(self.0, DIVERGING_SUB_EXPRESSION, e.span, "sub-expression diverges");
120117
}
121118
}
122119

@@ -126,13 +123,17 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DivergenceVisitor<'a, 'tcx> {
126123
ExprAgain(_) |
127124
ExprBreak(_) |
128125
ExprRet(_) => self.report_diverging_sub_expr(e),
129-
ExprCall(ref func, _) => match self.0.tcx.expr_ty(func).sty {
130-
ty::TyFnDef(_, _, fn_ty) |
131-
ty::TyFnPtr(fn_ty) => if let ty::TyNever = self.0.tcx.erase_late_bound_regions(&fn_ty.sig).output.sty {
132-
self.report_diverging_sub_expr(e);
133-
},
134-
_ => {},
135-
},
126+
ExprCall(ref func, _) => {
127+
match self.0.tcx.expr_ty(func).sty {
128+
ty::TyFnDef(_, _, fn_ty) |
129+
ty::TyFnPtr(fn_ty) => {
130+
if let ty::TyNever = self.0.tcx.erase_late_bound_regions(&fn_ty.sig).output.sty {
131+
self.report_diverging_sub_expr(e);
132+
}
133+
}
134+
_ => (),
135+
}
136+
}
136137
ExprMethodCall(..) => {
137138
let method_call = ty::MethodCall::expr(e.id);
138139
let borrowed_table = self.0.tcx.tables.borrow();
@@ -141,10 +142,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DivergenceVisitor<'a, 'tcx> {
141142
if let ty::TyNever = self.0.tcx.erase_late_bound_regions(&result_ty).sty {
142143
self.report_diverging_sub_expr(e);
143144
}
144-
},
145+
}
145146
_ => {
146147
// do not lint expressions referencing objects of type `!`, as that required a diverging expression to begin with
147-
},
148+
}
148149
}
149150
self.maybe_walk_expr(e);
150151
}
@@ -187,12 +188,12 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor) {
187188
map::Node::NodeItem(_) => {
188189
// We reached the top of the function, stop.
189190
break;
190-
},
191-
_ => { StopEarly::KeepGoing }
191+
}
192+
_ => StopEarly::KeepGoing,
192193
};
193194
match stop_early {
194195
StopEarly::Stop => break,
195-
StopEarly::KeepGoing => {},
196+
StopEarly::KeepGoing => (),
196197
}
197198

198199
cur_id = parent_id;
@@ -207,7 +208,7 @@ enum StopEarly {
207208
Stop,
208209
}
209210

210-
fn check_expr<'v, 't>(vis: & mut ReadVisitor<'v, 't>, expr: &'v Expr) -> StopEarly {
211+
fn check_expr<'v, 't>(vis: &mut ReadVisitor<'v, 't>, expr: &'v Expr) -> StopEarly {
211212
if expr.id == vis.last_expr.id {
212213
return StopEarly::KeepGoing;
213214
}
@@ -248,7 +249,7 @@ fn check_expr<'v, 't>(vis: & mut ReadVisitor<'v, 't>, expr: &'v Expr) -> StopEar
248249
}
249250
// All other expressions either have only one child or strictly
250251
// sequence the evaluation order of their sub-expressions.
251-
_ => {}
252+
_ => (),
252253
}
253254

254255
vis.last_expr = expr;
@@ -327,7 +328,7 @@ impl<'v, 't> Visitor<'v> for ReadVisitor<'v, 't> {
327328
ExprAddrOf(_, _) => {
328329
return;
329330
}
330-
_ => {}
331+
_ => ()
331332
}
332333

333334
walk_expr(self, expr);

clippy_lints/src/functions.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ impl LintPass for Functions {
6969
}
7070

7171
impl LateLintPass for Functions {
72-
fn check_fn(&mut self, cx: &LateContext, kind: intravisit::FnKind, decl: &hir::FnDecl, block: &hir::Block, span: Span, nodeid: ast::NodeId) {
72+
fn check_fn(&mut self, cx: &LateContext, kind: intravisit::FnKind, decl: &hir::FnDecl, block: &hir::Block,
73+
span: Span, nodeid: ast::NodeId) {
7374
use rustc::hir::map::Node::*;
7475

7576
let is_impl = if let Some(NodeItem(item)) = cx.tcx.map.find(cx.tcx.map.get_parent_node(nodeid)) {
@@ -90,7 +91,7 @@ impl LateLintPass for Functions {
9091
match kind {
9192
hir::intravisit::FnKind::Method(_, &hir::MethodSig { abi: Abi::Rust, .. }, _, _) |
9293
hir::intravisit::FnKind::ItemFn(_, _, _, _, Abi::Rust, _, _) => self.check_arg_number(cx, decl, span),
93-
_ => {},
94+
_ => (),
9495
}
9596
}
9697

@@ -122,7 +123,8 @@ impl Functions {
122123
}
123124
}
124125

125-
fn check_raw_ptr(&self, cx: &LateContext, unsafety: hir::Unsafety, decl: &hir::FnDecl, block: &hir::Block, nodeid: ast::NodeId) {
126+
fn check_raw_ptr(&self, cx: &LateContext, unsafety: hir::Unsafety, decl: &hir::FnDecl, block: &hir::Block,
127+
nodeid: ast::NodeId) {
126128
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) {
127129
let raw_ptrs = decl.inputs.iter().filter_map(|arg| raw_ptr_arg(cx, arg)).collect::<HashSet<_>>();
128130

0 commit comments

Comments
 (0)