Skip to content

Commit 6a45414

Browse files
committed
Merge branch 'master' of github.com:rust-lang/rust-clippy
2 parents 70b84e5 + 82b2dfb commit 6a45414

File tree

175 files changed

+3285
-2026
lines changed

Some content is hidden

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

175 files changed

+3285
-2026
lines changed

.travis.yml

+15-14
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,36 @@ matrix:
5050
# Builds that are only executed when a PR is r+ed or a try build is started
5151
# We don't want to run these always because they go towards
5252
# the build limit within the Travis rust-lang account.
53+
# The jobs are approximately sorted by execution time
5354
- env: INTEGRATION=rust-lang/cargo
5455
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
55-
- env: INTEGRATION=rust-random/rand
56+
- env: INTEGRATION=rust-lang-nursery/chalk
5657
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
57-
- env: INTEGRATION=rust-lang-nursery/stdsimd
58+
- env: INTEGRATION=rust-lang/rls
5859
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
59-
- env: INTEGRATION=rust-lang/rustfmt
60+
- env: INTEGRATION=Geal/nom
6061
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
61-
- env: INTEGRATION=rust-lang-nursery/futures-rs
62+
- env: INTEGRATION=rust-lang/rustfmt
6263
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
63-
- env: INTEGRATION=rust-lang-nursery/failure
64+
- env: INTEGRATION=hyperium/hyper
6465
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
65-
- env: INTEGRATION=rust-lang-nursery/log
66+
- env: INTEGRATION=bluss/rust-itertools
6667
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
67-
- env: INTEGRATION=rust-lang-nursery/chalk
68+
- env: INTEGRATION=serde-rs/serde
6869
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
69-
- env: INTEGRATION=rust-lang/rls
70+
- env: INTEGRATION=rust-lang-nursery/stdsimd
7071
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
71-
- env: INTEGRATION=chronotope/chrono
72+
- env: INTEGRATION=rust-random/rand
7273
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
73-
- env: INTEGRATION=serde-rs/serde
74+
- env: INTEGRATION=rust-lang-nursery/futures-rs
7475
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
75-
- env: INTEGRATION=Geal/nom
76+
- env: INTEGRATION=Marwes/combine
7677
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
77-
- env: INTEGRATION=hyperium/hyper
78+
- env: INTEGRATION=rust-lang-nursery/failure
7879
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
79-
- env: INTEGRATION=bluss/rust-itertools
80+
- env: INTEGRATION=rust-lang-nursery/log
8081
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
81-
- env: INTEGRATION=Marwes/combine
82+
- env: INTEGRATION=chronotope/chrono
8283
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
8384
allow_failures:
8485
- os: windows

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ All notable changes to this project will be documented in this file.
896896
[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
897897
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
898898
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
899+
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
899900
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
901+
[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map
900902
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
901903
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
902904
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
4848
cargo_metadata = "0.7.1"
4949
compiletest_rs = { version = "0.3.22", features = ["tmp"] }
5050
lazy_static = "1.0"
51-
serde_derive = "1.0"
5251
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
53-
serde = "1.0"
52+
serde = { version = "1.0", features = ["derive"] }
5453
derive-new = "0.5"
5554

5655
# A noop dependency that changes in the Rust repository, it's a bit of a hack.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

10-
[There are 299 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 301 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

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

appveyor.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ environment:
88
- TARGET: x86_64-pc-windows-msvc
99

1010
branches:
11-
# Don't build these branches
12-
except:
13-
# Used by bors
14-
- trying.tmp
15-
- staging.tmp
11+
# Only build AppVeyor on r+, try and the master branch
12+
only:
13+
- auto
14+
- try
15+
- master
1616

1717
install:
1818
- curl -sSf -o rustup-init.exe https://win.rustup.rs/

clippy_lints/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ matches = "0.1.7"
2424
quine-mc_cluskey = "0.2.2"
2525
regex-syntax = "0.6"
2626
semver = "0.9.0"
27-
serde = "1.0"
28-
serde_derive = "1.0"
29-
toml = "0.4"
27+
serde = { version = "1.0", features = ["derive"] }
28+
toml = "0.5"
3029
unicode-normalization = "0.1"
31-
pulldown-cmark = "0.2"
30+
pulldown-cmark = "0.5.0"
3231
url = "1.7.0"
3332
if_chain = "0.1.3"
3433
smallvec = { version = "0.6.5", features = ["union"] }

clippy_lints/src/approx_const.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use crate::utils::span_lint;
2+
use crate::utils::sym;
3+
use lazy_static::lazy_static;
24
use rustc::hir::*;
35
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
46
use rustc::{declare_lint_pass, declare_tool_lint};
57
use std::f64::consts as f64;
6-
use syntax::ast::{FloatTy, Lit, LitKind};
8+
use syntax::ast::{FloatTy, LitKind};
79
use syntax::symbol;
10+
use syntax::symbol::Symbol;
811

912
declare_clippy_lint! {
1013
/// **What it does:** Checks for floating point literals that approximate
@@ -19,10 +22,7 @@ declare_clippy_lint! {
1922
/// actually more precise, please [file a Rust
2023
/// issue](https://github.com/rust-lang/rust/issues).
2124
///
22-
/// **Known problems:** If you happen to have a value that is within 1/8192 of a
23-
/// known constant, but is not *and should not* be the same, this lint will
24-
/// report your value anyway. We have not yet noticed any false positives in
25-
/// code we tested clippy with (this includes servo), but YMMV.
25+
/// **Known problems:** None.
2626
///
2727
/// **Example:**
2828
/// ```rust
@@ -33,38 +33,40 @@ declare_clippy_lint! {
3333
"the approximate of a known float constant (in `std::fXX::consts`)"
3434
}
3535

36+
lazy_static! {
3637
// Tuples are of the form (constant, name, min_digits)
37-
const KNOWN_CONSTS: &[(f64, &str, usize)] = &[
38-
(f64::E, "E", 4),
39-
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
40-
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
41-
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
42-
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
43-
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
44-
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
45-
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
46-
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
47-
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
48-
(f64::LN_10, "LN_10", 5),
49-
(f64::LN_2, "LN_2", 5),
50-
(f64::LOG10_E, "LOG10_E", 5),
51-
(f64::LOG2_E, "LOG2_E", 5),
52-
(f64::PI, "PI", 3),
53-
(f64::SQRT_2, "SQRT_2", 5),
38+
static ref KNOWN_CONSTS: [(f64, Symbol, usize); 16] = [
39+
(f64::E, *sym::E, 4),
40+
(f64::FRAC_1_PI, *sym::FRAC_1_PI, 4),
41+
(f64::FRAC_1_SQRT_2, *sym::FRAC_1_SQRT_2, 5),
42+
(f64::FRAC_2_PI, *sym::FRAC_2_PI, 5),
43+
(f64::FRAC_2_SQRT_PI, *sym::FRAC_2_SQRT_PI, 5),
44+
(f64::FRAC_PI_2, *sym::FRAC_PI_2, 5),
45+
(f64::FRAC_PI_3, *sym::FRAC_PI_3, 5),
46+
(f64::FRAC_PI_4, *sym::FRAC_PI_4, 5),
47+
(f64::FRAC_PI_6, *sym::FRAC_PI_6, 5),
48+
(f64::FRAC_PI_8, *sym::FRAC_PI_8, 5),
49+
(f64::LN_10, *sym::LN_10, 5),
50+
(f64::LN_2, *sym::LN_2, 5),
51+
(f64::LOG10_E, *sym::LOG10_E, 5),
52+
(f64::LOG2_E, *sym::LOG2_E, 5),
53+
(f64::PI, *sym::PI, 3),
54+
(f64::SQRT_2, *sym::SQRT_2, 5),
5455
];
56+
}
5557

5658
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
5759

5860
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
5961
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
6062
if let ExprKind::Lit(lit) = &e.node {
61-
check_lit(cx, lit, e);
63+
check_lit(cx, &lit.node, e);
6264
}
6365
}
6466
}
6567

66-
fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
67-
match lit.node {
68+
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
69+
match *lit {
6870
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
6971
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
7072
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
@@ -75,7 +77,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
7577
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
7678
let s = s.as_str();
7779
if s.parse::<f64>().is_ok() {
78-
for &(constant, name, min_digits) in KNOWN_CONSTS {
80+
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
7981
if is_approx_const(constant, &s, min_digits) {
8082
span_lint(
8183
cx,

clippy_lints/src/assertions_on_constants.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use rustc::{declare_lint_pass, declare_tool_lint};
55
use syntax_pos::Span;
66

77
use crate::consts::{constant, Constant};
8-
use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
8+
use crate::utils::sym;
9+
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
910

1011
declare_clippy_lint! {
1112
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
@@ -34,16 +35,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3435
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
3536
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
3637
let mut is_debug_assert = false;
37-
let debug_assert_not_in_macro = |span: Span| {
38+
let debug_assert_not_in_macro_or_desugar = |span: Span| {
3839
is_debug_assert = true;
3940
// Check that `debug_assert!` itself is not inside a macro
40-
!in_macro(span)
41+
!in_macro_or_desugar(span)
4142
};
4243
if_chain! {
43-
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
44-
if !in_macro(assert_span)
45-
|| is_direct_expn_of(assert_span, "debug_assert")
46-
.map_or(false, debug_assert_not_in_macro);
44+
if let Some(assert_span) = is_direct_expn_of(e.span, *sym::assert);
45+
if !in_macro_or_desugar(assert_span)
46+
|| is_direct_expn_of(assert_span, *sym::debug_assert)
47+
.map_or(false, debug_assert_not_in_macro_or_desugar);
4748
if let ExprKind::Unary(_, ref lit) = e.node;
4849
if let Some(bool_const) = constant(cx, cx.tables, lit);
4950
then {

clippy_lints/src/assign_ops.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::utils::{
99
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
1010
};
1111
use crate::utils::{higher, sugg};
12+
use syntax::symbol::Symbol;
1213

1314
declare_clippy_lint! {
1415
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
@@ -88,8 +89,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8889
$($trait_name:ident),+) => {
8990
match $op {
9091
$(hir::BinOpKind::$trait_name => {
91-
let [krate, module] = crate::utils::paths::OPS_MODULE;
92-
let path = [krate, module, concat!(stringify!($trait_name), "Assign")];
92+
let [krate, module] = *crate::utils::paths::OPS_MODULE;
93+
let ident = {
94+
*crate::utils::sym::assign::$trait_name
95+
};
96+
let path: [Symbol; 3] = [krate, module, ident];
9397
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
9498
trait_id
9599
} else {
@@ -99,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
99103
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
100104
if_chain! {
101105
if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn);
102-
if trait_ref.path.def.def_id() == trait_id;
106+
if trait_ref.path.res.def_id() == trait_id;
103107
then { return; }
104108
}
105109
implements_trait($cx, $ty, trait_id, &[$rty])

0 commit comments

Comments
 (0)