From 9a301fd508e96d88b2ef09a31622873c881b6f99 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 4 Jan 2017 18:01:53 -0800 Subject: [PATCH] Bump to 0.0.106; Fix false positive in wrong_self_convention (fix #1420) --- CHANGELOG.md | 7 +++++-- Cargo.toml | 4 ++-- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/methods.rs | 8 +++++--- tests/compile-fail/wrong_self_convention.rs | 6 ++++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97bfbfda760..af28d607478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. -## 0.0.105 — 2016-12-15 -* Update to *rustc 1.15.0-nightly (8f02c429a 2016-12-15)* +## 0.0.106 — 2017-01-04 +* Fix FP introduced by rustup in [`wrong_self_convention`] + +## 0.0.105 — 2017-01-04 +* Update to *rustc 1.16.0-nightly (468227129 2017-01-03)* * New lints: [`deref_addrof`], [`double_parens`], [`pub_enum_variant_names`] * Fix suggestion in [`new_without_default`] * FP fix in [`absurd_extreme_comparisons`] diff --git a/Cargo.toml b/Cargo.toml index d614a2389ef..e0a90c49478 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.105" +version = "0.0.106" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -25,7 +25,7 @@ test = false [dependencies] # begin automatic update -clippy_lints = { version = "0.0.105", path = "clippy_lints" } +clippy_lints = { version = "0.0.106", path = "clippy_lints" } # end automatic update [dev-dependencies] diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 2792ca16d62..309340cbc27 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.105" +version = "0.0.106" # end automatic update authors = [ "Manish Goregaokar ", diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 8f1c6e4e9d1..05336d95a2d 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1342,7 +1342,7 @@ enum Convention { ]; -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Debug)] enum SelfKind { Value, Ref, @@ -1358,12 +1358,15 @@ fn matches(self, ty: &hir::Ty, arg: &hir::Arg, self_ty: &hir::Ty, allow_value_fo // Thus, we only need to test equality against the impl self type or if it is an explicit // `Self`. Furthermore, the only possible types for `self: ` are `&Self`, `Self`, `&mut Self`, // and `Box`, including the equivalent types with `Foo`. + let is_actually_self = |ty| is_self_ty(ty) || ty == self_ty; if is_self(arg) { match self { SelfKind::Value => is_actually_self(ty), - SelfKind::Ref | SelfKind::RefMut if allow_value_for_ref => is_actually_self(ty), SelfKind::Ref | SelfKind::RefMut => { + if allow_value_for_ref && is_actually_self(ty) { + return true; + } match ty.node { hir::TyRptr(_, ref mt_ty) => { let mutability_match = if self == SelfKind::Ref { @@ -1372,7 +1375,6 @@ fn matches(self, ty: &hir::Ty, arg: &hir::Arg, self_ty: &hir::Ty, allow_value_fo mt_ty.mutbl == hir::MutMutable }; is_actually_self(&mt_ty.ty) && mutability_match - }, _ => false, } diff --git a/tests/compile-fail/wrong_self_convention.rs b/tests/compile-fail/wrong_self_convention.rs index f20b3d2d17b..d22648c0cdb 100644 --- a/tests/compile-fail/wrong_self_convention.rs +++ b/tests/compile-fail/wrong_self_convention.rs @@ -13,8 +13,10 @@ fn main() {} impl Foo { fn as_i32(self) {} + fn as_u32(&self) {} fn into_i32(self) {} fn is_i32(self) {} + fn is_u32(&self) {} fn to_i32(self) {} fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self @@ -34,9 +36,13 @@ pub fn from_cake(self) {} impl Bar { fn as_i32(self) {} //~ERROR: methods called `as_*` usually take self by reference + fn as_u32(&self) {} fn into_i32(&self) {} //~ERROR: methods called `into_*` usually take self by value + fn into_u32(self) {} fn is_i32(self) {} //~ERROR: methods called `is_*` usually take self by reference + fn is_u32(&self) {} fn to_i32(self) {} //~ERROR: methods called `to_*` usually take self by reference + fn to_u32(&self) {} fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self pub fn as_i64(self) {} //~ERROR: methods called `as_*` usually take self by reference -- 2.44.0