From da14435ed2b97a96dc6df3f84df851c001a3e93f Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Sun, 15 Oct 2017 15:39:47 -0400 Subject: [PATCH 1/4] Updated clippy to account for changes from rust-lang/rust#44766 --- clippy_lints/src/lifetimes.rs | 4 ++-- clippy_lints/src/methods.rs | 4 ++-- clippy_lints/src/new_without_default.rs | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 16d636c68ab6..7cfe2c1cdcbc 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LifetimePass { fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) { if let ImplItemKind::Method(ref sig, id) = item.node { - check_fn_inner(cx, &sig.decl, Some(id), &sig.generics, item.span); + check_fn_inner(cx, &sig.decl, Some(id), &item.generics, item.span); } } @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LifetimePass { TraitMethod::Required(_) => None, TraitMethod::Provided(id) => Some(id), }; - check_fn_inner(cx, &sig.decl, body, &sig.generics, item.span); + check_fn_inner(cx, &sig.decl, body, &item.generics, item.span); } } } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index d986a548576b..fd888d23f8cc 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -719,7 +719,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if name == method_name && sig.decl.inputs.len() == n_args && out_type.matches(&sig.decl.output) && - self_kind.matches(first_arg_ty, first_arg, self_ty, false, &sig.generics) { + self_kind.matches(first_arg_ty, first_arg, self_ty, false, &implitem.generics) { span_lint(cx, SHOULD_IMPLEMENT_TRAIT, implitem.span, &format!( "defining a method called `{}` on this type; consider implementing \ the `{}` trait or choosing a less ambiguous name", name, trait_name)); @@ -733,7 +733,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { for &(ref conv, self_kinds) in &CONVENTIONS { if_let_chain! {[ conv.check(&name.as_str()), - !self_kinds.iter().any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy, &sig.generics)), + !self_kinds.iter().any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics)), ], { let lint = if item.vis == hir::Visibility::Public { WRONG_PUB_SELF_CONVENTION diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 1c5524af68e7..a566941a5029 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -108,12 +108,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { // can't be implemented by default return; } - if !sig.generics.ty_params.is_empty() { - // when the result of `new()` depends on a type parameter we should not require - // an - // impl of `Default` - return; - } + //TODO: There is no sig.generics anymore and I don't know how to fix this. + //if !sig.generics.ty_params.is_empty() { + // // when the result of `new()` depends on a type parameter we should not require + // // an + // // impl of `Default` + // return; + //} if decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { let self_ty = cx.tcx .type_of(cx.tcx.hir.local_def_id(cx.tcx.hir.get_parent(id))); From 09143cdaf08c835bd0111e5b10694088e7fe4b8b Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 28 Oct 2017 14:52:45 -0400 Subject: [PATCH 2/4] Update tests; make it work with generics on context --- clippy_lints/src/new_without_default.rs | 13 ++++++------- tests/ui/mut_mut.stderr | 24 ------------------------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 2fc6695fa8b7..e28d077f9999 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -108,13 +108,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { // can't be implemented by default return; } - //TODO: There is no sig.generics anymore and I don't know how to fix this. - //if !sig.generics.ty_params.is_empty() { - // // when the result of `new()` depends on a type parameter we should not require - // // an - // // impl of `Default` - // return; - //} + if !cx.generics.expect("method must have generics").ty_params.is_empty() { + // when the result of `new()` depends on a type parameter we should not require + // an + // impl of `Default` + return; + } if decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { let self_ty = cx.tcx .type_of(cx.tcx.hir.local_def_id(cx.tcx.hir.get_parent(id))); diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index 31f9178aa272..8bfc2fc8a5cc 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -39,12 +39,6 @@ error: generally you want to avoid `&mut &mut _` if possible 30 | let y : &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^^^ -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:30:17 - | -30 | let y : &mut &mut u32 = &mut &mut 2; - | ^^^^^^^^^^^^^ - error: generally you want to avoid `&mut &mut _` if possible --> $DIR/mut_mut.rs:35:38 | @@ -63,21 +57,3 @@ error: generally you want to avoid `&mut &mut _` if possible 35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^ -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:35:17 - | -35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:35:22 - | -35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:35:22 - | -35 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^ - From f76225e3887170743403af9204887918b5db5a80 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 29 Oct 2017 05:21:25 -0400 Subject: [PATCH 3/4] Handle TyForeign --- clippy_lints/src/utils/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index e0ed66894580..a3b0e928aa20 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -924,6 +924,7 @@ pub fn opt_def_id(def: Def) -> Option { Def::TyAlias(id) | Def::AssociatedTy(id) | Def::TyParam(id) | + Def::TyForeign(id) | Def::Struct(id) | Def::StructCtor(id, ..) | Def::Union(id) | From a69764d93d8fc6f9d6a668e8a24d0cb936e7fe70 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 29 Oct 2017 05:30:33 -0400 Subject: [PATCH 4/4] Bump to 0.0.167 (rustup to rustc 1.23.0-nightly (90ef3372e 2017-10-29)) --- CHANGELOG.md | 9 +++++++++ Cargo.toml | 4 ++-- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/lib.rs | 12 +++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6f91e3bb65..8c7447966818 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.167 +* Rustup to *rustc 1.23.0-nightly (90ef3372e 2017-10-29)* +* New lints: [`const_static_lifetime`], [`erasing_op`], [`fallible_impl_from`], [`println_empty_string`], [`useless_asref`] + ## 0.0.166 * Rustup to *rustc 1.22.0-nightly (b7960878b 2017-10-18)* * New lints: [`explicit_write`], [`identity_conversion`], [`implicit_hasher`], [`invalid_ref`], [`option_map_or_none`], [`range_minus_one`], [`range_plus_one`], [`transmute_int_to_bool`], [`transmute_int_to_char`], [`transmute_int_to_float`] @@ -486,6 +490,7 @@ All notable changes to this project will be documented in this file. [`cmp_null`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#cmp_null [`cmp_owned`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#cmp_owned [`collapsible_if`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#collapsible_if +[`const_static_lifetime`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#const_static_lifetime [`crosspointer_transmute`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#crosspointer_transmute [`cyclomatic_complexity`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#cyclomatic_complexity [`deprecated_semver`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#deprecated_semver @@ -504,6 +509,7 @@ All notable changes to this project will be documented in this file. [`enum_glob_use`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#enum_glob_use [`enum_variant_names`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#enum_variant_names [`eq_op`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#eq_op +[`erasing_op`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#erasing_op [`eval_order_dependence`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#eval_order_dependence [`expl_impl_clone_on_copy`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy [`explicit_counter_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_counter_loop @@ -511,6 +517,7 @@ All notable changes to this project will be documented in this file. [`explicit_iter_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_iter_loop [`explicit_write`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_write [`extend_from_slice`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#extend_from_slice +[`fallible_impl_from`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#fallible_impl_from [`filter_map`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#filter_map [`filter_next`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#filter_next [`float_arithmetic`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#float_arithmetic @@ -611,6 +618,7 @@ All notable changes to this project will be documented in this file. [`precedence`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#precedence [`print_stdout`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#print_stdout [`print_with_newline`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#print_with_newline +[`println_empty_string`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#println_empty_string [`ptr_arg`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ptr_arg [`pub_enum_variant_names`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#pub_enum_variant_names [`range_minus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_minus_one @@ -673,6 +681,7 @@ All notable changes to this project will be documented in this file. [`use_debug`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#use_debug [`use_self`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#use_self [`used_underscore_binding`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#used_underscore_binding +[`useless_asref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_asref [`useless_attribute`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_attribute [`useless_format`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_format [`useless_let_if_seq`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_let_if_seq diff --git a/Cargo.toml b/Cargo.toml index 35e078d65779..6e6704bb6b23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.166" +version = "0.0.167" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -37,7 +37,7 @@ path = "src/driver.rs" [dependencies] # begin automatic update -clippy_lints = { version = "0.0.166", path = "clippy_lints" } +clippy_lints = { version = "0.0.167", path = "clippy_lints" } # end automatic update cargo_metadata = "0.2" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 2dcac941c09f..ed0e24306363 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.166" +version = "0.0.167" # end automatic update authors = [ "Manish Goregaokar ", diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1cd3479f11d7..18361f54d64e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -93,12 +93,13 @@ pub mod entry; pub mod enum_clike; pub mod enum_glob_use; pub mod enum_variants; -pub mod erasing_op; pub mod eq_op; +pub mod erasing_op; pub mod escape; pub mod eta_reduction; pub mod eval_order_dependence; pub mod explicit_write; +pub mod fallible_impl_from; pub mod format; pub mod formatting; pub mod functions; @@ -106,7 +107,6 @@ pub mod identity_conversion; pub mod identity_op; pub mod if_let_redundant_pattern_matching; pub mod if_not_else; -pub mod fallible_impl_from; pub mod infinite_iter; pub mod int_plus_one; pub mod invalid_ref; @@ -209,7 +209,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { let mut store = reg.sess.lint_store.borrow_mut(); store.register_removed( "should_assert_eq", - "`assert!()` will be more flexible with RFC 2011" + "`assert!()` will be more flexible with RFC 2011", ); store.register_removed( "extend_from_slice", @@ -360,11 +360,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_lint_group("clippy_pedantic", vec![ booleans::NONMINIMAL_BOOL, - const_static_lifetime::CONST_STATIC_LIFETIME, empty_enum::EMPTY_ENUM, enum_glob_use::ENUM_GLOB_USE, enum_variants::PUB_ENUM_VARIANT_NAMES, enum_variants::STUTTER, + fallible_impl_from::FALLIBLE_IMPL_FROM, if_not_else::IF_NOT_ELSE, infinite_iter::MAYBE_INFINITE_ITER, int_plus_one::INT_PLUS_ONE, @@ -423,6 +423,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { booleans::LOGIC_BUG, bytecount::NAIVE_BYTECOUNT, collapsible_if::COLLAPSIBLE_IF, + const_static_lifetime::CONST_STATIC_LIFETIME, copies::IF_SAME_THEN_ELSE, copies::IFS_SAME_COND, copies::MATCH_SAME_ARMS, @@ -441,6 +442,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { enum_variants::MODULE_INCEPTION, eq_op::EQ_OP, eq_op::OP_REF, + erasing_op::ERASING_OP, escape::BOXED_LOCAL, eta_reduction::REDUNDANT_CLOSURE, eval_order_dependence::DIVERGING_SUB_EXPRESSION, @@ -455,7 +457,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { identity_conversion::IDENTITY_CONVERSION, identity_op::IDENTITY_OP, if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING, - fallible_impl_from::FALLIBLE_IMPL_FROM, infinite_iter::INFINITE_ITER, invalid_ref::INVALID_REF, is_unit_expr::UNIT_EXPR, @@ -509,6 +510,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { methods::SINGLE_CHAR_PATTERN, methods::STRING_EXTEND_CHARS, methods::TEMPORARY_CSTRING_AS_PTR, + methods::USELESS_ASREF, methods::WRONG_SELF_CONVENTION, minmax::MIN_MAX, misc::CMP_NAN,