Skip to content

Commit 7030259

Browse files
committed
Merge branch 'master' of github.com:Manishearth/rust-clippy into fold_any
2 parents a324a2b + 9a2c50f commit 7030259

File tree

201 files changed

+1429
-558
lines changed

Some content is hidden

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

201 files changed

+1429
-558
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ rust: nightly
44

55
os:
66
- linux
7-
- osx
7+
# - osx # doesn't even start atm. Not sure what travis is up to. Disabling to reduce the noise
88

99
sudo: false
1010

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.180
5+
* Rustup to *rustc 1.25.0-nightly (3f92e8d89 2018-01-14)*
6+
47
## 0.0.179
58
* Rustup to *rustc 1.25.0-nightly (61452e506 2018-01-09)*
69

@@ -580,6 +583,7 @@ All notable changes to this project will be documented in this file.
580583
[`ineffective_bit_mask`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ineffective_bit_mask
581584
[`infinite_iter`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#infinite_iter
582585
[`inline_always`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#inline_always
586+
[`inline_fn_without_body`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#inline_fn_without_body
583587
[`int_plus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#int_plus_one
584588
[`integer_arithmetic`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#integer_arithmetic
585589
[`invalid_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_ref
@@ -670,6 +674,7 @@ All notable changes to this project will be documented in this file.
670674
[`redundant_closure_call`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_closure_call
671675
[`redundant_pattern`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_pattern
672676
[`regex_macro`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#regex_macro
677+
[`replace_consts`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#replace_consts
673678
[`result_map_unwrap_or_else`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
674679
[`result_unwrap_used`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#result_unwrap_used
675680
[`reverse_range_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#reverse_range_loop

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.179"
3+
version = "0.0.180"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",
@@ -37,13 +37,13 @@ path = "src/driver.rs"
3737

3838
[dependencies]
3939
# begin automatic update
40-
clippy_lints = { version = "0.0.179", path = "clippy_lints" }
40+
clippy_lints = { version = "0.0.180", path = "clippy_lints" }
4141
# end automatic update
4242
cargo_metadata = "0.2"
4343
regex = "0.2"
4444

4545
[dev-dependencies]
46-
compiletest_rs = "0.3"
46+
compiletest_rs = "0.3.5"
4747
duct = "0.8.2"
4848
lazy_static = "1.0"
4949
serde_derive = "1.0"

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.0.179"
4+
version = "0.0.180"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <[email protected]>",

clippy_lints/src/const_static_lifetime.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use syntax::ast::{Item, ItemKind, Ty, TyKind};
22
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
3-
use utils::{in_macro, span_lint_and_then};
3+
use utils::{in_macro, snippet, span_lint_and_then};
44

55
/// **What it does:** Checks for constants with an explicit `'static` lifetime.
66
///
@@ -51,14 +51,15 @@ impl StaticConst {
5151
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) |
5252
TyKind::Tup(..) => {
5353
if lifetime.ident.name == "'static" {
54-
let mut sug: String = String::new();
54+
let snip = snippet(cx, borrow_type.ty.span, "<type>");
55+
let sugg = format!("&{}", snip);
5556
span_lint_and_then(
5657
cx,
5758
CONST_STATIC_LIFETIME,
5859
lifetime.span,
5960
"Constants have by default a `'static` lifetime",
6061
|db| {
61-
db.span_suggestion(lifetime.span, "consider removing `'static`", sug);
62+
db.span_suggestion(ty.span, "consider removing `'static`", sugg);
6263
},
6364
);
6465
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//! lint on if expressions with an else if, but without a final else branch
2+
3+
use rustc::lint::*;
4+
use syntax::ast::*;
5+
6+
use utils::{in_external_macro, span_lint_and_sugg};
7+
8+
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
9+
/// but without a final `else` branch.
10+
///
11+
/// **Why is this bad?** Some coding guidelines require this (e.g. MISRA-C:2004 Rule 14.10).
12+
///
13+
/// **Known problems:** None.
14+
///
15+
/// **Example:**
16+
/// ```rust
17+
/// if x.is_positive() {
18+
/// a();
19+
/// } else if x.is_negative() {
20+
/// b();
21+
/// }
22+
/// ```
23+
///
24+
/// Could be written:
25+
///
26+
/// ```rust
27+
/// if x.is_positive() {
28+
/// a();
29+
/// } else if x.is_negative() {
30+
/// b();
31+
/// } else {
32+
/// // we don't care about zero
33+
/// }
34+
/// ```
35+
declare_restriction_lint! {
36+
pub ELSE_IF_WITHOUT_ELSE,
37+
"if expression with an `else if`, but without a final `else` branch"
38+
}
39+
40+
#[derive(Copy, Clone)]
41+
pub struct ElseIfWithoutElse;
42+
43+
impl LintPass for ElseIfWithoutElse {
44+
fn get_lints(&self) -> LintArray {
45+
lint_array!(ELSE_IF_WITHOUT_ELSE)
46+
}
47+
}
48+
49+
impl EarlyLintPass for ElseIfWithoutElse {
50+
fn check_expr(&mut self, cx: &EarlyContext, mut item: &Expr) {
51+
if in_external_macro(cx, item.span) {
52+
return;
53+
}
54+
55+
while let ExprKind::If(_, _, Some(ref els)) = item.node {
56+
if let ExprKind::If(_, _, None) = els.node {
57+
span_lint_and_sugg(
58+
cx,
59+
ELSE_IF_WITHOUT_ELSE,
60+
els.span,
61+
"if expression with an `else if`, but without a final `else`",
62+
"add an `else` block here",
63+
"".to_string()
64+
);
65+
}
66+
67+
item = els;
68+
}
69+
}
70+
}

clippy_lints/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
8686
use rustc::hir::map::Node::*;
8787

8888
let is_impl = if let Some(NodeItem(item)) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(nodeid)) {
89-
matches!(item.node, hir::ItemImpl(_, _, _, _, Some(_), _, _) | hir::ItemAutoImpl(..))
89+
matches!(item.node, hir::ItemImpl(_, _, _, _, Some(_), _, _))
9090
} else {
9191
false
9292
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! checks for `#[inline]` on trait methods without bodies
2+
3+
use rustc::lint::*;
4+
use rustc::hir::*;
5+
use syntax::ast::{Attribute, Name};
6+
use utils::span_lint_and_then;
7+
use utils::sugg::DiagnosticBuilderExt;
8+
9+
/// **What it does:** Checks for `#[inline]` on trait methods without bodies
10+
///
11+
/// **Why is this bad?** Only implementations of trait methods may be inlined.
12+
/// The inline attribute is ignored for trait methods without bodies.
13+
///
14+
/// **Known problems:** None.
15+
///
16+
/// **Example:**
17+
/// ```rust
18+
/// trait Animal {
19+
/// #[inline]
20+
/// fn name(&self) -> &'static str;
21+
/// }
22+
/// ```
23+
declare_lint! {
24+
pub INLINE_FN_WITHOUT_BODY,
25+
Warn,
26+
"use of `#[inline]` on trait methods without bodies"
27+
}
28+
29+
#[derive(Copy, Clone)]
30+
pub struct Pass;
31+
32+
impl LintPass for Pass {
33+
fn get_lints(&self) -> LintArray {
34+
lint_array!(INLINE_FN_WITHOUT_BODY)
35+
}
36+
}
37+
38+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
39+
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
40+
match item.node {
41+
TraitItemKind::Method(_, TraitMethod::Required(_)) => {
42+
check_attrs(cx, &item.name, &item.attrs);
43+
},
44+
_ => {},
45+
}
46+
}
47+
}
48+
49+
fn check_attrs(cx: &LateContext, name: &Name, attrs: &[Attribute]) {
50+
for attr in attrs {
51+
if attr.name().map_or(true, |n| n != "inline") {
52+
continue;
53+
}
54+
55+
span_lint_and_then(
56+
cx,
57+
INLINE_FN_WITHOUT_BODY,
58+
attr.span,
59+
&format!("use of `#[inline]` on trait method `{}` which has no body", name),
60+
|db| {
61+
db.suggest_remove_item(cx, attr.span, "remove");
62+
},
63+
);
64+
}
65+
}

clippy_lints/src/is_unit_expr.rs

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)