Skip to content

Commit 9c48a2c

Browse files
author
Michael Wright
committed
Merge branch 'master' into fix-4727
2 parents e3c1aea + 4192dbe commit 9c48a2c

Some content is hidden

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

55 files changed

+417
-330
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ matrix:
5656
# We don't want to run these always because they go towards
5757
# the build limit within the Travis rust-lang account.
5858
# The jobs are approximately sorted by execution time
59+
- env: INTEGRATION=rust-lang/rls
60+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
5961
- env: INTEGRATION=rust-lang/cargo
6062
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6163
- env: INTEGRATION=rust-lang-nursery/chalk
6264
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
63-
- env: INTEGRATION=rust-lang/rls
64-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6565
- env: INTEGRATION=Geal/nom
6666
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
67-
# FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4742
67+
# FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4727
6868
#- env: INTEGRATION=rust-lang/rustfmt
6969
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7070
- env: INTEGRATION=hyperium/hyper
@@ -90,7 +90,6 @@ matrix:
9090
allow_failures:
9191
- os: windows
9292
env: CARGO_INCREMENTAL=0 OS_WINDOWS=true
93-
- env: INTEGRATION=rust-lang-nursery/stdsimd
9493

9594
before_script:
9695
- |

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

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: 6 additions & 4 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
}

clippy_lints/src/attrs.rs

Lines changed: 8 additions & 5 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

@@ -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!(),

clippy_lints/src/deprecated_lints.rs

Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,129 +4,137 @@ macro_rules! declare_deprecated_lint {
44
}
55
}
66

7-
/// **What it does:** Nothing. This lint has been deprecated.
8-
///
9-
/// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend
10-
/// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011.
117
declare_deprecated_lint! {
8+
/// **What it does:** Nothing. This lint has been deprecated.
9+
///
10+
/// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend
11+
/// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011.
1212
pub SHOULD_ASSERT_EQ,
1313
"`assert!()` will be more flexible with RFC 2011"
1414
}
1515

16-
/// **What it does:** Nothing. This lint has been deprecated.
17-
///
18-
/// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than
19-
/// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true.
2016
declare_deprecated_lint! {
17+
/// **What it does:** Nothing. This lint has been deprecated.
18+
///
19+
/// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than
20+
/// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true.
2121
pub EXTEND_FROM_SLICE,
2222
"`.extend_from_slice(_)` is a faster way to extend a Vec by a slice"
2323
}
2424

25-
/// **What it does:** Nothing. This lint has been deprecated.
26-
///
27-
/// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's
28-
/// an infinite iterator, which is better expressed by `iter::repeat`,
29-
/// but the method has been removed for `Iterator::step_by` which panics
30-
/// if given a zero
3125
declare_deprecated_lint! {
26+
/// **What it does:** Nothing. This lint has been deprecated.
27+
///
28+
/// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's
29+
/// an infinite iterator, which is better expressed by `iter::repeat`,
30+
/// but the method has been removed for `Iterator::step_by` which panics
31+
/// if given a zero
3232
pub RANGE_STEP_BY_ZERO,
3333
"`iterator.step_by(0)` panics nowadays"
3434
}
3535

36-
/// **What it does:** Nothing. This lint has been deprecated.
37-
///
38-
/// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good
39-
/// stable alternatives. `Vec::as_slice` has now been stabilized.
4036
declare_deprecated_lint! {
37+
/// **What it does:** Nothing. This lint has been deprecated.
38+
///
39+
/// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good
40+
/// stable alternatives. `Vec::as_slice` has now been stabilized.
4141
pub UNSTABLE_AS_SLICE,
4242
"`Vec::as_slice` has been stabilized in 1.7"
4343
}
4444

45-
46-
/// **What it does:** Nothing. This lint has been deprecated.
47-
///
48-
/// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good
49-
/// stable alternatives. `Vec::as_mut_slice` has now been stabilized.
5045
declare_deprecated_lint! {
46+
/// **What it does:** Nothing. This lint has been deprecated.
47+
///
48+
/// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good
49+
/// stable alternatives. `Vec::as_mut_slice` has now been stabilized.
5150
pub UNSTABLE_AS_MUT_SLICE,
5251
"`Vec::as_mut_slice` has been stabilized in 1.7"
5352
}
5453

55-
/// **What it does:** Nothing. This lint has been deprecated.
56-
///
57-
/// **Deprecation reason:** This used to check for `.to_string()` method calls on values
58-
/// of type `&str`. This is not unidiomatic and with specialization coming, `to_string` could be
59-
/// specialized to be as efficient as `to_owned`.
6054
declare_deprecated_lint! {
55+
/// **What it does:** Nothing. This lint has been deprecated.
56+
///
57+
/// **Deprecation reason:** This used to check for `.to_string()` method calls on values
58+
/// of type `&str`. This is not unidiomatic and with specialization coming, `to_string` could be
59+
/// specialized to be as efficient as `to_owned`.
6160
pub STR_TO_STRING,
6261
"using `str::to_string` is common even today and specialization will likely happen soon"
6362
}
6463

65-
/// **What it does:** Nothing. This lint has been deprecated.
66-
///
67-
/// **Deprecation reason:** This used to check for `.to_string()` method calls on values
68-
/// of type `String`. This is not unidiomatic and with specialization coming, `to_string` could be
69-
/// specialized to be as efficient as `clone`.
7064
declare_deprecated_lint! {
65+
/// **What it does:** Nothing. This lint has been deprecated.
66+
///
67+
/// **Deprecation reason:** This used to check for `.to_string()` method calls on values
68+
/// of type `String`. This is not unidiomatic and with specialization coming, `to_string` could be
69+
/// specialized to be as efficient as `clone`.
7170
pub STRING_TO_STRING,
7271
"using `string::to_string` is common even today and specialization will likely happen soon"
7372
}
7473

75-
/// **What it does:** Nothing. This lint has been deprecated.
76-
///
77-
/// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting
78-
/// between non-pointer types of differing alignment is well-defined behavior (it's semantically
79-
/// equivalent to a memcpy). This lint has thus been refactored into two separate lints:
80-
/// cast_ptr_alignment and transmute_ptr_to_ptr.
8174
declare_deprecated_lint! {
75+
/// **What it does:** Nothing. This lint has been deprecated.
76+
///
77+
/// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting
78+
/// between non-pointer types of differing alignment is well-defined behavior (it's semantically
79+
/// equivalent to a memcpy). This lint has thus been refactored into two separate lints:
80+
/// cast_ptr_alignment and transmute_ptr_to_ptr.
8281
pub MISALIGNED_TRANSMUTE,
8382
"this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr"
8483
}
8584

86-
/// **What it does:** Nothing. This lint has been deprecated.
87-
///
88-
/// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy.
89-
/// Additionally, compound assignment operators may be overloaded separately from their non-assigning
90-
/// counterparts, so this lint may suggest a change in behavior or the code may not compile.
9185
declare_deprecated_lint! {
86+
/// **What it does:** Nothing. This lint has been deprecated.
87+
///
88+
/// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy.
89+
/// Additionally, compound assignment operators may be overloaded separately from their non-assigning
90+
/// counterparts, so this lint may suggest a change in behavior or the code may not compile.
9291
pub ASSIGN_OPS,
9392
"using compound assignment operators (e.g., `+=`) is harmless"
9493
}
9594

96-
/// **What it does:** Nothing. This lint has been deprecated.
97-
///
98-
/// **Deprecation reason:** The original rule will only lint for `if let`. After
99-
/// making it support to lint `match`, naming as `if let` is not suitable for it.
100-
/// So, this lint is deprecated.
10195
declare_deprecated_lint! {
96+
/// **What it does:** Nothing. This lint has been deprecated.
97+
///
98+
/// **Deprecation reason:** The original rule will only lint for `if let`. After
99+
/// making it support to lint `match`, naming as `if let` is not suitable for it.
100+
/// So, this lint is deprecated.
102101
pub IF_LET_REDUNDANT_PATTERN_MATCHING,
103102
"this lint has been changed to redundant_pattern_matching"
104103
}
105104

106-
/// **What it does:** Nothing. This lint has been deprecated.
107-
///
108-
/// **Deprecation reason:** This lint used to suggest replacing `let mut vec =
109-
/// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The
110-
/// replacement has very different performance characteristics so the lint is
111-
/// deprecated.
112105
declare_deprecated_lint! {
106+
/// **What it does:** Nothing. This lint has been deprecated.
107+
///
108+
/// **Deprecation reason:** This lint used to suggest replacing `let mut vec =
109+
/// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The
110+
/// replacement has very different performance characteristics so the lint is
111+
/// deprecated.
113112
pub UNSAFE_VECTOR_INITIALIZATION,
114113
"the replacement suggested by this lint had substantially different behavior"
115114
}
116115

117-
/// **What it does:** Nothing. This lint has been deprecated.
118-
///
119-
/// **Deprecation reason:** This lint has been superseded by the warn-by-default
120-
/// `invalid_value` rustc lint.
121116
declare_deprecated_lint! {
117+
/// **What it does:** Nothing. This lint has been deprecated.
118+
///
119+
/// **Deprecation reason:** This lint has been superseded by the warn-by-default
120+
/// `invalid_value` rustc lint.
122121
pub INVALID_REF,
123122
"superseded by rustc lint `invalid_value`"
124123
}
125124

126-
/// **What it does:** Nothing. This lint has been deprecated.
127-
///
128-
/// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc.
129125
declare_deprecated_lint! {
126+
/// **What it does:** Nothing. This lint has been deprecated.
127+
///
128+
/// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc.
130129
pub UNUSED_COLLECT,
131130
"`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint"
132131
}
132+
133+
declare_deprecated_lint! {
134+
/// **What it does:** Nothing. This lint has been deprecated.
135+
///
136+
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
137+
/// `array_into_iter`.
138+
pub INTO_ITER_ON_ARRAY,
139+
"this lint has been uplifted to rustc and is now called `array_into_iter`"
140+
}

clippy_lints/src/doc.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_tool_lint, impl_lint_pass};
77
use rustc_data_structures::fx::FxHashSet;
88
use std::ops::Range;
9-
use syntax::ast::Attribute;
9+
use syntax::ast::{AttrKind, Attribute};
1010
use syntax::source_map::{BytePos, Span};
1111
use syntax_pos::Pos;
1212
use url::Url;
@@ -247,13 +247,11 @@ pub fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String
247247
let mut spans = vec![];
248248

249249
for attr in attrs {
250-
if attr.is_sugared_doc {
251-
if let Some(ref current) = attr.value_str() {
252-
let current = current.to_string();
253-
let (current, current_spans) = strip_doc_comment_decoration(&current, attr.span);
254-
spans.extend_from_slice(&current_spans);
255-
doc.push_str(&current);
256-
}
250+
if let AttrKind::DocComment(ref comment) = attr.kind {
251+
let comment = comment.to_string();
252+
let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span);
253+
spans.extend_from_slice(&current_spans);
254+
doc.push_str(&comment);
257255
} else if attr.check_name(sym!(doc)) {
258256
// ignore mix of sugared and non-sugared doc
259257
return true; // don't trigger the safety check

clippy_lints/src/excessive_precision.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
4343
let ty = cx.tables.expr_ty(expr);
4444
if let ty::Float(fty) = ty.kind;
4545
if let hir::ExprKind::Lit(ref lit) = expr.kind;
46-
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
46+
if let LitKind::Float(sym, _) = lit.node;
4747
if let Some(sugg) = Self::check(sym, fty);
4848
then {
4949
span_lint_and_sugg(

0 commit comments

Comments
 (0)