Skip to content

Commit 4d62619

Browse files
ManishearthCentril
authored andcommitted
Update clippy
1 parent 3eaa180 commit 4d62619

Some content is hidden

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

74 files changed

+726
-557
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cache:
1313
- $HOME/.cargo
1414
before_cache:
1515
- cargo install -Z install-upgrade cargo-cache --debug
16+
- find $HOME/.cargo/bin/ ! -type d -exec strip {} \;
1617
- cargo cache --autoclean
1718

1819
env:
@@ -46,7 +47,6 @@ matrix:
4647
fast_finish: true
4748
include:
4849
# Builds that are executed for every PR
49-
- os: osx # run base tests on both platforms
5050
- os: linux
5151
- os: windows
5252
env: CARGO_INCREMENTAL=0 OS_WINDOWS=true
@@ -55,15 +55,17 @@ matrix:
5555
# We don't want to run these always because they go towards
5656
# the build limit within the Travis rust-lang account.
5757
# The jobs are approximately sorted by execution time
58+
- os: osx
59+
if: branch IN (auto, try)
60+
- env: INTEGRATION=rust-lang/rls
61+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
5862
- env: INTEGRATION=rust-lang/cargo
5963
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6064
- env: INTEGRATION=rust-lang-nursery/chalk
6165
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
62-
- env: INTEGRATION=rust-lang/rls
63-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6466
- env: INTEGRATION=Geal/nom
6567
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
66-
# FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4742
68+
# FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4727
6769
#- env: INTEGRATION=rust-lang/rustfmt
6870
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6971
- env: INTEGRATION=hyperium/hyper

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ Released 2018-09-13
996996
[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op
997997
[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence
998998
[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
999+
[`exit`]: https://rust-lang.github.io/rust-clippy/master/index.html#exit
9991000
[`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
10001001
[`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy
10011002
[`explicit_counter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ publish = false
2222
travis-ci = { repository = "rust-lang/rust-clippy" }
2323
appveyor = { repository = "rust-lang/rust-clippy" }
2424

25-
[lib]
26-
name = "clippy"
27-
plugin = true
28-
test = false
29-
3025
[[bin]]
3126
name = "cargo-clippy"
3227
test = false

ci/integration-tests.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@ cargo install --force --debug --path .
1414
echo "Running integration test for crate ${INTEGRATION}"
1515

1616
git clone --depth=1 "https://github.com/${INTEGRATION}.git" checkout
17-
cd checkout || exit 1
17+
cd checkout
1818

19-
# run clippy on a project, try to be verbose and trigger as many warnings as possible for greater coverage
19+
# run clippy on a project, try to be verbose and trigger as many warnings
20+
# as possible for greater coverage
21+
# NOTE: we use `tee` to print any warnings and errors to stdout
22+
# to avoid build timeout in Travis
2023
RUST_BACKTRACE=full \
2124
cargo clippy \
2225
--all-targets \
2326
--all-features \
24-
-- --cap-lints warn -W clippy::pedantic -W clippy::nursery \
25-
2>& 1 \
26-
| tee clippy_output
27+
-- \
28+
--cap-lints warn \
29+
-W clippy::pedantic \
30+
-W clippy::nursery \
31+
2>&1 | tee clippy_output
32+
33+
cargo uninstall clippy
2734

2835
if grep -q "internal compiler error\|query stack during panic\|E0463" clippy_output; then
2936
exit 1

clippy_lints/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ edition = "2018"
1818

1919
[dependencies]
2020
cargo_metadata = "0.9.0"
21+
if_chain = "1.0.0"
2122
itertools = "0.8"
2223
lazy_static = "1.0.2"
2324
matches = "0.1.7"
25+
pulldown-cmark = "0.6.0"
2426
quine-mc_cluskey = "0.2.2"
2527
regex-syntax = "0.6"
26-
semver = "0.9.0"
2728
serde = { version = "1.0", features = ["derive"] }
29+
smallvec = { version = "1", features = ["union"] }
2830
toml = "0.5.3"
2931
unicode-normalization = "0.1"
30-
pulldown-cmark = "0.6.0"
31-
url = { version = "2.1.0", features = ["serde"] } # cargo requires serde feat in its url dep
32-
# see https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864
33-
if_chain = "1.0.0"
34-
smallvec = { version = "0.6.5", features = ["union"] }
32+
semver = "0.9.0"
33+
# NOTE: cargo requires serde feat in its url dep
34+
# see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
35+
url = { version = "2.1.0", features = ["serde"] }
3536

3637
[features]
3738
debugging = []

clippy_lints/src/approx_const.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
55
use std::f64::consts as f64;
6-
use syntax::ast::{FloatTy, LitKind};
6+
use syntax::ast::{FloatTy, LitFloatType, LitKind};
77
use syntax::symbol;
88

99
declare_clippy_lint! {
@@ -62,9 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
6262

6363
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
6464
match *lit {
65-
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
66-
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
67-
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
65+
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
66+
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
67+
FloatTy::F64 => check_known_consts(cx, e, s, "f64"),
68+
},
69+
LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"),
6870
_ => (),
6971
}
7072
}
@@ -97,14 +99,11 @@ fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, mod
9799
fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {
98100
if value.len() <= min_digits {
99101
false
102+
} else if constant.to_string().starts_with(value) {
103+
// The value is a truncated constant
104+
true
100105
} else {
101106
let round_const = format!("{:.*}", value.len() - 2, constant);
102-
103-
let mut trunc_const = constant.to_string();
104-
if trunc_const.len() > value.len() {
105-
trunc_const.truncate(value.len());
106-
}
107-
108-
(value == round_const) || (value == trunc_const)
107+
value == round_const
109108
}
110109
}

clippy_lints/src/attrs.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::ty;
1515
use rustc::{declare_lint_pass, declare_tool_lint};
1616
use rustc_errors::Applicability;
1717
use semver::Version;
18-
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
18+
use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
1919
use syntax::source_map::Span;
2020
use syntax_pos::symbol::Symbol;
2121

@@ -355,7 +355,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
355355
}
356356

357357
fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item) -> bool {
358-
if let ItemKind::Fn(_, _, _, eid) = item.kind {
358+
if let ItemKind::Fn(_, _, eid) = item.kind {
359359
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
360360
} else {
361361
true
@@ -417,11 +417,14 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
417417
}
418418

419419
for attr in attrs {
420-
if attr.is_sugared_doc {
421-
return;
422-
}
420+
let attr_item = if let AttrKind::Normal(ref attr) = attr.kind {
421+
attr
422+
} else {
423+
continue;
424+
};
425+
423426
if attr.style == AttrStyle::Outer {
424-
if attr.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
427+
if attr_item.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
425428
return;
426429
}
427430

clippy_lints/src/consts.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
161161
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
162162
LitKind::Char(c) => Constant::Char(c),
163163
LitKind::Int(n, _) => Constant::Int(n),
164-
LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
165-
LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
166-
LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").kind {
164+
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
165+
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
166+
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
167+
},
168+
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind {
167169
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
168170
ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
169171
_ => bug!(),

0 commit comments

Comments
 (0)