Skip to content

Commit 3c6503e

Browse files
committed
Format code
1 parent e4b954e commit 3c6503e

File tree

11 files changed

+134
-129
lines changed

11 files changed

+134
-129
lines changed

build.rs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
//! This build script was originally taken from the Rocket web framework:
1414
//! https://github.com/SergioBenitez/Rocket
1515
16-
extern crate rustc_version;
1716
extern crate ansi_term;
17+
extern crate rustc_version;
1818

19-
use std::env;
20-
use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta};
2119
use ansi_term::Colour::Red;
20+
use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta};
21+
use std::env;
2222

2323
fn main() {
2424
check_rustc_version();
@@ -31,77 +31,81 @@ fn main() {
3131

3232
fn check_rustc_version() {
3333
let string = include_str!("min_version.txt");
34-
let min_version_meta = version_meta_for(string)
35-
.expect("Could not parse version string in min_version.txt");
36-
let current_version_meta = version_meta()
37-
.expect("Could not retrieve current rustc version information from ENV");
34+
let min_version_meta = version_meta_for(string).expect("Could not parse version string in min_version.txt");
35+
let current_version_meta = version_meta().expect("Could not retrieve current rustc version information from ENV");
3836

3937
let min_version = min_version_meta.clone().semver;
40-
let min_date_str = min_version_meta.clone().commit_date
38+
let min_date_str = min_version_meta
39+
.clone()
40+
.commit_date
4141
.expect("min_version.txt does not contain a rustc commit date");
4242

4343
// Dev channel (rustc built from git) does not have any date or commit information in rustc -vV
4444
// `current_version_meta.commit_date` would crash, so we return early here.
4545
if current_version_meta.channel == Channel::Dev {
46-
return
46+
return;
4747
}
4848

4949
let current_version = current_version_meta.clone().semver;
50-
let current_date_str = current_version_meta.clone().commit_date
50+
let current_date_str = current_version_meta
51+
.clone()
52+
.commit_date
5153
.expect("current rustc version information does not contain a rustc commit date");
5254

5355
let print_version_err = |version: &Version, date: &str| {
54-
eprintln!("> {} {}. {} {}.\n",
55-
"Installed rustc version is:",
56-
format!("{} ({})", version, date),
57-
"Minimum required rustc version:",
58-
format!("{} ({})", min_version, min_date_str));
56+
eprintln!(
57+
"> {} {}. {} {}.\n",
58+
"Installed rustc version is:",
59+
format!("{} ({})", version, date),
60+
"Minimum required rustc version:",
61+
format!("{} ({})", min_version, min_date_str)
62+
);
5963
};
6064

6165
if !correct_channel(&current_version_meta) {
62-
eprintln!("\n{} {}",
63-
Red.bold().paint("error:"),
64-
"clippy requires a nightly version of Rust.");
66+
eprintln!(
67+
"\n{} {}",
68+
Red.bold().paint("error:"),
69+
"clippy requires a nightly version of Rust."
70+
);
6571
print_version_err(&current_version, &*current_date_str);
66-
eprintln!("{}{}{}",
67-
"See the README (",
68-
"https://github.com/rust-lang-nursery/rust-clippy#usage",
69-
") for more information.");
72+
eprintln!(
73+
"{}{}{}",
74+
"See the README (", "https://github.com/rust-lang-nursery/rust-clippy#usage", ") for more information."
75+
);
7076
panic!("Aborting compilation due to incompatible compiler.")
7177
}
7278

7379
let current_date = str_to_ymd(&current_date_str).unwrap();
7480
let min_date = str_to_ymd(&min_date_str).unwrap();
7581

7682
if current_date < min_date {
77-
eprintln!("\n{} {}",
78-
Red.bold().paint("error:"),
79-
"clippy does not support this version of rustc nightly.");
80-
eprintln!("> {}{}{}",
81-
"Use `",
82-
"rustup update",
83-
"` or your preferred method to update Rust.");
83+
eprintln!(
84+
"\n{} {}",
85+
Red.bold().paint("error:"),
86+
"clippy does not support this version of rustc nightly."
87+
);
88+
eprintln!(
89+
"> {}{}{}",
90+
"Use `", "rustup update", "` or your preferred method to update Rust."
91+
);
8492
print_version_err(&current_version, &*current_date_str);
8593
panic!("Aborting compilation due to incompatible compiler.")
8694
}
8795
}
8896

8997
fn correct_channel(version_meta: &VersionMeta) -> bool {
9098
match version_meta.channel {
91-
Channel::Stable | Channel::Beta => {
92-
false
93-
},
94-
Channel::Nightly | Channel::Dev => {
95-
true
96-
}
99+
Channel::Stable | Channel::Beta => false,
100+
Channel::Nightly | Channel::Dev => true,
97101
}
98102
}
99103

100104
/// Convert a string of %Y-%m-%d to a single u32 maintaining ordering.
101105
fn str_to_ymd(ymd: &str) -> Option<u32> {
102106
let ymd: Vec<u32> = ymd.split("-").filter_map(|s| s.parse::<u32>().ok()).collect();
103107
if ymd.len() != 3 {
104-
return None
108+
return None;
105109
}
106110

107111
let (y, m, d) = (ymd[0], ymd[1], ymd[2]);

clippy_lints/src/approx_const.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc::lint::*;
21
use rustc::hir::*;
2+
use rustc::lint::*;
33
use std::f64::consts as f64;
44
use syntax::ast::{FloatTy, Lit, LitKind};
55
use syntax::symbol;
@@ -90,8 +90,7 @@ fn check_known_consts(cx: &LateContext, e: &Expr, s: &symbol::Symbol, module: &s
9090
&format!(
9191
"approximate value of `{}::consts::{}` found. \
9292
Consider using it directly",
93-
module,
94-
&name
93+
module, &name
9594
),
9695
);
9796
return;

clippy_lints/src/arithmetic.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
5757
match expr.node {
5858
hir::ExprBinary(ref op, ref l, ref r) => {
5959
match op.node {
60-
hir::BiAnd |
61-
hir::BiOr |
62-
hir::BiBitAnd |
63-
hir::BiBitOr |
64-
hir::BiBitXor |
65-
hir::BiShl |
66-
hir::BiShr |
67-
hir::BiEq |
68-
hir::BiLt |
69-
hir::BiLe |
70-
hir::BiNe |
71-
hir::BiGe |
72-
hir::BiGt => return,
60+
hir::BiAnd
61+
| hir::BiOr
62+
| hir::BiBitAnd
63+
| hir::BiBitOr
64+
| hir::BiBitXor
65+
| hir::BiShl
66+
| hir::BiShr
67+
| hir::BiEq
68+
| hir::BiLt
69+
| hir::BiLe
70+
| hir::BiNe
71+
| hir::BiGe
72+
| hir::BiGt => return,
7373
_ => (),
7474
}
7575
let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));

clippy_lints/src/array_indexing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use consts::{constant, Constant};
2+
use rustc::hir;
13
use rustc::lint::*;
24
use rustc::ty;
3-
use rustc::hir;
45
use syntax::ast::RangeLimits;
5-
use utils::{self, higher};
66
use utils::higher::Range;
7-
use consts::{constant, Constant};
7+
use utils::{self, higher};
88

99
/// **What it does:** Checks for out of bounds array indexing with a constant
1010
/// index.

clippy_lints/src/assign_ops.rs

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,28 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
9595
MISREFACTORED_ASSIGN_OP,
9696
expr.span,
9797
"variable appears on both sides of an assignment operation",
98-
|db| if let (Some(snip_a), Some(snip_r)) =
99-
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span))
100-
{
101-
let a = &sugg::Sugg::hir(cx, assignee, "..");
102-
let r = &sugg::Sugg::hir(cx, rhs, "..");
103-
let long = format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
104-
db.span_suggestion(
105-
expr.span,
106-
&format!("Did you mean {} = {} {} {} or {}? Consider replacing it with",
107-
snip_a, snip_a, op.node.as_str(), snip_r,
108-
long),
109-
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r)
110-
);
111-
db.span_suggestion(
112-
expr.span,
113-
"or",
114-
long
115-
);
98+
|db| {
99+
if let (Some(snip_a), Some(snip_r)) =
100+
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span))
101+
{
102+
let a = &sugg::Sugg::hir(cx, assignee, "..");
103+
let r = &sugg::Sugg::hir(cx, rhs, "..");
104+
let long =
105+
format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
106+
db.span_suggestion(
107+
expr.span,
108+
&format!(
109+
"Did you mean {} = {} {} {} or {}? Consider replacing it with",
110+
snip_a,
111+
snip_a,
112+
op.node.as_str(),
113+
snip_r,
114+
long
115+
),
116+
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
117+
);
118+
db.span_suggestion(expr.span, "or", long);
119+
}
116120
},
117121
);
118122
};
@@ -189,14 +193,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
189193
ASSIGN_OP_PATTERN,
190194
expr.span,
191195
"manual implementation of an assign operation",
192-
|db| if let (Some(snip_a), Some(snip_r)) =
193-
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
194-
{
195-
db.span_suggestion(
196-
expr.span,
197-
"replace it with",
198-
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
199-
);
196+
|db| {
197+
if let (Some(snip_a), Some(snip_r)) =
198+
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
199+
{
200+
db.span_suggestion(
201+
expr.span,
202+
"replace it with",
203+
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
204+
);
205+
}
200206
},
201207
);
202208
}
@@ -205,7 +211,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
205211
let mut visitor = ExprVisitor {
206212
assignee,
207213
counter: 0,
208-
cx
214+
cx,
209215
};
210216

211217
walk_expr(&mut visitor, e);
@@ -218,13 +224,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
218224
// a = b commutative_op a
219225
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) {
220226
match op.node {
221-
hir::BiAdd |
222-
hir::BiMul |
223-
hir::BiAnd |
224-
hir::BiOr |
225-
hir::BiBitXor |
226-
hir::BiBitAnd |
227-
hir::BiBitOr => {
227+
hir::BiAdd
228+
| hir::BiMul
229+
| hir::BiAnd
230+
| hir::BiOr
231+
| hir::BiBitXor
232+
| hir::BiBitAnd
233+
| hir::BiBitOr => {
228234
lint(assignee, l);
229235
},
230236
_ => {},

clippy_lints/src/attrs.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
//! checks for attributes
22
33
use reexport::*;
4-
use rustc::lint::*;
54
use rustc::hir::*;
5+
use rustc::lint::*;
66
use rustc::ty::{self, TyCtxt};
77
use semver::Version;
8-
use syntax::ast::{Attribute, AttrStyle, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
8+
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
99
use syntax::codemap::Span;
10-
use utils::{in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_then, without_block_comments};
10+
use utils::{
11+
in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_then,
12+
without_block_comments,
13+
};
1114

1215
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
1316
/// unless the annotated function is empty or simply panics.
@@ -118,7 +121,12 @@ pub struct AttrPass;
118121

119122
impl LintPass for AttrPass {
120123
fn get_lints(&self) -> LintArray {
121-
lint_array!(INLINE_ALWAYS, DEPRECATED_SEMVER, USELESS_ATTRIBUTE, EMPTY_LINE_AFTER_OUTER_ATTR)
124+
lint_array!(
125+
INLINE_ALWAYS,
126+
DEPRECATED_SEMVER,
127+
USELESS_ATTRIBUTE,
128+
EMPTY_LINE_AFTER_OUTER_ATTR
129+
)
122130
}
123131
}
124132

@@ -170,11 +178,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
170178
"useless lint attribute",
171179
|db| {
172180
sugg = sugg.replacen("#[", "#![", 1);
173-
db.span_suggestion(
174-
line_span,
175-
"if you just forgot a `!`, use",
176-
sugg,
177-
);
181+
db.span_suggestion(line_span, "if you just forgot a `!`, use", sugg);
178182
},
179183
);
180184
}
@@ -234,10 +238,7 @@ fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> b
234238
StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
235239
}
236240
} else {
237-
block
238-
.expr
239-
.as_ref()
240-
.map_or(false, |e| is_relevant_expr(tcx, tables, e))
241+
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
241242
}
242243
}
243244

0 commit comments

Comments
 (0)