Skip to content

Commit a90e548

Browse files
committed
Update Clippy
1 parent c4fde5a commit a90e548

File tree

171 files changed

+2471
-1302
lines changed

Some content is hidden

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

171 files changed

+2471
-1302
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ indent_size = 4
1414

1515
[*.md]
1616
trim_trailing_whitespace = false
17+
18+
[*.yml]
19+
indent_size = 2

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ env:
2626

2727
before_install:
2828
- export CARGO_TARGET_DIR="$TRAVIS_BUILD_DIR/target"
29-
- curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly --profile=minimal
29+
- |
30+
case "$TRAVIS_OS_NAME" in
31+
linux ) HOST=x86_64-unknown-linux-gnu;;
32+
osx ) HOST=x86_64-apple-darwin;;
33+
windows ) HOST=x86_64-pc-windows-msvc;;
34+
esac
35+
- curl -sSL https://sh.rustup.rs | sh -s -- -y --default-host="$HOST" --default-toolchain=nightly --profile=minimal
3036
- export PATH="$HOME/.cargo/bin:$PATH"
3137
install:
3238
- |
3339
if [[ -z ${INTEGRATION} ]]; then
3440
if ! rustup component add rustfmt; then
35-
cargo install --git https://github.com/rust-lang/rustfmt --bin rustfmt
41+
TARGET=$(rustc -Vv | awk '/host/{print $2}')
42+
NIGHTLY=$(curl -s "https://rust-lang.github.io/rustup-components-history/${TARGET}/rustfmt")
43+
curl -sSL "https://static.rust-lang.org/dist/${NIGHTLY}/rustfmt-nightly-${TARGET}.tar.xz" | \
44+
tar -xJf - --strip-components=3 -C ~/.cargo/bin
45+
rm -rf ~/.cargo/bin/doc
3646
fi
3747
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
3848
. $HOME/.nvm/nvm.sh

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ Released 2018-09-13
11341134
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
11351135
[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array
11361136
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
1137+
[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering
11371138
[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref
11381139
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
11391140
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
@@ -1360,6 +1361,7 @@ Released 2018-09-13
13601361
[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
13611362
[`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies
13621363
[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm
1364+
[`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns
13631365
[`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal
13641366
[`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline
13651367
[`writeln_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#writeln_empty_string

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 344 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 346 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/assign_ops.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
use crate::utils::{
2+
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
3+
};
4+
use crate::utils::{higher, sugg};
15
use if_chain::if_chain;
26
use rustc::declare_lint_pass;
3-
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
7+
use rustc::hir::map::Map;
48
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
59
use rustc_errors::Applicability;
610
use rustc_hir as hir;
11+
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
712
use rustc_session::declare_tool_lint;
813

9-
use crate::utils::{
10-
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
11-
};
12-
use crate::utils::{higher, sugg};
13-
1414
declare_clippy_lint! {
1515
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
1616
/// patterns.
@@ -209,7 +209,7 @@ fn lint_misrefactored_assign_op(
209209
db.span_suggestion(
210210
expr.span,
211211
&format!(
212-
"Did you mean {} = {} {} {} or {}? Consider replacing it with",
212+
"Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
213213
snip_a,
214214
snip_a,
215215
op.node.as_str(),
@@ -246,14 +246,16 @@ struct ExprVisitor<'a, 'tcx> {
246246
}
247247

248248
impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
249+
type Map = Map<'tcx>;
250+
249251
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
250252
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
251253
self.counter += 1;
252254
}
253255

254256
walk_expr(self, expr);
255257
}
256-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
258+
fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
257259
NestedVisitorMap::None
258260
}
259261
}

clippy_lints/src/atomic_ordering.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use crate::utils::{match_def_path, span_help_and_lint};
2+
use if_chain::if_chain;
3+
use rustc::declare_lint_pass;
4+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5+
use rustc::ty;
6+
use rustc_hir::def_id::DefId;
7+
use rustc_hir::*;
8+
use rustc_session::declare_tool_lint;
9+
10+
declare_clippy_lint! {
11+
/// **What it does:** Checks for usage of invalid atomic
12+
/// ordering in Atomic*::{load, store} calls.
13+
///
14+
/// **Why is this bad?** Using an invalid atomic ordering
15+
/// will cause a panic at run-time.
16+
///
17+
/// **Known problems:** None.
18+
///
19+
/// **Example:**
20+
/// ```rust,no_run
21+
/// # use std::sync::atomic::{AtomicBool, Ordering};
22+
///
23+
/// let x = AtomicBool::new(true);
24+
///
25+
/// let _ = x.load(Ordering::Release);
26+
/// let _ = x.load(Ordering::AcqRel);
27+
///
28+
/// x.store(false, Ordering::Acquire);
29+
/// x.store(false, Ordering::AcqRel);
30+
/// ```
31+
pub INVALID_ATOMIC_ORDERING,
32+
correctness,
33+
"usage of invalid atomic ordering in atomic load/store calls"
34+
}
35+
36+
declare_lint_pass!(AtomicOrdering => [INVALID_ATOMIC_ORDERING]);
37+
38+
const ATOMIC_TYPES: [&str; 12] = [
39+
"AtomicBool",
40+
"AtomicI8",
41+
"AtomicI16",
42+
"AtomicI32",
43+
"AtomicI64",
44+
"AtomicIsize",
45+
"AtomicPtr",
46+
"AtomicU8",
47+
"AtomicU16",
48+
"AtomicU32",
49+
"AtomicU64",
50+
"AtomicUsize",
51+
];
52+
53+
fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
54+
if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables.expr_ty(expr).kind {
55+
ATOMIC_TYPES
56+
.iter()
57+
.any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty]))
58+
} else {
59+
false
60+
}
61+
}
62+
63+
fn match_ordering_def_path(cx: &LateContext<'_, '_>, did: DefId, orderings: &[&str]) -> bool {
64+
orderings
65+
.iter()
66+
.any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering]))
67+
}
68+
69+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AtomicOrdering {
70+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
71+
if_chain! {
72+
if let ExprKind::MethodCall(ref method_path, _, args) = &expr.kind;
73+
let method = method_path.ident.name.as_str();
74+
if type_is_atomic(cx, &args[0]);
75+
if method == "load" || method == "store";
76+
let ordering_arg = if method == "load" { &args[1] } else { &args[2] };
77+
if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind;
78+
if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id();
79+
then {
80+
if method == "load" &&
81+
match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) {
82+
span_help_and_lint(
83+
cx,
84+
INVALID_ATOMIC_ORDERING,
85+
ordering_arg.span,
86+
"atomic loads cannot have `Release` and `AcqRel` ordering",
87+
"consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`"
88+
);
89+
} else if method == "store" &&
90+
match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) {
91+
span_help_and_lint(
92+
cx,
93+
INVALID_ATOMIC_ORDERING,
94+
ordering_arg.span,
95+
"atomic stores cannot have `Acquire` and `AcqRel` ordering",
96+
"consider using ordering modes `Release`, `SeqCst` or `Relaxed`"
97+
);
98+
}
99+
}
100+
}
101+
}
102+
}

clippy_lints/src/attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ declare_clippy_lint! {
187187
/// ```
188188
pub DEPRECATED_CFG_ATTR,
189189
complexity,
190-
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
190+
"usage of `cfg_attr(rustfmt)` instead of tool attributes"
191191
}
192192

193193
declare_lint_pass!(Attributes => [
@@ -449,7 +449,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
449449
EMPTY_LINE_AFTER_OUTER_ATTR,
450450
begin_of_attr_to_item,
451451
"Found an empty line after an outer attribute. \
452-
Perhaps you forgot to add a '!' to make it an inner attribute?",
452+
Perhaps you forgot to add a `!` to make it an inner attribute?",
453453
);
454454
}
455455
}
@@ -520,7 +520,7 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
520520
cx,
521521
DEPRECATED_CFG_ATTR,
522522
attr.span,
523-
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
523+
"`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes",
524524
"use",
525525
"#[rustfmt::skip]".to_string(),
526526
Applicability::MachineApplicable,

clippy_lints/src/block_in_if_condition.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::utils::*;
22
use matches::matches;
33
use rustc::declare_lint_pass;
4-
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
4+
use rustc::hir::map::Map;
55
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
6+
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
67
use rustc_hir::*;
78
use rustc_session::declare_tool_lint;
89

@@ -51,6 +52,8 @@ struct ExVisitor<'a, 'tcx> {
5152
}
5253

5354
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
55+
type Map = Map<'tcx>;
56+
5457
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
5558
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
5659
let body = self.cx.tcx.hir().body(eid);
@@ -62,14 +65,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
6265
}
6366
walk_expr(self, expr);
6467
}
65-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
68+
fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
6669
NestedVisitorMap::None
6770
}
6871
}
6972

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

7477
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
7578
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {

clippy_lints/src/booleans.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use crate::utils::{
44
};
55
use if_chain::if_chain;
66
use rustc::declare_lint_pass;
7-
use rustc::hir::intravisit;
8-
use rustc::hir::intravisit::*;
7+
use rustc::hir::map::Map;
98
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
109
use rustc_errors::Applicability;
10+
use rustc_hir::intravisit;
11+
use rustc_hir::intravisit::*;
1112
use rustc_hir::*;
1213
use rustc_session::declare_tool_lint;
1314
use rustc_span::source_map::Span;
@@ -438,6 +439,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
438439
}
439440

440441
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
442+
type Map = Map<'tcx>;
443+
441444
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
442445
if in_macro(e.span) {
443446
return;
@@ -456,7 +459,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
456459
_ => walk_expr(self, e),
457460
}
458461
}
459-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
462+
fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
460463
NestedVisitorMap::None
461464
}
462465
}
@@ -471,6 +474,8 @@ struct NotSimplificationVisitor<'a, 'tcx> {
471474
}
472475

473476
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
477+
type Map = Map<'tcx>;
478+
474479
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
475480
if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind {
476481
if let Some(suggestion) = simplify_not(self.cx, inner) {
@@ -488,7 +493,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
488493

489494
walk_expr(self, expr);
490495
}
491-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
496+
fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
492497
NestedVisitorMap::None
493498
}
494499
}

clippy_lints/src/cognitive_complexity.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! calculate cognitive complexity and warn about overly complex functions
22
3-
use rustc::hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor};
3+
use rustc::hir::map::Map;
44
use rustc::impl_lint_pass;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
6+
use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor};
67
use rustc_hir::*;
78
use rustc_session::declare_tool_lint;
89
use rustc_span::source_map::Span;
@@ -141,6 +142,8 @@ struct CCHelper {
141142
}
142143

143144
impl<'tcx> Visitor<'tcx> for CCHelper {
145+
type Map = Map<'tcx>;
146+
144147
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
145148
walk_expr(self, e);
146149
match e.kind {
@@ -154,7 +157,7 @@ impl<'tcx> Visitor<'tcx> for CCHelper {
154157
_ => {},
155158
}
156159
}
157-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
160+
fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
158161
NestedVisitorMap::None
159162
}
160163
}

0 commit comments

Comments
 (0)