about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Mcguigan <joshmcg88@gmail.com>2018-10-01 04:47:06 -0700
committerJosh Mcguigan <joshmcg88@gmail.com>2018-10-02 04:47:38 -0700
commitf142098474fbe4d46bd20227ae318adf168302dc (patch)
tree89bcf9a32ca74838cdd70ee95abef9ee2b03a463
parent5f9af5f69c81367e32deae49e5c200826bab0954 (diff)
downloadrust-f142098474fbe4d46bd20227ae318adf168302dc.tar.gz
rust-f142098474fbe4d46bd20227ae318adf168302dc.zip
Correct false positive in wrong_self_convention lint for to_mut
-rw-r--r--clippy_lints/src/methods/mod.rs18
-rw-r--r--tests/ui/wrong_self_convention.rs1
2 files changed, 11 insertions, 8 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 2524152a120..e0d858bd270 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -882,12 +882,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
                 let ty = cx.tcx.type_of(def_id);
                 let is_copy = is_copy(cx, ty);
                 for &(ref conv, self_kinds) in &CONVENTIONS {
-                    if_chain! {
-                        if conv.check(&name.as_str());
+                    if conv.check(&name.as_str()) {
                         if !self_kinds
-                            .iter()
-                            .any(|k| k.matches(cx, first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics));
-                        then {
+                                .iter()
+                                .any(|k| k.matches(cx, first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics)) {
                             let lint = if item.vis.node.is_pub() {
                                 WRONG_PUB_SELF_CONVENTION
                             } else {
@@ -904,6 +902,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
                                                           .collect::<Vec<_>>()
                                                           .join(" or ")));
                         }
+
+                        // Only check the first convention to match (CONVENTIONS should be listed from most to least specific)
+                        break;
                     }
                 }
 
@@ -1183,8 +1184,8 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
                         Applicability::MaybeIncorrect,
                     );
                     db.span_suggestion_with_applicability(
-                        expr.span, 
-                        "or try being explicit about what type to clone", 
+                        expr.span,
+                        "or try being explicit about what type to clone",
                         explicit,
                         Applicability::MaybeIncorrect,
                     );
@@ -2067,12 +2068,13 @@ enum Convention {
 }
 
 #[rustfmt::skip]
-const CONVENTIONS: [(Convention, &[SelfKind]); 6] = [
+const CONVENTIONS: [(Convention, &[SelfKind]); 7] = [
     (Convention::Eq("new"), &[SelfKind::No]),
     (Convention::StartsWith("as_"), &[SelfKind::Ref, SelfKind::RefMut]),
     (Convention::StartsWith("from_"), &[SelfKind::No]),
     (Convention::StartsWith("into_"), &[SelfKind::Value]),
     (Convention::StartsWith("is_"), &[SelfKind::Ref, SelfKind::No]),
+    (Convention::Eq("to_mut"), &[SelfKind::RefMut]),
     (Convention::StartsWith("to_"), &[SelfKind::Ref]),
 ];
 
diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs
index 1e718c1c648..2fb33d08619 100644
--- a/tests/ui/wrong_self_convention.rs
+++ b/tests/ui/wrong_self_convention.rs
@@ -59,4 +59,5 @@ impl Bar {
     fn is_(self) {}
     fn to_(self) {}
     fn from_(self) {}
+    fn to_mut(&mut self) {}
 }