From 94e35510aedb6248e3066300acb41efd2c8699c9 Mon Sep 17 00:00:00 2001 From: Evan Stoll Date: Wed, 30 Oct 2019 21:05:23 -0400 Subject: [PATCH 01/28] Fix #4748 - Deprecated lints don't expand - Move doc comments inside of declare_deprecated_lint macros so that they are picked up by lintlib.py --- clippy_lints/src/deprecated_lints.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 97ae9c780888..ec349a23760c 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -4,85 +4,85 @@ macro_rules! declare_deprecated_lint { } } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend /// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011. -declare_deprecated_lint! { pub SHOULD_ASSERT_EQ, "`assert!()` will be more flexible with RFC 2011" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than /// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true. -declare_deprecated_lint! { pub EXTEND_FROM_SLICE, "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's /// an infinite iterator, which is better expressed by `iter::repeat`, /// but the method has been removed for `Iterator::step_by` which panics /// if given a zero -declare_deprecated_lint! { pub RANGE_STEP_BY_ZERO, "`iterator.step_by(0)` panics nowadays" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good /// stable alternatives. `Vec::as_slice` has now been stabilized. -declare_deprecated_lint! { pub UNSTABLE_AS_SLICE, "`Vec::as_slice` has been stabilized in 1.7" } - +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good /// stable alternatives. `Vec::as_mut_slice` has now been stabilized. -declare_deprecated_lint! { pub UNSTABLE_AS_MUT_SLICE, "`Vec::as_mut_slice` has been stabilized in 1.7" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This used to check for `.to_string()` method calls on values /// of type `&str`. This is not unidiomatic and with specialization coming, `to_string` could be /// specialized to be as efficient as `to_owned`. -declare_deprecated_lint! { pub STR_TO_STRING, "using `str::to_string` is common even today and specialization will likely happen soon" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This used to check for `.to_string()` method calls on values /// of type `String`. This is not unidiomatic and with specialization coming, `to_string` could be /// specialized to be as efficient as `clone`. -declare_deprecated_lint! { pub STRING_TO_STRING, "using `string::to_string` is common even today and specialization will likely happen soon" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting /// between non-pointer types of differing alignment is well-defined behavior (it's semantically /// equivalent to a memcpy). This lint has thus been refactored into two separate lints: /// cast_ptr_alignment and transmute_ptr_to_ptr. -declare_deprecated_lint! { pub MISALIGNED_TRANSMUTE, "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy. @@ -93,40 +93,40 @@ declare_deprecated_lint! { "using compound assignment operators (e.g., `+=`) is harmless" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** The original rule will only lint for `if let`. After /// making it support to lint `match`, naming as `if let` is not suitable for it. /// So, this lint is deprecated. -declare_deprecated_lint! { pub IF_LET_REDUNDANT_PATTERN_MATCHING, "this lint has been changed to redundant_pattern_matching" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This lint used to suggest replacing `let mut vec = /// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The /// replacement has very different performance characteristics so the lint is /// deprecated. -declare_deprecated_lint! { pub UNSAFE_VECTOR_INITIALIZATION, "the replacement suggested by this lint had substantially different behavior" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This lint has been superseded by the warn-by-default /// `invalid_value` rustc lint. -declare_deprecated_lint! { pub INVALID_REF, "superseded by rustc lint `invalid_value`" } +declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc. -declare_deprecated_lint! { pub UNUSED_COLLECT, "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint" } From 4e78547e6f65e2b5bdbdd46592f6882d6cd33628 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 31 Oct 2019 09:13:08 +0200 Subject: [PATCH 02/28] `DecimalLiteralRepresentation` simplification Remove recalculation of literal value. --- clippy_lints/src/literal_representation.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index badd2237073c..09ef000994f2 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -509,17 +509,12 @@ impl DecimalLiteralRepresentation { fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { // Lint integral literals. if_chain! { - if let LitKind::Int(..) = lit.kind; + if let LitKind::Int(val, _) = lit.kind; if let Some(src) = snippet_opt(cx, lit.span); if let Some(firstch) = src.chars().next(); if char::to_digit(firstch, 10).is_some(); let digit_info = DigitInfo::new(&src, false); if digit_info.radix == Radix::Decimal; - if let Ok(val) = digit_info.digits - .chars() - .filter(|&c| c != '_') - .collect::() - .parse::(); if val >= u128::from(self.threshold); then { let hex = format!("{:#X}", val); From 1acea2e4fc231e4dd6229b6e0869f29e79b40edc Mon Sep 17 00:00:00 2001 From: Evan Stoll Date: Sat, 2 Nov 2019 14:09:41 -0400 Subject: [PATCH 03/28] deprecated_lints: remove extraneous `declare_deprecated_lint` --- clippy_lints/src/deprecated_lints.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index ec349a23760c..5156749e8657 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -82,7 +82,6 @@ declare_deprecated_lint! { "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr" } -declare_deprecated_lint! { /// **What it does:** Nothing. This lint has been deprecated. /// /// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy. From 9a2c968f9ff9826fb46e8b37036f904f303e064b Mon Sep 17 00:00:00 2001 From: Evan Stoll Date: Sat, 2 Nov 2019 14:10:59 -0400 Subject: [PATCH 04/28] deprecated_lints: align doc comment indents with `pub LINT_NAME` --- clippy_lints/src/deprecated_lints.rs | 112 +++++++++++++-------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 5156749e8657..a7640b8e8ced 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -5,79 +5,79 @@ macro_rules! declare_deprecated_lint { } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend -/// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend + /// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011. pub SHOULD_ASSERT_EQ, "`assert!()` will be more flexible with RFC 2011" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than -/// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than + /// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true. pub EXTEND_FROM_SLICE, "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's -/// an infinite iterator, which is better expressed by `iter::repeat`, -/// but the method has been removed for `Iterator::step_by` which panics -/// if given a zero + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's + /// an infinite iterator, which is better expressed by `iter::repeat`, + /// but the method has been removed for `Iterator::step_by` which panics + /// if given a zero pub RANGE_STEP_BY_ZERO, "`iterator.step_by(0)` panics nowadays" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good -/// stable alternatives. `Vec::as_slice` has now been stabilized. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good + /// stable alternatives. `Vec::as_slice` has now been stabilized. pub UNSTABLE_AS_SLICE, "`Vec::as_slice` has been stabilized in 1.7" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good -/// stable alternatives. `Vec::as_mut_slice` has now been stabilized. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good + /// stable alternatives. `Vec::as_mut_slice` has now been stabilized. pub UNSTABLE_AS_MUT_SLICE, "`Vec::as_mut_slice` has been stabilized in 1.7" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This used to check for `.to_string()` method calls on values -/// of type `&str`. This is not unidiomatic and with specialization coming, `to_string` could be -/// specialized to be as efficient as `to_owned`. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This used to check for `.to_string()` method calls on values + /// of type `&str`. This is not unidiomatic and with specialization coming, `to_string` could be + /// specialized to be as efficient as `to_owned`. pub STR_TO_STRING, "using `str::to_string` is common even today and specialization will likely happen soon" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This used to check for `.to_string()` method calls on values -/// of type `String`. This is not unidiomatic and with specialization coming, `to_string` could be -/// specialized to be as efficient as `clone`. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This used to check for `.to_string()` method calls on values + /// of type `String`. This is not unidiomatic and with specialization coming, `to_string` could be + /// specialized to be as efficient as `clone`. pub STRING_TO_STRING, "using `string::to_string` is common even today and specialization will likely happen soon" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting -/// between non-pointer types of differing alignment is well-defined behavior (it's semantically -/// equivalent to a memcpy). This lint has thus been refactored into two separate lints: -/// cast_ptr_alignment and transmute_ptr_to_ptr. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting + /// between non-pointer types of differing alignment is well-defined behavior (it's semantically + /// equivalent to a memcpy). This lint has thus been refactored into two separate lints: + /// cast_ptr_alignment and transmute_ptr_to_ptr. pub MISALIGNED_TRANSMUTE, "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr" } @@ -93,39 +93,39 @@ declare_deprecated_lint! { } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** The original rule will only lint for `if let`. After -/// making it support to lint `match`, naming as `if let` is not suitable for it. -/// So, this lint is deprecated. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** The original rule will only lint for `if let`. After + /// making it support to lint `match`, naming as `if let` is not suitable for it. + /// So, this lint is deprecated. pub IF_LET_REDUNDANT_PATTERN_MATCHING, "this lint has been changed to redundant_pattern_matching" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This lint used to suggest replacing `let mut vec = -/// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The -/// replacement has very different performance characteristics so the lint is -/// deprecated. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint used to suggest replacing `let mut vec = + /// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The + /// replacement has very different performance characteristics so the lint is + /// deprecated. pub UNSAFE_VECTOR_INITIALIZATION, "the replacement suggested by this lint had substantially different behavior" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This lint has been superseded by the warn-by-default -/// `invalid_value` rustc lint. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been superseded by the warn-by-default + /// `invalid_value` rustc lint. pub INVALID_REF, "superseded by rustc lint `invalid_value`" } declare_deprecated_lint! { -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc. + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc. pub UNUSED_COLLECT, "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint" } From 8ca9c237a069dc12db8073923ec0a4a83d0a1efc Mon Sep 17 00:00:00 2001 From: Evan Stoll Date: Sat, 2 Nov 2019 14:19:25 -0400 Subject: [PATCH 05/28] deprecated_lints: re-fix ASSIGN_OPS lint doc-comment --- clippy_lints/src/deprecated_lints.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index a7640b8e8ced..729c494d1dcc 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -82,12 +82,12 @@ declare_deprecated_lint! { "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr" } -/// **What it does:** Nothing. This lint has been deprecated. -/// -/// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy. -/// Additionally, compound assignment operators may be overloaded separately from their non-assigning -/// counterparts, so this lint may suggest a change in behavior or the code may not compile. declare_deprecated_lint! { + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy. + /// Additionally, compound assignment operators may be overloaded separately from their non-assigning + /// counterparts, so this lint may suggest a change in behavior or the code may not compile. pub ASSIGN_OPS, "using compound assignment operators (e.g., `+=`) is harmless" } From e3d6069e1845827a1f507882b407122db4418aa4 Mon Sep 17 00:00:00 2001 From: HMPerson1 Date: Mon, 4 Nov 2019 20:03:03 -0500 Subject: [PATCH 06/28] Use correct TypeckTables when hashing bodies --- clippy_lints/src/utils/hir_utils.rs | 22 +++++++++++++--------- tests/ui/crashes/ice-4760.rs | 10 ++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 tests/ui/crashes/ice-4760.rs diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index d8b20a5df615..5602e76322d7 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -451,6 +451,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { CaptureClause::CaptureByRef => 1, } .hash(&mut self.s); + // closures inherit TypeckTables self.hash_expr(&self.cx.tcx.hir().body(eid).value); }, ExprKind::Field(ref e, ref f) => { @@ -490,10 +491,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { }, ExprKind::Repeat(ref e, ref l_id) => { self.hash_expr(e); - let full_table = self.tables; - self.tables = self.cx.tcx.body_tables(l_id.body); - self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value); - self.tables = full_table; + self.hash_body(l_id.body); }, ExprKind::Ret(ref e) => { if let Some(ref e) = *e { @@ -609,7 +607,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { }, TyKind::Array(ty, anon_const) => { self.hash_ty(ty); - self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value); + self.hash_body(anon_const.body); }, TyKind::Ptr(mut_ty) => { self.hash_ty(&mut_ty.ty); @@ -660,9 +658,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { match arg { GenericArg::Lifetime(ref l) => self.hash_lifetime(l), GenericArg::Type(ref ty) => self.hash_ty(&ty), - GenericArg::Const(ref ca) => { - self.hash_expr(&self.cx.tcx.hir().body(ca.value.body).value); - }, + GenericArg::Const(ref ca) => self.hash_body(ca.value.body), } } }, @@ -670,9 +666,17 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_lifetime(lifetime); }, TyKind::Typeof(anon_const) => { - self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value); + self.hash_body(anon_const.body); }, TyKind::Err | TyKind::Infer | TyKind::Never => {}, } } + + pub fn hash_body(&mut self, body_id: BodyId) { + // swap out TypeckTables when hashing a body + let old_tables = self.tables; + self.tables = self.cx.tcx.body_tables(body_id); + self.hash_expr(&self.cx.tcx.hir().body(body_id).value); + self.tables = old_tables; + } } diff --git a/tests/ui/crashes/ice-4760.rs b/tests/ui/crashes/ice-4760.rs new file mode 100644 index 000000000000..ead67d5ed1b1 --- /dev/null +++ b/tests/ui/crashes/ice-4760.rs @@ -0,0 +1,10 @@ +// run-pass +const COUNT: usize = 2; +struct Thing; +trait Dummy {} + +const _: () = { + impl Dummy for Thing where [i32; COUNT]: Sized {} +}; + +fn main() {} From a902e3fd715d01c05568f9f9e99e9311b9653c48 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 6 Nov 2019 06:24:47 +0000 Subject: [PATCH 07/28] rustup https://github.com/rust-lang/rust/pull/66014 --- tests/ui/builtin-type-shadow.stderr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ui/builtin-type-shadow.stderr b/tests/ui/builtin-type-shadow.stderr index c19ea6114f85..42bde5e07f36 100644 --- a/tests/ui/builtin-type-shadow.stderr +++ b/tests/ui/builtin-type-shadow.stderr @@ -10,9 +10,11 @@ error[E0308]: mismatched types --> $DIR/builtin-type-shadow.rs:5:5 | LL | fn foo(a: u32) -> u32 { - | --- expected `u32` because of return type + | --- --- expected `u32` because of return type + | | + | this type parameter LL | 42 - | ^^ expected type parameter, found integer + | ^^ expected type parameter `u32`, found integer | = note: expected type `u32` found type `{integer}` From 3e1760cb048e636c382ef70d7df05e7e7880205e Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 6 Nov 2019 13:27:39 +0700 Subject: [PATCH 08/28] build: re-enable stdsimd integration test Also sorting rls to the first in the list because it is now the longest running test. --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ab711b723b0..b07ebe501c76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,15 +56,15 @@ matrix: # We don't want to run these always because they go towards # the build limit within the Travis rust-lang account. # The jobs are approximately sorted by execution time + - env: INTEGRATION=rust-lang/rls + if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang/cargo if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang-nursery/chalk if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - - env: INTEGRATION=rust-lang/rls - if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=Geal/nom if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - # FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4742 + # FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4727 #- env: INTEGRATION=rust-lang/rustfmt # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=hyperium/hyper @@ -90,7 +90,6 @@ matrix: allow_failures: - os: windows env: CARGO_INCREMENTAL=0 OS_WINDOWS=true - - env: INTEGRATION=rust-lang-nursery/stdsimd before_script: - | From 51632530d78598a91ab935cd09c4eca3b2097269 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 6 Nov 2019 16:50:24 +0700 Subject: [PATCH 09/28] rustup rust-lang/rust#65776 --- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/non_expressive_names.rs | 4 ++-- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/unsafe_removed_from_name.rs | 4 ++-- clippy_lints/src/utils/internal_lints.rs | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e7b07bb1c1b6..db94d9dcdafa 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -17,7 +17,7 @@ use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use syntax::ast; use syntax::source_map::Span; -use syntax::symbol::{sym, LocalInternedString, Symbol}; +use syntax::symbol::{sym, Symbol, SymbolStr}; use crate::utils::usage::mutated_variables; use crate::utils::{ @@ -1148,8 +1148,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { } let (method_names, arg_lists, method_spans) = method_calls(expr, 2); - let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); - let method_names: Vec<&str> = method_names.iter().map(std::convert::AsRef::as_ref).collect(); + let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); + let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); match method_names.as_slice() { ["unwrap", "get"] => lint_get_unwrap(cx, expr, arg_lists[1], false), diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 08a78b784ba5..12df9325650f 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; use syntax::ast::*; use syntax::attr; use syntax::source_map::Span; -use syntax::symbol::LocalInternedString; +use syntax::symbol::SymbolStr; use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor}; declare_clippy_lint! { @@ -72,7 +72,7 @@ pub struct NonExpressiveNames { impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]); struct ExistingName { - interned: LocalInternedString, + interned: SymbolStr, span: Span, len: usize, whitelist: &'static [&'static str], diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 464845c3c741..eee60e33bab6 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite { if let Some(get_index_arg) = args.get(1); if let ExprKind::Lit(ref lit) = get_index_arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; - if let pushed_path = Path::new(&path_lit.as_str()); + if let pushed_path = Path::new(&*path_lit.as_str()); if let Some(pushed_path_lit) = pushed_path.to_str(); if pushed_path.has_root(); if let Some(root) = pushed_path.components().next(); diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 528a1915be84..2f0e406b1a55 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -3,7 +3,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; use syntax::source_map::Span; -use syntax::symbol::LocalInternedString; +use syntax::symbol::SymbolStr; declare_clippy_lint! { /// **What it does:** Checks for imports that remove "unsafe" from an item's @@ -73,6 +73,6 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>, } #[must_use] -fn contains_unsafe(name: &LocalInternedString) -> bool { +fn contains_unsafe(name: &SymbolStr) -> bool { name.contains("Unsafe") || name.contains("unsafe") } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index b5cd0d17f77d..1d1a3da6bc41 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -13,7 +13,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use syntax::ast::{Crate as AstCrate, ItemKind, Name}; use syntax::source_map::Span; -use syntax_pos::symbol::LocalInternedString; +use syntax_pos::symbol::SymbolStr; declare_clippy_lint! { /// **What it does:** Checks for various things we like to keep tidy in clippy. @@ -112,7 +112,7 @@ impl EarlyLintPass for ClippyLintsInternal { if let ItemKind::Mod(ref utils_mod) = utils.kind { if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name.as_str() == "paths") { if let ItemKind::Mod(ref paths_mod) = paths.kind { - let mut last_name: Option = None; + let mut last_name: Option = None; for item in &*paths_mod.items { let name = item.ident.as_str(); if let Some(ref last_name) = last_name { @@ -279,8 +279,8 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { let (method_names, arg_lists, spans) = method_calls(expr, 2); - let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); - let method_names: Vec<&str> = method_names.iter().map(std::convert::AsRef::as_ref).collect(); + let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); + let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); if_chain! { if let ["expn_data", "outer_expn"] = method_names.as_slice(); let args = arg_lists[1]; From 56f3ba33c55f4651c7fdc54370b2f3601fbf7c4b Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 6 Nov 2019 16:46:32 +0700 Subject: [PATCH 10/28] chore: sort out clippy_lints deps --- clippy_lints/Cargo.toml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index f7054a243756..9a77ee238eb7 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -18,20 +18,21 @@ edition = "2018" [dependencies] cargo_metadata = "0.9.0" +if_chain = "1.0.0" itertools = "0.8" lazy_static = "1.0.2" matches = "0.1.7" +pulldown-cmark = "0.6.0" quine-mc_cluskey = "0.2.2" regex-syntax = "0.6" -semver = "0.9.0" serde = { version = "1.0", features = ["derive"] } +smallvec = { version = "0.6.5", features = ["union"] } toml = "0.5.3" unicode-normalization = "0.1" -pulldown-cmark = "0.6.0" -url = { version = "2.1.0", features = ["serde"] } # cargo requires serde feat in its url dep -# see https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864 -if_chain = "1.0.0" -smallvec = { version = "0.6.5", features = ["union"] } +semver = "0.9.0" +# NOTE: cargo requires serde feat in its url dep +# see +url = { version = "2.1.0", features = ["serde"] } [features] debugging = [] From 42c8c03464c5ca876d9fa1e31b6837a647bac5e0 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 6 Nov 2019 17:00:12 +0700 Subject: [PATCH 11/28] bump smallvec to 1.0.0 --- clippy_lints/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 9a77ee238eb7..608fb668c5ae 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -26,7 +26,7 @@ pulldown-cmark = "0.6.0" quine-mc_cluskey = "0.2.2" regex-syntax = "0.6" serde = { version = "1.0", features = ["derive"] } -smallvec = { version = "0.6.5", features = ["union"] } +smallvec = { version = "1", features = ["union"] } toml = "0.5.3" unicode-normalization = "0.1" semver = "0.9.0" From fdc0153ef5c6899abcaa0cc26b69a8ef2db8f353 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 7 Nov 2019 00:38:10 +0700 Subject: [PATCH 12/28] rustup improper_ctypes: `extern "C"` fns --- tests/ui/functions.rs | 4 +- tests/ui/needless_pass_by_value.rs | 5 ++- tests/ui/needless_pass_by_value.stderr | 52 +++++++++++++------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tests/ui/functions.rs b/tests/ui/functions.rs index 7e2e083e2988..271754cb06ee 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -31,12 +31,12 @@ fn bad_multiline( extern "C" fn extern_fn( _one: u32, _two: u32, - _three: &str, + _three: *const u8, _four: bool, _five: f32, _six: f32, _seven: bool, - _eight: (), + _eight: *const std::ffi::c_void, ) { } diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index ca94daa24e84..e93a7fe2985b 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -11,6 +11,7 @@ use std::borrow::Borrow; use std::collections::HashSet; use std::convert::AsRef; +use std::mem::MaybeUninit; // `v` should be warned // `w`, `x` and `y` are allowed (moved or mutated) @@ -111,8 +112,8 @@ trait FalsePositive { } // shouldn't warn on extern funcs -extern "C" fn ext(x: String) -> usize { - x.len() +extern "C" fn ext(x: MaybeUninit) -> usize { + unsafe { x.assume_init() } } // whitelist RangeArgument diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 6cf517c22efb..37241dbb409e 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -1,5 +1,5 @@ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:17:23 + --> $DIR/needless_pass_by_value.rs:18:23 | LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { | ^^^^^^ help: consider changing the type to: `&[T]` @@ -7,55 +7,55 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec $DIR/needless_pass_by_value.rs:31:11 + --> $DIR/needless_pass_by_value.rs:32:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:31:22 + --> $DIR/needless_pass_by_value.rs:32:22 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:37:71 + --> $DIR/needless_pass_by_value.rs:38:71 | LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { | ^ help: consider taking a reference instead: `&V` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:49:18 + --> $DIR/needless_pass_by_value.rs:50:18 | LL | fn test_match(x: Option>, y: Option>) { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option>` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:62:24 + --> $DIR/needless_pass_by_value.rs:63:24 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:62:36 + --> $DIR/needless_pass_by_value.rs:63:36 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:78:49 + --> $DIR/needless_pass_by_value.rs:79:49 | LL | fn test_blanket_ref(_foo: T, _serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:80:18 + --> $DIR/needless_pass_by_value.rs:81:18 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:80:29 + --> $DIR/needless_pass_by_value.rs:81:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -70,13 +70,13 @@ LL | let _ = t.to_string(); | ^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:80:40 + --> $DIR/needless_pass_by_value.rs:81:40 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ help: consider taking a reference instead: `&Vec` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:80:53 + --> $DIR/needless_pass_by_value.rs:81:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -91,85 +91,85 @@ LL | let _ = v.to_owned(); | ^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:93:12 + --> $DIR/needless_pass_by_value.rs:94:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:94:12 + --> $DIR/needless_pass_by_value.rs:95:12 | LL | t: String, | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:103:23 + --> $DIR/needless_pass_by_value.rs:104:23 | LL | fn baz(&self, _u: U, _s: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:103:30 + --> $DIR/needless_pass_by_value.rs:104:30 | LL | fn baz(&self, _u: U, _s: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:125:24 + --> $DIR/needless_pass_by_value.rs:126:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as Copy - --> $DIR/needless_pass_by_value.rs:123:1 + --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:131:29 + --> $DIR/needless_pass_by_value.rs:132:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as Copy - --> $DIR/needless_pass_by_value.rs:123:1 + --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:131:45 + --> $DIR/needless_pass_by_value.rs:132:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as Copy - --> $DIR/needless_pass_by_value.rs:123:1 + --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:131:61 + --> $DIR/needless_pass_by_value.rs:132:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as Copy - --> $DIR/needless_pass_by_value.rs:123:1 + --> $DIR/needless_pass_by_value.rs:124:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:143:40 + --> $DIR/needless_pass_by_value.rs:144:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:148:20 + --> $DIR/needless_pass_by_value.rs:149:20 | LL | fn more_fun(_item: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` From 305ba73fc1f0e5bd76c2572d9e858741e7a71a09 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 7 Nov 2019 00:34:45 -0800 Subject: [PATCH 13/28] Rustup to rustc 1.40.0-nightly (7a76fe76f 2019-11-07) --- clippy_lints/src/attrs.rs | 13 ++++++++----- clippy_lints/src/doc.rs | 14 ++++++-------- clippy_lints/src/main_recursion.rs | 9 ++++++++- clippy_lints/src/utils/attrs.rs | 5 +++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 2324693cdc98..06df8504def9 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -15,7 +15,7 @@ use rustc::ty; use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use semver::Version; -use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; +use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; use syntax::source_map::Span; use syntax_pos::symbol::Symbol; @@ -417,11 +417,14 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib } for attr in attrs { - if attr.is_sugared_doc { - return; - } + let attr_item = if let AttrKind::Normal(ref attr) = attr.kind { + attr + } else { + continue; + }; + if attr.style == AttrStyle::Outer { - if attr.tokens.is_empty() || !is_present_in_source(cx, attr.span) { + if attr_item.tokens.is_empty() || !is_present_in_source(cx, attr.span) { return; } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 726a044f9ed9..aca4d176724f 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -6,7 +6,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashSet; use std::ops::Range; -use syntax::ast::Attribute; +use syntax::ast::{AttrKind, Attribute}; use syntax::source_map::{BytePos, Span}; use syntax_pos::Pos; use url::Url; @@ -247,13 +247,11 @@ pub fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet [MAIN_RECURSION]); impl LateLintPass<'_, '_> for MainRecursion { fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate) { - self.has_no_std_attr = krate.attrs.iter().any(|attr| attr.path == sym::no_std); + self.has_no_std_attr = krate.attrs.iter().any(|attr| { + if let AttrKind::Normal(ref attr) = attr.kind { + attr.path == sym::no_std + } else { + false + } + }); } fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { diff --git a/clippy_lints/src/utils/attrs.rs b/clippy_lints/src/utils/attrs.rs index 2520f366b327..19dbae2eabd9 100644 --- a/clippy_lints/src/utils/attrs.rs +++ b/clippy_lints/src/utils/attrs.rs @@ -57,6 +57,11 @@ pub fn get_attr<'a>( name: &'static str, ) -> impl Iterator { attrs.iter().filter(move |attr| { + let attr = if let ast::AttrKind::Normal(ref attr) = attr.kind { + attr + } else { + return false; + }; let attr_segments = &attr.path.segments; if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" { if let Some(deprecation_status) = From e917b012865d67f05e69da8d741f2be91f4e9a26 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 7 Nov 2019 13:27:00 +0100 Subject: [PATCH 14/28] Rustup to rust-lang/rust#65884 --- clippy_lints/src/approx_const.rs | 10 ++++++---- clippy_lints/src/consts.rs | 8 +++++--- clippy_lints/src/excessive_precision.rs | 2 +- clippy_lints/src/literal_representation.rs | 2 +- clippy_lints/src/misc_early.rs | 8 ++++---- clippy_lints/src/precedence.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/types.rs | 4 ++-- clippy_lints/src/utils/author.rs | 14 +++++++++----- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 81555a4c533b..fac75cffeba6 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -3,7 +3,7 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, declare_tool_lint}; use std::f64::consts as f64; -use syntax::ast::{FloatTy, LitKind}; +use syntax::ast::{FloatTy, LitFloatType, LitKind}; use syntax::symbol; declare_clippy_lint! { @@ -62,9 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant { fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) { match *lit { - LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"), - LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"), - LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"), + LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { + FloatTy::F32 => check_known_consts(cx, e, s, "f32"), + FloatTy::F64 => check_known_consts(cx, e, s, "f64"), + }, + LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"), _ => (), } } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index dc70de48503c..fc5c8b2e379d 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -161,9 +161,11 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), - LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), - LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), - LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").kind { + LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { + FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), + FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), + }, + LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind { ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), _ => bug!(), diff --git a/clippy_lints/src/excessive_precision.rs b/clippy_lints/src/excessive_precision.rs index fcc247974c57..8027a736c6b4 100644 --- a/clippy_lints/src/excessive_precision.rs +++ b/clippy_lints/src/excessive_precision.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision { let ty = cx.tables.expr_ty(expr); if let ty::Float(fty) = ty.kind; if let hir::ExprKind::Lit(ref lit) = expr.kind; - if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node; + if let LitKind::Float(sym, _) = lit.node; if let Some(sugg) = Self::check(sym, fty); then { span_lint_and_sugg( diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index badd2237073c..c526858a7a2d 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -373,7 +373,7 @@ impl LiteralDigitGrouping { } } }, - LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => { + LitKind::Float(..) => { // Lint floating-point literals. if_chain! { if let Some(src) = snippet_opt(cx, lit.span); diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 2f43daf4caf7..d756980b354d 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -482,8 +482,8 @@ impl MiscEarlyLints { if let LitKind::Int(value, lit_int_type) = lit.kind { let suffix = match lit_int_type { - LitIntType::Signed(ty) => ty.ty_to_string(), - LitIntType::Unsigned(ty) => ty.ty_to_string(), + LitIntType::Signed(ty) => ty.name_str(), + LitIntType::Unsigned(ty) => ty.name_str(), LitIntType::Unsuffixed => "", }; @@ -543,8 +543,8 @@ impl MiscEarlyLints { }, ); } - } else if let LitKind::Float(_, float_ty) = lit.kind { - let suffix = float_ty.ty_to_string(); + } else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind { + let suffix = float_ty.name_str(); let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1; if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' { span_lint_and_sugg( diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index a2d054c1de42..a0bcba17d556 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -90,7 +90,7 @@ impl EarlyLintPass for Precedence { if let Some(slf) = args.first() { if let ExprKind::Lit(ref lit) = slf.kind { match lit.kind { - LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => { + LitKind::Int(..) | LitKind::Float(..) => { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 1339555f9ce8..788d02ecb0aa 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -390,7 +390,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); let arg = if let ty::Int(_) = from_ty.kind { - arg.as_ty(ast::UintTy::U32) + arg.as_ty(ast::UintTy::U32.name_str()) } else { arg }; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 6c1e0b808d9f..62da724ffd9e 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -15,7 +15,7 @@ use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_errors::Applicability; use rustc_target::spec::abi::Abi; use rustc_typeck::hir_ty_to_ty; -use syntax::ast::{FloatTy, IntTy, LitIntType, LitKind, UintTy}; +use syntax::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; use syntax::errors::DiagnosticBuilder; use syntax::source_map::Span; use syntax::symbol::{sym, Symbol}; @@ -1186,7 +1186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { } } match lit.node { - LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::FloatUnsuffixed(_) => {}, + LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {}, _ => { if cast_from.kind == cast_to.kind && !in_external_macro(cx.sess(), expr.span) { span_lint( diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index a424c09ef408..f3fc0487b265 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -9,7 +9,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::session::Session; use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashMap; -use syntax::ast::{Attribute, LitKind}; +use syntax::ast::{Attribute, LitFloatType, LitKind}; declare_clippy_lint! { /// **What it does:** Generates clippy code that detects the offending pattern @@ -288,10 +288,14 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { LitKind::Byte(b) => println!(" if let LitKind::Byte({}) = {}.node;", b, lit_pat), // FIXME: also check int type LitKind::Int(i, _) => println!(" if let LitKind::Int({}, _) = {}.node;", i, lit_pat), - LitKind::Float(..) => println!(" if let LitKind::Float(..) = {}.node;", lit_pat), - LitKind::FloatUnsuffixed(_) => { - println!(" if let LitKind::FloatUnsuffixed(_) = {}.node;", lit_pat) - }, + LitKind::Float(_, LitFloatType::Suffixed(_)) => println!( + " if let LitKind::Float(_, LitFloatType::Suffixed(_)) = {}.node;", + lit_pat + ), + LitKind::Float(_, LitFloatType::Unsuffixed) => println!( + " if let LitKind::Float(_, LitFloatType::Unsuffixed) = {}.node;", + lit_pat + ), LitKind::ByteStr(ref vec) => { let vec_pat = self.next("vec"); println!(" if let LitKind::ByteStr(ref {}) = {}.node;", vec_pat, lit_pat); From 08fd397c2c8db452692dc71ce7b4d3c47417ff09 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 7 Nov 2019 13:44:57 +0100 Subject: [PATCH 15/28] Deprecate `into_iter_on_array` lint This lint was uplifted/reimplemented by rustc. Rustup to rust-lang/rust#66017 --- README.md | 2 +- clippy_lints/src/deprecated_lints.rs | 9 ++++ clippy_lints/src/lib.rs | 7 +-- clippy_lints/src/methods/mod.rs | 45 ++--------------- src/lintlist/mod.rs | 9 +--- tests/ui/deprecated.rs | 1 + tests/ui/deprecated.stderr | 8 +++- tests/ui/for_loop_fixable.fixed | 5 +- tests/ui/for_loop_fixable.rs | 5 +- tests/ui/for_loop_fixable.stderr | 26 ++++------ tests/ui/for_loop_unfixable.rs | 2 +- tests/ui/into_iter_on_ref.fixed | 3 -- tests/ui/into_iter_on_ref.rs | 3 -- tests/ui/into_iter_on_ref.stderr | 72 +++++++++++----------------- 14 files changed, 67 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index 87ef441eadd5..41b8b4199ec5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 331 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 97ae9c780888..2ac5dca8c2ee 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -130,3 +130,12 @@ declare_deprecated_lint! { pub UNUSED_COLLECT, "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint" } + +declare_deprecated_lint! { + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been uplifted to rustc and is now called + /// `array_into_iter`. + pub INTO_ITER_ON_ARRAY, + "this lint has been uplifted to rustc and is now called `array_into_iter`" +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 817575092cc5..1bd117dae943 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -430,6 +430,10 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf "clippy::unused_collect", "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint", ); + store.register_removed( + "clippy::into_iter_on_array", + "this lint has been uplifted to rustc and is now called `array_into_iter`", + ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s used in `update_lints` @@ -584,7 +588,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &methods::FLAT_MAP_IDENTITY, &methods::GET_UNWRAP, &methods::INEFFICIENT_TO_STRING, - &methods::INTO_ITER_ON_ARRAY, &methods::INTO_ITER_ON_REF, &methods::ITER_CLONED_COLLECT, &methods::ITER_NTH, @@ -1142,7 +1145,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&methods::FILTER_NEXT), LintId::of(&methods::FLAT_MAP_IDENTITY), LintId::of(&methods::INEFFICIENT_TO_STRING), - LintId::of(&methods::INTO_ITER_ON_ARRAY), LintId::of(&methods::INTO_ITER_ON_REF), LintId::of(&methods::ITER_CLONED_COLLECT), LintId::of(&methods::ITER_NTH), @@ -1481,7 +1483,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT), LintId::of(&methods::CLONE_DOUBLE_REF), - LintId::of(&methods::INTO_ITER_ON_ARRAY), LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR), LintId::of(&methods::UNINIT_ASSUMED_INIT), LintId::of(&minmax::MIN_MAX), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index db94d9dcdafa..c71324ea4725 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -968,34 +968,6 @@ declare_clippy_lint! { "using `filter_map` when a more succinct alternative exists" } -declare_clippy_lint! { - /// **What it does:** Checks for `into_iter` calls on types which should be replaced by `iter` or - /// `iter_mut`. - /// - /// **Why is this bad?** Arrays and `PathBuf` do not yet have an `into_iter` method which move out - /// their content into an iterator. Auto-referencing resolves the `into_iter` call to its reference - /// instead, like `<&[T; N] as IntoIterator>::into_iter`, which just iterates over item references - /// like calling `iter` would. Furthermore, when the standard library actually - /// [implements the `into_iter` method](https://github.com/rust-lang/rust/issues/25725) which moves - /// the content out of the array, the original use of `into_iter` got inferred with the wrong type - /// and the code will be broken. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::>(); - /// ``` - /// Could be written as: - /// ```rust - /// let _ = [1, 2, 3].iter().map(|x| *x).collect::>(); - /// ``` - pub INTO_ITER_ON_ARRAY, - correctness, - "using `.into_iter()` on an array" -} - declare_clippy_lint! { /// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter` /// or `iter_mut`. @@ -1133,7 +1105,6 @@ declare_lint_pass!(Methods => [ USELESS_ASREF, UNNECESSARY_FOLD, UNNECESSARY_FILTER_MAP, - INTO_ITER_ON_ARRAY, INTO_ITER_ON_REF, SUSPICIOUS_MAP, UNINIT_ASSUMED_INIT, @@ -2786,16 +2757,8 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re } } -fn ty_has_iter_method( - cx: &LateContext<'_, '_>, - self_ref_ty: Ty<'_>, -) -> Option<(&'static Lint, &'static str, &'static str)> { +fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> { has_iter_method(cx, self_ref_ty).map(|ty_name| { - let lint = if ty_name == "array" || ty_name == "PathBuf" { - INTO_ITER_ON_ARRAY - } else { - INTO_ITER_ON_REF - }; let mutbl = match self_ref_ty.kind { ty::Ref(_, _, mutbl) => mutbl, _ => unreachable!(), @@ -2804,7 +2767,7 @@ fn ty_has_iter_method( hir::MutImmutable => "iter", hir::MutMutable => "iter_mut", }; - (lint, ty_name, method_name) + (ty_name, method_name) }) } @@ -2812,10 +2775,10 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_ if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) { return; } - if let Some((lint, kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) { + if let Some((kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) { span_lint_and_sugg( cx, - lint, + INTO_ITER_ON_REF, method_span, &format!( "this .into_iter() call is equivalent to .{}() and will not move the {}", diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index a053cf8bef0c..35cbeae39889 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 332] = [ +pub const ALL_LINTS: [Lint; 331] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -812,13 +812,6 @@ pub const ALL_LINTS: [Lint; 332] = [ deprecation: None, module: "integer_division", }, - Lint { - name: "into_iter_on_array", - group: "correctness", - desc: "using `.into_iter()` on an array", - deprecation: None, - module: "methods", - }, Lint { name: "into_iter_on_ref", group: "style", diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index a928d044b7ad..91d43758ab0a 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -5,5 +5,6 @@ #[warn(clippy::misaligned_transmute)] #[warn(clippy::unused_collect)] #[warn(clippy::invalid_ref)] +#[warn(clippy::into_iter_on_array)] fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index 00ed4c5e51d7..d353b26e5376 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -42,11 +42,17 @@ error: lint `clippy::invalid_ref` has been removed: `superseded by rustc lint `i LL | #[warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ +error: lint `clippy::into_iter_on_array` has been removed: `this lint has been uplifted to rustc and is now called `array_into_iter`` + --> $DIR/deprecated.rs:8:8 + | +LL | #[warn(clippy::into_iter_on_array)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::str_to_string)] | ^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/for_loop_fixable.fixed b/tests/ui/for_loop_fixable.fixed index 3075638ef94b..ec5ff1aeeef4 100644 --- a/tests/ui/for_loop_fixable.fixed +++ b/tests/ui/for_loop_fixable.fixed @@ -31,7 +31,7 @@ impl Unrelated { clippy::cognitive_complexity, clippy::similar_names )] -#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)] +#[allow(clippy::many_single_char_names, unused_variables)] fn main() { const MAX_LEN: usize = 42; let mut vec = vec![1, 2, 3, 4]; @@ -102,9 +102,6 @@ fn main() { let out_vec = vec![1, 2, 3]; for _v in out_vec {} - let array = [1, 2, 3]; - for _v in &array {} - for _v in &vec {} // these are fine for _v in &mut vec {} // these are fine diff --git a/tests/ui/for_loop_fixable.rs b/tests/ui/for_loop_fixable.rs index 2201596fd6a6..2f42ea3ca417 100644 --- a/tests/ui/for_loop_fixable.rs +++ b/tests/ui/for_loop_fixable.rs @@ -31,7 +31,7 @@ impl Unrelated { clippy::cognitive_complexity, clippy::similar_names )] -#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)] +#[allow(clippy::many_single_char_names, unused_variables)] fn main() { const MAX_LEN: usize = 42; let mut vec = vec![1, 2, 3, 4]; @@ -102,9 +102,6 @@ fn main() { let out_vec = vec![1, 2, 3]; for _v in out_vec.into_iter() {} - let array = [1, 2, 3]; - for _v in array.into_iter() {} - for _v in &vec {} // these are fine for _v in &mut vec {} // these are fine diff --git a/tests/ui/for_loop_fixable.stderr b/tests/ui/for_loop_fixable.stderr index 7454f40f3e2d..485ba1ee7b3a 100644 --- a/tests/ui/for_loop_fixable.stderr +++ b/tests/ui/for_loop_fixable.stderr @@ -77,64 +77,58 @@ LL | for _v in out_vec.into_iter() {} = note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:106:15 - | -LL | for _v in array.into_iter() {} - | ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:111:15 + --> $DIR/for_loop_fixable.rs:108:15 | LL | for _v in [1, 2, 3].iter() {} | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:115:15 + --> $DIR/for_loop_fixable.rs:112:15 | LL | for _v in [0; 32].iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:120:15 + --> $DIR/for_loop_fixable.rs:117:15 | LL | for _v in ll.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&ll` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:123:15 + --> $DIR/for_loop_fixable.rs:120:15 | LL | for _v in vd.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&vd` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:126:15 + --> $DIR/for_loop_fixable.rs:123:15 | LL | for _v in bh.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bh` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:129:15 + --> $DIR/for_loop_fixable.rs:126:15 | LL | for _v in hm.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&hm` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:132:15 + --> $DIR/for_loop_fixable.rs:129:15 | LL | for _v in bt.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bt` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:135:15 + --> $DIR/for_loop_fixable.rs:132:15 | LL | for _v in hs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&hs` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:138:15 + --> $DIR/for_loop_fixable.rs:135:15 | LL | for _v in bs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bs` -error: aborting due to 18 previous errors +error: aborting due to 17 previous errors diff --git a/tests/ui/for_loop_unfixable.rs b/tests/ui/for_loop_unfixable.rs index 5d94647e0dbf..20a93a222829 100644 --- a/tests/ui/for_loop_unfixable.rs +++ b/tests/ui/for_loop_unfixable.rs @@ -17,7 +17,7 @@ unused, dead_code )] -#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)] +#[allow(clippy::many_single_char_names, unused_variables)] fn main() { for i in 5..5 { println!("{}", i); diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed index f5342be631b0..c30d23de3f86 100644 --- a/tests/ui/into_iter_on_ref.fixed +++ b/tests/ui/into_iter_on_ref.fixed @@ -1,7 +1,6 @@ // run-rustfix #![allow(clippy::useless_vec)] #![warn(clippy::into_iter_on_ref)] -#![deny(clippy::into_iter_on_array)] struct X; use std::collections::*; @@ -10,9 +9,7 @@ fn main() { for _ in &[1, 2, 3] {} for _ in vec![X, X] {} for _ in &vec![X, X] {} - for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter() - let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter() let _ = vec![1, 2, 3].into_iter(); let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter() let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter() diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 5ec64dcf733a..94bc1689619a 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -1,7 +1,6 @@ // run-rustfix #![allow(clippy::useless_vec)] #![warn(clippy::into_iter_on_ref)] -#![deny(clippy::into_iter_on_array)] struct X; use std::collections::*; @@ -10,9 +9,7 @@ fn main() { for _ in &[1, 2, 3] {} for _ in vec![X, X] {} for _ in &vec![X, X] {} - for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter() - let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter() let _ = vec![1, 2, 3].into_iter(); let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index 931e4880f938..a5be50f64052 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -1,23 +1,5 @@ -error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:13:24 - | -LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - | -note: lint level defined here - --> $DIR/into_iter_on_ref.rs:4:9 - | -LL | #![deny(clippy::into_iter_on_array)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:15:23 - | -LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - error: this .into_iter() call is equivalent to .iter() and will not move the Vec - --> $DIR/into_iter_on_ref.rs:17:30 + --> $DIR/into_iter_on_ref.rs:14:30 | LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` @@ -25,154 +7,154 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` error: this .into_iter() call is equivalent to .iter() and will not move the slice - --> $DIR/into_iter_on_ref.rs:18:46 + --> $DIR/into_iter_on_ref.rs:15:46 | LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the slice - --> $DIR/into_iter_on_ref.rs:19:41 + --> $DIR/into_iter_on_ref.rs:16:41 | LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the slice - --> $DIR/into_iter_on_ref.rs:20:44 + --> $DIR/into_iter_on_ref.rs:17:44 | LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:22:32 + --> $DIR/into_iter_on_ref.rs:19:32 | LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the array - --> $DIR/into_iter_on_ref.rs:23:36 + --> $DIR/into_iter_on_ref.rs:20:36 | LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the array - --> $DIR/into_iter_on_ref.rs:24:40 + --> $DIR/into_iter_on_ref.rs:21:40 | LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the Option - --> $DIR/into_iter_on_ref.rs:26:24 + --> $DIR/into_iter_on_ref.rs:23:24 | LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the Option - --> $DIR/into_iter_on_ref.rs:27:28 + --> $DIR/into_iter_on_ref.rs:24:28 | LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the Result - --> $DIR/into_iter_on_ref.rs:28:32 + --> $DIR/into_iter_on_ref.rs:25:32 | LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the Result - --> $DIR/into_iter_on_ref.rs:29:37 + --> $DIR/into_iter_on_ref.rs:26:37 | LL | let _ = (&mut Err::(7)).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the Vec - --> $DIR/into_iter_on_ref.rs:30:34 + --> $DIR/into_iter_on_ref.rs:27:34 | LL | let _ = (&Vec::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the Vec - --> $DIR/into_iter_on_ref.rs:31:38 + --> $DIR/into_iter_on_ref.rs:28:38 | LL | let _ = (&mut Vec::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the BTreeMap - --> $DIR/into_iter_on_ref.rs:32:44 + --> $DIR/into_iter_on_ref.rs:29:44 | LL | let _ = (&BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the BTreeMap - --> $DIR/into_iter_on_ref.rs:33:48 + --> $DIR/into_iter_on_ref.rs:30:48 | LL | let _ = (&mut BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the VecDeque - --> $DIR/into_iter_on_ref.rs:34:39 + --> $DIR/into_iter_on_ref.rs:31:39 | LL | let _ = (&VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the VecDeque - --> $DIR/into_iter_on_ref.rs:35:43 + --> $DIR/into_iter_on_ref.rs:32:43 | LL | let _ = (&mut VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the LinkedList - --> $DIR/into_iter_on_ref.rs:36:41 + --> $DIR/into_iter_on_ref.rs:33:41 | LL | let _ = (&LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the LinkedList - --> $DIR/into_iter_on_ref.rs:37:45 + --> $DIR/into_iter_on_ref.rs:34:45 | LL | let _ = (&mut LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the HashMap - --> $DIR/into_iter_on_ref.rs:38:43 + --> $DIR/into_iter_on_ref.rs:35:43 | LL | let _ = (&HashMap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter_mut() and will not move the HashMap - --> $DIR/into_iter_on_ref.rs:39:47 + --> $DIR/into_iter_on_ref.rs:36:47 | LL | let _ = (&mut HashMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() | ^^^^^^^^^ help: call directly: `iter_mut` error: this .into_iter() call is equivalent to .iter() and will not move the BTreeSet - --> $DIR/into_iter_on_ref.rs:41:39 + --> $DIR/into_iter_on_ref.rs:38:39 | LL | let _ = (&BTreeSet::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the BinaryHeap - --> $DIR/into_iter_on_ref.rs:42:41 + --> $DIR/into_iter_on_ref.rs:39:41 | LL | let _ = (&BinaryHeap::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the HashSet - --> $DIR/into_iter_on_ref.rs:43:38 + --> $DIR/into_iter_on_ref.rs:40:38 | LL | let _ = (&HashSet::::new()).into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the Path - --> $DIR/into_iter_on_ref.rs:44:43 + --> $DIR/into_iter_on_ref.rs:41:43 | LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` error: this .into_iter() call is equivalent to .iter() and will not move the PathBuf - --> $DIR/into_iter_on_ref.rs:45:47 + --> $DIR/into_iter_on_ref.rs:42:47 | LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter() | ^^^^^^^^^ help: call directly: `iter` -error: aborting due to 28 previous errors +error: aborting due to 26 previous errors From 695aa59c6df35343ebbcb153f6249cde0d018139 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Fri, 18 Oct 2019 21:09:42 +0200 Subject: [PATCH 16/28] Add lint for exit --- clippy_lints/src/exit.rs | 41 +++++++++++++++++++++++++++++++++ clippy_lints/src/lib.rs | 2 ++ clippy_lints/src/utils/paths.rs | 1 + tests/ui/exit.rs | 4 ++++ tests/ui/exit.stderr | 10 ++++++++ 5 files changed, 58 insertions(+) create mode 100644 clippy_lints/src/exit.rs create mode 100644 tests/ui/exit.rs create mode 100644 tests/ui/exit.stderr diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs new file mode 100644 index 000000000000..222f84bd028e --- /dev/null +++ b/clippy_lints/src/exit.rs @@ -0,0 +1,41 @@ +use crate::utils::{match_def_path, paths, qpath_res, span_lint}; +use if_chain::if_chain; +use rustc::hir::{Expr, ExprKind}; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::{declare_lint_pass, declare_tool_lint}; + +declare_clippy_lint! { + /// **What it does:** `exit()` terminates the program and doesn't provide a + /// stack trace. + /// + /// **Why is this bad?** Ideally a program is terminated by finishing + /// the main function. + /// + /// **Known problems:** This can be valid code in main() to return + /// errors + /// + /// **Example:** + /// ```ignore + /// std::process::exit(0) + /// ``` + pub EXIT, + restriction, + "`std::process::exit` is called, terminating the program" +} + +declare_lint_pass!(Exit => [EXIT]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { + if_chain! { + if let ExprKind::Call(ref path_expr, ref _args) = e.kind; + if let ExprKind::Path(ref path) = path_expr.kind; + if let Some(def_id) = qpath_res(cx, path, path_expr.hir_id).opt_def_id(); + if match_def_path(cx, def_id, &paths::EXIT); + then { + span_lint(cx, EXIT, e.span, "usage of `process::exit`"); + } + + } + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1bd117dae943..99bbaf32c290 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -188,6 +188,7 @@ pub mod escape; pub mod eta_reduction; pub mod eval_order_dependence; pub mod excessive_precision; +pub mod exit; pub mod explicit_write; pub mod fallible_impl_from; pub mod format; @@ -941,6 +942,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold)); store.register_late_pass(|| box unused_self::UnusedSelf); store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); + reg.register_late_lint_pass(||box exit::Exit); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 9787517e5055..042ca4ee7fdc 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -27,6 +27,7 @@ pub const DROP: [&str; 3] = ["core", "mem", "drop"]; pub const DROP_TRAIT: [&str; 4] = ["core", "ops", "drop", "Drop"]; pub const DURATION: [&str; 3] = ["core", "time", "Duration"]; pub const EARLY_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "EarlyContext"]; +pub const EXIT: [&str; 3] = ["std", "process", "exit"]; pub const FMT_ARGUMENTS_NEW_V1: [&str; 4] = ["core", "fmt", "Arguments", "new_v1"]; pub const FMT_ARGUMENTS_NEW_V1_FORMATTED: [&str; 4] = ["core", "fmt", "Arguments", "new_v1_formatted"]; pub const FMT_ARGUMENTV1_NEW: [&str; 4] = ["core", "fmt", "ArgumentV1", "new"]; diff --git a/tests/ui/exit.rs b/tests/ui/exit.rs new file mode 100644 index 000000000000..1850241c4768 --- /dev/null +++ b/tests/ui/exit.rs @@ -0,0 +1,4 @@ +#[warn(clippy::exit)] +fn main() { + std::process::exit(1); +} diff --git a/tests/ui/exit.stderr b/tests/ui/exit.stderr new file mode 100644 index 000000000000..4fd294395501 --- /dev/null +++ b/tests/ui/exit.stderr @@ -0,0 +1,10 @@ +error: usage of `process::exit` + --> $DIR/exit.rs:3:5 + | +LL | std::process::exit(1); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::exit` implied by `-D warnings` + +error: aborting due to previous error + From 60c2fdd0b96829df97329e29fdb92c958a3c5d4f Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Fri, 18 Oct 2019 21:10:35 +0200 Subject: [PATCH 17/28] Update lints --- CHANGELOG.md | 1 + clippy_lints/src/lib.rs | 1 + src/lintlist/mod.rs | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b32914854fe..84a3bd491cb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -996,6 +996,7 @@ Released 2018-09-13 [`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op [`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence [`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision +[`exit`]: https://rust-lang.github.io/rust-clippy/master/index.html#exit [`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call [`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy [`explicit_counter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 99bbaf32c290..d267a3d47e39 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -949,6 +949,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&arithmetic::INTEGER_ARITHMETIC), LintId::of(&dbg_macro::DBG_MACRO), LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE), + LintId::of(&exit::EXIT), LintId::of(&implicit_return::IMPLICIT_RETURN), LintId::of(&indexing_slicing::INDEXING_SLICING), LintId::of(&inherent_impl::MULTIPLE_INHERENT_IMPL), diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 35cbeae39889..7ce73b6c090f 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -490,6 +490,13 @@ pub const ALL_LINTS: [Lint; 331] = [ deprecation: None, module: "excessive_precision", }, + Lint { + name: "exit", + group: "restriction", + desc: "`std::process::exit` is called, terminating the program", + deprecation: None, + module: "exit", + }, Lint { name: "expect_fun_call", group: "perf", From 9471669e4695921cd8b70c8edaad143d8e84f430 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Sat, 19 Oct 2019 14:31:02 +0200 Subject: [PATCH 18/28] Exclude main from exit lint --- clippy_lints/src/exit.rs | 29 +++++++++++++++++++++++++---- tests/ui/exit.rs | 8 ++++++++ tests/ui/exit.stderr | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 222f84bd028e..9952ef3ea623 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -1,6 +1,6 @@ use crate::utils::{match_def_path, paths, qpath_res, span_lint}; use if_chain::if_chain; -use rustc::hir::{Expr, ExprKind}; +use rustc::hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, declare_tool_lint}; @@ -11,8 +11,7 @@ declare_clippy_lint! { /// **Why is this bad?** Ideally a program is terminated by finishing /// the main function. /// - /// **Known problems:** This can be valid code in main() to return - /// errors + /// **Known problems:** None. /// /// **Example:** /// ```ignore @@ -33,7 +32,29 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { if let Some(def_id) = qpath_res(cx, path, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::EXIT); then { - span_lint(cx, EXIT, e.span, "usage of `process::exit`"); + let mut parent = cx.tcx.hir().get_parent_item(e.hir_id); + // We have to traverse the parents upwards until we find a function + // otherwise a exit in a let or if in main would still trigger this + loop{ + match cx.tcx.hir().find(parent) { + Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) => { + // If we found a function we check it's name if it is + // `main` we emit a lint. + if ident.name.as_str() != "main" { + span_lint(cx, EXIT, e.span, "usage of `process::exit`"); + } + // We found any kind of function and can end our loop + break; + } + // If we found anything but a funciton we continue with the + // loop and go one parent up + Some(_) => { + cx.tcx.hir().get_parent_item(parent); + }, + // If we found nothing we break. + None => break, + } + } } } diff --git a/tests/ui/exit.rs b/tests/ui/exit.rs index 1850241c4768..bf8ea9bebf7e 100644 --- a/tests/ui/exit.rs +++ b/tests/ui/exit.rs @@ -1,4 +1,12 @@ #[warn(clippy::exit)] +fn not_main() { + std::process::exit(3); +} + fn main() { + if true { + std::process::exit(2); + }; + not_main(); std::process::exit(1); } diff --git a/tests/ui/exit.stderr b/tests/ui/exit.stderr index 4fd294395501..756cf8837491 100644 --- a/tests/ui/exit.stderr +++ b/tests/ui/exit.stderr @@ -1,7 +1,7 @@ error: usage of `process::exit` --> $DIR/exit.rs:3:5 | -LL | std::process::exit(1); +LL | std::process::exit(3); | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::exit` implied by `-D warnings` From ffcf4bec0f9785925b12bce49149997b1ba5c79e Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Oct 2019 22:55:01 +0200 Subject: [PATCH 19/28] Improve function checking --- clippy_lints/src/exit.rs | 7 ++++--- tests/ui/exit.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 9952ef3ea623..23952efbc8d8 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -1,4 +1,4 @@ -use crate::utils::{match_def_path, paths, qpath_res, span_lint}; +use crate::utils::{is_entrypoint_fn, match_def_path, paths, qpath_res, span_lint}; use if_chain::if_chain; use rustc::hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; @@ -40,7 +40,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) => { // If we found a function we check it's name if it is // `main` we emit a lint. - if ident.name.as_str() != "main" { + let def_id = cx.tcx.hir().local_def_id(parent); + if !is_entrypoint_fn(cx, def_id) { span_lint(cx, EXIT, e.span, "usage of `process::exit`"); } // We found any kind of function and can end our loop @@ -49,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { // If we found anything but a funciton we continue with the // loop and go one parent up Some(_) => { - cx.tcx.hir().get_parent_item(parent); + parent = cx.tcx.hir().get_parent_item(parent); }, // If we found nothing we break. None => break, diff --git a/tests/ui/exit.rs b/tests/ui/exit.rs index bf8ea9bebf7e..0ad15faef77b 100644 --- a/tests/ui/exit.rs +++ b/tests/ui/exit.rs @@ -1,5 +1,12 @@ #[warn(clippy::exit)] + fn not_main() { + if true { + std::process::exit(4); + } +} + +fn also_not_main() { std::process::exit(3); } @@ -7,6 +14,7 @@ fn main() { if true { std::process::exit(2); }; + also_not_main(); not_main(); std::process::exit(1); } From eae6a62db7582cc0c243a798268a258436c27407 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Thu, 24 Oct 2019 21:17:21 +0200 Subject: [PATCH 20/28] Simplify dentry point detection --- README.md | 2 +- clippy_lints/src/exit.rs | 28 ++++++---------------------- clippy_lints/src/lib.rs | 1 + src/lintlist/mod.rs | 2 +- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 41b8b4199ec5..922dbcd11380 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 331 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 23952efbc8d8..7220833b9f23 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -33,31 +33,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { if match_def_path(cx, def_id, &paths::EXIT); then { let mut parent = cx.tcx.hir().get_parent_item(e.hir_id); - // We have to traverse the parents upwards until we find a function - // otherwise a exit in a let or if in main would still trigger this - loop{ - match cx.tcx.hir().find(parent) { - Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) => { - // If we found a function we check it's name if it is - // `main` we emit a lint. - let def_id = cx.tcx.hir().local_def_id(parent); - if !is_entrypoint_fn(cx, def_id) { - span_lint(cx, EXIT, e.span, "usage of `process::exit`"); - } - // We found any kind of function and can end our loop - break; - } - // If we found anything but a funciton we continue with the - // loop and go one parent up - Some(_) => { - parent = cx.tcx.hir().get_parent_item(parent); - }, - // If we found nothing we break. - None => break, + if let Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent) { + // If the next item up is a function we check if it is an entry point + // and only then emit a linter warning + let def_id = cx.tcx.hir().local_def_id(parent); + if !is_entrypoint_fn(cx, def_id) { + span_lint(cx, EXIT, e.span, "usage of `process::exit`"); } } } - } } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d267a3d47e39..84e074fc2929 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -502,6 +502,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &eval_order_dependence::DIVERGING_SUB_EXPRESSION, &eval_order_dependence::EVAL_ORDER_DEPENDENCE, &excessive_precision::EXCESSIVE_PRECISION, + &exit::EXIT, &explicit_write::EXPLICIT_WRITE, &fallible_impl_from::FALLIBLE_IMPL_FROM, &format::USELESS_FORMAT, diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 7ce73b6c090f..cda2a4faba15 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 331] = [ +pub const ALL_LINTS: [Lint; 333] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", From a984702b509ce18d1dc22b1abf627b7c03fd59f6 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Fri, 25 Oct 2019 10:16:25 +0200 Subject: [PATCH 21/28] Update clippy_lints/src/lib.rs Co-Authored-By: Philipp Krones --- clippy_lints/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 84e074fc2929..e0a34102ceb6 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -943,7 +943,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold)); store.register_late_pass(|| box unused_self::UnusedSelf); store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); - reg.register_late_lint_pass(||box exit::Exit); + store.register_late_lint_pass(|| box exit::Exit); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), From abdf027df30b93a0cbd3c00690761ace7ee43430 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Fri, 25 Oct 2019 10:59:33 +0200 Subject: [PATCH 22/28] Update clippy_lints/src/lib.rs Co-Authored-By: Philipp Krones --- clippy_lints/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index e0a34102ceb6..dae1c429b7d5 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -943,7 +943,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold)); store.register_late_pass(|| box unused_self::UnusedSelf); store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); - store.register_late_lint_pass(|| box exit::Exit); + store.register_late_pass(|| box exit::Exit); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), From 5e6017d193bfc3891e99018997854bec5c97a919 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Tue, 29 Oct 2019 21:34:00 +0100 Subject: [PATCH 23/28] Update tests for exit --- tests/ui/{exit.rs => exit1.rs} | 5 ----- tests/ui/exit1.stderr | 10 ++++++++++ tests/ui/exit2.rs | 13 +++++++++++++ tests/ui/{exit.stderr => exit2.stderr} | 2 +- tests/ui/exit3.rs | 8 ++++++++ 5 files changed, 32 insertions(+), 6 deletions(-) rename tests/ui/{exit.rs => exit1.rs} (73%) create mode 100644 tests/ui/exit1.stderr create mode 100644 tests/ui/exit2.rs rename tests/ui/{exit.stderr => exit2.stderr} (89%) create mode 100644 tests/ui/exit3.rs diff --git a/tests/ui/exit.rs b/tests/ui/exit1.rs similarity index 73% rename from tests/ui/exit.rs rename to tests/ui/exit1.rs index 0ad15faef77b..4eac6eb74672 100644 --- a/tests/ui/exit.rs +++ b/tests/ui/exit1.rs @@ -6,15 +6,10 @@ fn not_main() { } } -fn also_not_main() { - std::process::exit(3); -} - fn main() { if true { std::process::exit(2); }; - also_not_main(); not_main(); std::process::exit(1); } diff --git a/tests/ui/exit1.stderr b/tests/ui/exit1.stderr new file mode 100644 index 000000000000..a8d3956aa27a --- /dev/null +++ b/tests/ui/exit1.stderr @@ -0,0 +1,10 @@ +error: usage of `process::exit` + --> $DIR/exit1.rs:5:9 + | +LL | std::process::exit(4); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::exit` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/tests/ui/exit2.rs b/tests/ui/exit2.rs new file mode 100644 index 000000000000..4b693ed7083f --- /dev/null +++ b/tests/ui/exit2.rs @@ -0,0 +1,13 @@ +#[warn(clippy::exit)] + +fn also_not_main() { + std::process::exit(3); +} + +fn main() { + if true { + std::process::exit(2); + }; + also_not_main(); + std::process::exit(1); +} diff --git a/tests/ui/exit.stderr b/tests/ui/exit2.stderr similarity index 89% rename from tests/ui/exit.stderr rename to tests/ui/exit2.stderr index 756cf8837491..7263e156a9d2 100644 --- a/tests/ui/exit.stderr +++ b/tests/ui/exit2.stderr @@ -1,5 +1,5 @@ error: usage of `process::exit` - --> $DIR/exit.rs:3:5 + --> $DIR/exit2.rs:4:5 | LL | std::process::exit(3); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/exit3.rs b/tests/ui/exit3.rs new file mode 100644 index 000000000000..9dc0e1015a4f --- /dev/null +++ b/tests/ui/exit3.rs @@ -0,0 +1,8 @@ +#[warn(clippy::exit)] + +fn main() { + if true { + std::process::exit(2); + }; + std::process::exit(1); +} From 2f1370d64cb62c521ec04999f30ed856b644dccc Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Thu, 7 Nov 2019 17:13:26 +0100 Subject: [PATCH 24/28] Update lints --- README.md | 2 +- src/lintlist/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 922dbcd11380..87ef441eadd5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index cda2a4faba15..5c92d69a4993 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 333] = [ +pub const ALL_LINTS: [Lint; 332] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", From fe90b82951f4a240ffd064c4a4b8ecfe2177f454 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 6 Nov 2019 10:36:04 -0800 Subject: [PATCH 25/28] Remove clippy_lints from useless attribute test --- tests/ui/auxiliary/proc_macro_derive.rs | 2 +- tests/ui/used_underscore_binding.rs | 1 + tests/ui/used_underscore_binding.stderr | 10 +++++----- tests/ui/useless_attribute.rs | 5 ++--- tests/ui/useless_attribute.stderr | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/ui/auxiliary/proc_macro_derive.rs b/tests/ui/auxiliary/proc_macro_derive.rs index 08b993173029..f6d101a0911b 100644 --- a/tests/ui/auxiliary/proc_macro_derive.rs +++ b/tests/ui/auxiliary/proc_macro_derive.rs @@ -16,7 +16,7 @@ pub fn derive(_: TokenStream) -> TokenStream { let output = quote! { // Should not trigger `useless_attribute` #[allow(dead_code)] - extern crate clippy_lints; + extern crate rustc; }; output } diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index 5a02ff5d193d..9c06e047c4ad 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -1,5 +1,6 @@ // aux-build:proc_macro_derive.rs +#![feature(rustc_private)] #![warn(clippy::all)] #![allow(clippy::blacklisted_name)] #![warn(clippy::used_underscore_binding)] diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr index 8216a3c66e5b..47693518f862 100644 --- a/tests/ui/used_underscore_binding.stderr +++ b/tests/ui/used_underscore_binding.stderr @@ -1,5 +1,5 @@ error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:24:5 + --> $DIR/used_underscore_binding.rs:25:5 | LL | _foo + 1 | ^^^^ @@ -7,25 +7,25 @@ LL | _foo + 1 = note: `-D clippy::used-underscore-binding` implied by `-D warnings` error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:29:20 + --> $DIR/used_underscore_binding.rs:30:20 | LL | println!("{}", _foo); | ^^^^ error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:30:16 + --> $DIR/used_underscore_binding.rs:31:16 | LL | assert_eq!(_foo, _foo); | ^^^^ error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:30:22 + --> $DIR/used_underscore_binding.rs:31:22 | LL | assert_eq!(_foo, _foo); | ^^^^ error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:43:5 + --> $DIR/used_underscore_binding.rs:44:5 | LL | s._underscore_field += 1; | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index dd84b1b2c1c3..529680a7588a 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -2,16 +2,15 @@ #![warn(clippy::useless_attribute)] #![warn(unreachable_pub)] +#![feature(rustc_private)] #[allow(dead_code)] #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] #[rustfmt::skip] -#[cfg_attr(feature = "cargo-clippy", - allow(dead_code))] #[allow(unused_imports)] #[allow(unused_extern_crates)] #[macro_use] -extern crate clippy_lints; +extern crate rustc; #[macro_use] extern crate proc_macro_derive; diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index bf7ea1698d35..87a1291543e1 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -1,5 +1,5 @@ error: useless lint attribute - --> $DIR/useless_attribute.rs:6:1 + --> $DIR/useless_attribute.rs:7:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` @@ -7,7 +7,7 @@ LL | #[allow(dead_code)] = note: `-D clippy::useless-attribute` implied by `-D warnings` error: useless lint attribute - --> $DIR/useless_attribute.rs:7:1 + --> $DIR/useless_attribute.rs:8:1 | LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)` From 4721f4419b0fcfa95e42690a1acc3198b943fb22 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 7 Nov 2019 12:48:22 -0800 Subject: [PATCH 26/28] Remove clippy dependency in lint_without_lint_pass --- tests/ui/lint_without_lint_pass.rs | 30 +++++++++++++------------- tests/ui/lint_without_lint_pass.stderr | 11 +++++----- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/ui/lint_without_lint_pass.rs b/tests/ui/lint_without_lint_pass.rs index dc93bbfd7526..81353414d24d 100644 --- a/tests/ui/lint_without_lint_pass.rs +++ b/tests/ui/lint_without_lint_pass.rs @@ -5,25 +5,25 @@ extern crate rustc; use rustc::lint::{LintArray, LintPass}; -#[macro_use] -extern crate clippy_lints; - -declare_clippy_lint! { - pub TEST_LINT, - correctness, - "" +declare_tool_lint! { + pub clippy::TEST_LINT, + Warn, + "", + report_in_external_macro: true } -declare_clippy_lint! { - pub TEST_LINT_REGISTERED, - correctness, - "" +declare_tool_lint! { + pub clippy::TEST_LINT_REGISTERED, + Warn, + "", + report_in_external_macro: true } -declare_clippy_lint! { - pub TEST_LINT_REGISTERED_ONLY_IMPL, - correctness, - "" +declare_tool_lint! { + pub clippy::TEST_LINT_REGISTERED_ONLY_IMPL, + Warn, + "", + report_in_external_macro: true } pub struct Pass; diff --git a/tests/ui/lint_without_lint_pass.stderr b/tests/ui/lint_without_lint_pass.stderr index 0559cee70efb..7ee9d96c16a2 100644 --- a/tests/ui/lint_without_lint_pass.stderr +++ b/tests/ui/lint_without_lint_pass.stderr @@ -1,10 +1,11 @@ error: the lint `TEST_LINT` is not added to any `LintPass` - --> $DIR/lint_without_lint_pass.rs:11:1 + --> $DIR/lint_without_lint_pass.rs:8:1 | -LL | / declare_clippy_lint! { -LL | | pub TEST_LINT, -LL | | correctness, -LL | | "" +LL | / declare_tool_lint! { +LL | | pub clippy::TEST_LINT, +LL | | Warn, +LL | | "", +LL | | report_in_external_macro: true LL | | } | |_^ | From acbe224f6ab5fc8abbaf8201788a362d94901b34 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 8 Nov 2019 10:10:08 +0700 Subject: [PATCH 27/28] rustup https://github.com/rust-lang/rust/pull/65916 --- clippy_lints/src/utils/sugg.rs | 6 +++--- clippy_lints/src/write.rs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 4fe41a880cc7..ff874179cfff 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -12,9 +12,9 @@ use std::borrow::Cow; use std::convert::TryInto; use std::fmt::Display; use syntax::ast; -use syntax::parse::token; use syntax::print::pprust::token_kind_to_string; use syntax::source_map::{CharPos, Span}; +use syntax::token; use syntax::util::parser::AssocOp; use syntax_pos::{BytePos, Pos}; @@ -440,7 +440,7 @@ fn associativity(op: &AssocOp) -> Associativity { /// Converts a `hir::BinOp` to the corresponding assigning binary operator. fn hirbinop2assignop(op: hir::BinOp) -> AssocOp { - use syntax::parse::token::BinOpToken::*; + use syntax::token::BinOpToken::*; AssocOp::AssignOp(match op.node { hir::BinOpKind::Add => Plus, @@ -468,7 +468,7 @@ fn hirbinop2assignop(op: hir::BinOp) -> AssocOp { /// Converts an `ast::BinOp` to the corresponding assigning binary operator. fn astbinop2assignop(op: ast::BinOp) -> AssocOp { use syntax::ast::BinOpKind::*; - use syntax::parse::token::BinOpToken; + use syntax::token::BinOpToken; AssocOp::AssignOp(match op.node { Add => BinOpToken::Plus, diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 989d2f374a84..9a7cfb677108 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -4,7 +4,8 @@ use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_errors::Applicability; use std::borrow::Cow; use syntax::ast::*; -use syntax::parse::{parser, token}; +use syntax::parse::parser; +use syntax::token; use syntax::tokenstream::TokenStream; use syntax_pos::{BytePos, Span}; From ff5bf67b94b1ed2009bf9b8fb87e1c14853cea73 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 8 Nov 2019 10:16:43 +0700 Subject: [PATCH 28/28] remove unused warnings --- clippy_lints/src/exit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 7220833b9f23..986c3d97b58b 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -32,8 +32,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { if let Some(def_id) = qpath_res(cx, path, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::EXIT); then { - let mut parent = cx.tcx.hir().get_parent_item(e.hir_id); - if let Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent) { + let parent = cx.tcx.hir().get_parent_item(e.hir_id); + if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent) { // If the next item up is a function we check if it is an entry point // and only then emit a linter warning let def_id = cx.tcx.hir().local_def_id(parent);