Skip to content

Commit d5c40bb

Browse files
committed
Fixed some code in clippy to pass the new lint.
1 parent 0ecdc00 commit d5c40bb

File tree

12 files changed

+508
-567
lines changed

12 files changed

+508
-567
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,22 @@ declare_lint! {
3333
}
3434

3535
// Tuples are of the form (constant, name, min_digits)
36-
const KNOWN_CONSTS: &'static [(f64, &'static str, usize)] = &[
37-
(f64::E, "E", 4),
38-
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
39-
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
40-
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
41-
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
42-
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
43-
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
44-
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
45-
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
46-
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
47-
(f64::LN_10, "LN_10", 5),
48-
(f64::LN_2, "LN_2", 5),
49-
(f64::LOG10_E, "LOG10_E", 5),
50-
(f64::LOG2_E, "LOG2_E", 5),
51-
(f64::PI, "PI", 3),
52-
(f64::SQRT_2, "SQRT_2", 5),
53-
];
36+
const KNOWN_CONSTS: &[(f64, &str, usize)] = &[(f64::E, "E", 4),
37+
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
38+
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
39+
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
40+
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
41+
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
42+
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
43+
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
44+
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
45+
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
46+
(f64::LN_10, "LN_10", 5),
47+
(f64::LN_2, "LN_2", 5),
48+
(f64::LOG10_E, "LOG10_E", 5),
49+
(f64::LOG2_E, "LOG2_E", 5),
50+
(f64::PI, "PI", 3),
51+
(f64::SQRT_2, "SQRT_2", 5)];
5452

5553
#[derive(Copy, Clone)]
5654
pub struct Pass;
@@ -83,17 +81,12 @@ fn check_known_consts(cx: &LateContext, e: &Expr, s: &symbol::Symbol, module: &s
8381
if s.parse::<f64>().is_ok() {
8482
for &(constant, name, min_digits) in KNOWN_CONSTS {
8583
if is_approx_const(constant, &s, min_digits) {
86-
span_lint(
87-
cx,
88-
APPROX_CONSTANT,
89-
e.span,
90-
&format!(
91-
"approximate value of `{}::consts::{}` found. \
92-
Consider using it directly",
93-
module,
94-
&name
95-
),
96-
);
84+
span_lint(cx,
85+
APPROX_CONSTANT,
86+
e.span,
87+
&format!("approximate value of `{}::consts::{}` found. Consider using it directly",
88+
module,
89+
&name));
9790
return;
9891
}
9992
}

clippy_lints/src/block_in_if_condition.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
7171
}
7272
}
7373

74-
const BRACED_EXPR_MESSAGE: &'static str = "omit braces around single expression condition";
75-
const COMPLEX_BLOCK_MESSAGE: &'static str = "in an 'if' condition, avoid complex blocks or closures with blocks; \
74+
const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition";
75+
const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks or closures with blocks; \
7676
instead, move the block or closure higher and bind it with a 'let'";
7777

7878
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
@@ -87,34 +87,29 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
8787
if in_macro(expr.span) || differing_macro_contexts(expr.span, ex.span) {
8888
return;
8989
}
90-
span_help_and_lint(
91-
cx,
92-
BLOCK_IN_IF_CONDITION_EXPR,
93-
check.span,
94-
BRACED_EXPR_MESSAGE,
95-
&format!("try\nif {} {} ... ",
90+
span_help_and_lint(cx,
91+
BLOCK_IN_IF_CONDITION_EXPR,
92+
check.span,
93+
BRACED_EXPR_MESSAGE,
94+
&format!("try\nif {} {} ... ",
9695
snippet_block(cx, ex.span, ".."),
97-
snippet_block(cx, then.span, "..")),
98-
);
96+
snippet_block(cx, then.span, "..")));
9997
}
10098
} else {
101-
let span = block
102-
.expr
99+
let span = block.expr
103100
.as_ref()
104101
.map_or_else(|| block.stmts[0].span, |e| e.span);
105102
if in_macro(span) || differing_macro_contexts(expr.span, span) {
106103
return;
107104
}
108105
// move block higher
109-
span_help_and_lint(
110-
cx,
111-
BLOCK_IN_IF_CONDITION_STMT,
112-
check.span,
113-
COMPLEX_BLOCK_MESSAGE,
114-
&format!("try\nlet res = {};\nif res {} ... ",
106+
span_help_and_lint(cx,
107+
BLOCK_IN_IF_CONDITION_STMT,
108+
check.span,
109+
COMPLEX_BLOCK_MESSAGE,
110+
&format!("try\nlet res = {};\nif res {} ... ",
115111
snippet_block(cx, block.span, ".."),
116-
snippet_block(cx, then.span, "..")),
117-
);
112+
snippet_block(cx, then.span, "..")));
118113
}
119114
}
120115
} else {

clippy_lints/src/const_static_lifetime.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl StaticConst {
3737
match ty.node {
3838
// Be carefull of nested structures (arrays and tuples)
3939
TyKind::Array(ref ty, _) => {
40-
println!("array");
4140
self.visit_type(&*ty, cx);
4241
},
4342
TyKind::Tup(ref tup) => {
@@ -63,7 +62,7 @@ impl StaticConst {
6362
self.visit_type(&*borrow_type.ty, cx);
6463
},
6564
TyKind::Slice(ref ty) => {
66-
self.visit_type(&ty, cx);
65+
self.visit_type(ty, cx);
6766
},
6867
_ => {},
6968
}

clippy_lints/src/doc.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ pub struct Doc {
3838

3939
impl Doc {
4040
pub fn new(valid_idents: Vec<String>) -> Self {
41-
Self {
42-
valid_idents: valid_idents,
43-
}
41+
Self { valid_idents: valid_idents }
4442
}
4543
}
4644

@@ -88,18 +86,13 @@ impl<'a> Iterator for Parser<'a> {
8886
#[allow(cast_possible_truncation)]
8987
pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
9088
// one-line comments lose their prefix
91-
const ONELINERS: &'static [&'static str] = &["///!", "///", "//!", "//"];
89+
const ONELINERS: &[&str] = &["///!", "///", "//!", "//"];
9290
for prefix in ONELINERS {
9391
if comment.starts_with(*prefix) {
9492
let doc = &comment[prefix.len()..];
9593
let mut doc = doc.to_owned();
9694
doc.push('\n');
97-
return (
98-
doc.to_owned(),
99-
vec![
100-
(doc.len(), span.with_lo(span.lo() + BytePos(prefix.len() as u32))),
101-
],
102-
);
95+
return (doc.to_owned(), vec![(doc.len(), span.with_lo(span.lo() + BytePos(prefix.len() as u32)))]);
10396
}
10497
}
10598

@@ -190,7 +183,7 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
190183
cx: &EarlyContext,
191184
valid_idents: &[String],
192185
docs: Events,
193-
spans: &[(usize, Span)],
186+
spans: &[(usize, Span)]
194187
) {
195188
use pulldown_cmark::Event::*;
196189
use pulldown_cmark::Tag::*;
@@ -200,15 +193,19 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
200193

201194
for (offset, event) in docs {
202195
match event {
203-
Start(CodeBlock(_)) | Start(Code) => in_code = true,
204-
End(CodeBlock(_)) | End(Code) => in_code = false,
196+
Start(CodeBlock(_)) |
197+
Start(Code) => in_code = true,
198+
End(CodeBlock(_)) |
199+
End(Code) => in_code = false,
205200
Start(Link(link, _)) => in_link = Some(link),
206201
End(Link(_, _)) => in_link = None,
207202
Start(_tag) | End(_tag) => (), // We don't care about other tags
208-
Html(_html) | InlineHtml(_html) => (), // HTML is weird, just ignore it
203+
Html(_html) |
204+
InlineHtml(_html) => (), // HTML is weird, just ignore it
209205
SoftBreak => (),
210206
HardBreak => (),
211-
FootnoteReference(text) | Text(text) => {
207+
FootnoteReference(text) |
208+
Text(text) => {
212209
if Some(&text) == in_link.as_ref() {
213210
// Probably a link of the form `<http://example.com>`
214211
// Which are represented as a link to "http://example.com" with
@@ -247,11 +244,9 @@ fn check_text(cx: &EarlyContext, valid_idents: &[String], text: &str, span: Span
247244

248245
// Adjust for the current word
249246
let offset = word.as_ptr() as usize - text.as_ptr() as usize;
250-
let span = Span::new(
251-
span.lo() + BytePos::from_usize(offset),
252-
span.lo() + BytePos::from_usize(offset + word.len()),
253-
span.ctxt(),
254-
);
247+
let span = Span::new(span.lo() + BytePos::from_usize(offset),
248+
span.lo() + BytePos::from_usize(offset + word.len()),
249+
span.ctxt());
255250

256251
check_word(cx, word, span);
257252
}
@@ -274,7 +269,7 @@ fn check_word(cx: &EarlyContext, word: &str, span: Span) {
274269
};
275270

276271
s.chars().all(char::is_alphanumeric) && s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1 &&
277-
s.chars().filter(|&c| c.is_lowercase()).take(1).count() > 0
272+
s.chars().filter(|&c| c.is_lowercase()).take(1).count() > 0
278273
}
279274

280275
fn has_underscore(s: &str) -> bool {
@@ -294,11 +289,9 @@ fn check_word(cx: &EarlyContext, word: &str, span: Span) {
294289
}
295290

296291
if has_underscore(word) || word.contains("::") || is_camel_case(word) {
297-
span_lint(
298-
cx,
299-
DOC_MARKDOWN,
300-
span,
301-
&format!("you should put `{}` between ticks in the documentation", word),
302-
);
292+
span_lint(cx,
293+
DOC_MARKDOWN,
294+
span,
295+
&format!("you should put `{}` between ticks in the documentation", word));
303296
}
304297
}

0 commit comments

Comments
 (0)