about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMateusz Gacek <96mateusz.gacek@gmail.com>2021-03-18 19:45:13 +0100
committerMateusz Gacek <96mateusz.gacek@gmail.com>2021-03-19 20:29:55 +0100
commit1f2d01641d6ef2f283265eb603c7d231692b6a89 (patch)
treeb8364d07ef3b92fcda346253c2bea189b5c7d61f
parent032cdfe043c5c9d00530dc18005066a184f3d46e (diff)
downloadrust-1f2d01641d6ef2f283265eb603c7d231692b6a89.tar.gz
rust-1f2d01641d6ef2f283265eb603c7d231692b6a89.zip
wrong_self_convention: Enhance lint message
-rw-r--r--clippy_lints/src/methods/mod.rs8
-rw-r--r--clippy_lints/src/methods/wrong_self_convention.rs19
-rw-r--r--tests/ui/def_id_nocore.stderr2
-rw-r--r--tests/ui/wrong_self_convention.stderr48
-rw-r--r--tests/ui/wrong_self_conventions_mut.stderr4
5 files changed, 42 insertions, 39 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 722effc29b2..a3652c18a78 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -2348,10 +2348,10 @@ impl SelfKind {
     #[must_use]
     fn description(self) -> &'static str {
         match self {
-            Self::Value => "self by value",
-            Self::Ref => "self by reference",
-            Self::RefMut => "self by mutable reference",
-            Self::No => "no self",
+            Self::Value => "`self` by value",
+            Self::Ref => "`self` by reference",
+            Self::RefMut => "`self` by mutable reference",
+            Self::No => "no `self`",
         }
     }
 }
diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs
index bece8f251da..59e683aa9a7 100644
--- a/clippy_lints/src/methods/wrong_self_convention.rs
+++ b/clippy_lints/src/methods/wrong_self_convention.rs
@@ -51,13 +51,16 @@ impl Convention {
 impl fmt::Display for Convention {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
         match *self {
-            Self::Eq(this) => this.fmt(f),
-            Self::StartsWith(this) => this.fmt(f).and_then(|_| '*'.fmt(f)),
-            Self::EndsWith(this) => '*'.fmt(f).and_then(|_| this.fmt(f)),
-            Self::NotEndsWith(this) => '~'.fmt(f).and_then(|_| this.fmt(f)),
-            Self::IsSelfTypeCopy(is_true) => format!("self type is {} Copy", if is_true { "" } else { "not" }).fmt(f),
+            Self::Eq(this) => format!("`{}`", this).fmt(f),
+            Self::StartsWith(this) => format!("`{}*`", this).fmt(f),
+            Self::EndsWith(this) => format!("`*{}`", this).fmt(f),
+            Self::NotEndsWith(this) => format!("`~{}`", this).fmt(f),
+            Self::IsSelfTypeCopy(is_true) => {
+                format!("`self` type is{} `Copy`", if is_true { "" } else { " not" }).fmt(f)
+            },
             Self::ImplementsTrait(is_true) => {
-                format!("Method {} implement a trait", if is_true { "" } else { "do not" }).fmt(f)
+                let (negation, s_suffix) = if is_true { ("", "s") } else { (" does not", "") };
+                format!("Method{} implement{} a trait", negation, s_suffix).fmt(f)
             },
         }
     }
@@ -99,7 +102,7 @@ pub(super) fn check<'tcx>(
                             {
                                 None
                             } else {
-                                Some(format!("`{}`", &conv.to_string()))
+                                Some(conv.to_string())
                             }
                         })
                         .collect::<Vec<_>>()
@@ -107,7 +110,7 @@ pub(super) fn check<'tcx>(
 
                     format!("methods with the following characteristics: ({})", &s)
                 } else {
-                    format!("methods called `{}`", &conventions[0])
+                    format!("methods called {}", &conventions[0])
                 }
             };
 
diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr
index a3e9cc75b08..702684f6b43 100644
--- a/tests/ui/def_id_nocore.stderr
+++ b/tests/ui/def_id_nocore.stderr
@@ -1,4 +1,4 @@
-error: methods called `as_*` usually take self by reference or self by mutable reference
+error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
   --> $DIR/def_id_nocore.rs:26:19
    |
 LL |     pub fn as_ref(self) -> &'static str {
diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr
index 6daa334ed48..1d58a12ac79 100644
--- a/tests/ui/wrong_self_convention.stderr
+++ b/tests/ui/wrong_self_convention.stderr
@@ -1,4 +1,4 @@
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:18:17
    |
 LL |     fn from_i32(self) {}
@@ -7,7 +7,7 @@ LL |     fn from_i32(self) {}
    = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
    = help: consider choosing a less ambiguous name
 
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:24:21
    |
 LL |     pub fn from_i64(self) {}
@@ -15,7 +15,7 @@ LL |     pub fn from_i64(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `as_*` usually take self by reference or self by mutable reference
+error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
   --> $DIR/wrong_self_convention.rs:36:15
    |
 LL |     fn as_i32(self) {}
@@ -23,7 +23,7 @@ LL |     fn as_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `into_*` usually take self by value
+error: methods called `into_*` usually take `self` by value
   --> $DIR/wrong_self_convention.rs:38:17
    |
 LL |     fn into_i32(&self) {}
@@ -31,7 +31,7 @@ LL |     fn into_i32(&self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `is_*` usually take self by reference or no self
+error: methods called `is_*` usually take `self` by reference or no `self`
   --> $DIR/wrong_self_convention.rs:40:15
    |
 LL |     fn is_i32(self) {}
@@ -39,7 +39,7 @@ LL |     fn is_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference
+error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
   --> $DIR/wrong_self_convention.rs:42:15
    |
 LL |     fn to_i32(self) {}
@@ -47,7 +47,7 @@ LL |     fn to_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:44:17
    |
 LL |     fn from_i32(self) {}
@@ -55,7 +55,7 @@ LL |     fn from_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `as_*` usually take self by reference or self by mutable reference
+error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
   --> $DIR/wrong_self_convention.rs:46:19
    |
 LL |     pub fn as_i64(self) {}
@@ -63,7 +63,7 @@ LL |     pub fn as_i64(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `into_*` usually take self by value
+error: methods called `into_*` usually take `self` by value
   --> $DIR/wrong_self_convention.rs:47:21
    |
 LL |     pub fn into_i64(&self) {}
@@ -71,7 +71,7 @@ LL |     pub fn into_i64(&self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `is_*` usually take self by reference or no self
+error: methods called `is_*` usually take `self` by reference or no `self`
   --> $DIR/wrong_self_convention.rs:48:19
    |
 LL |     pub fn is_i64(self) {}
@@ -79,7 +79,7 @@ LL |     pub fn is_i64(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference
+error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
   --> $DIR/wrong_self_convention.rs:49:19
    |
 LL |     pub fn to_i64(self) {}
@@ -87,7 +87,7 @@ LL |     pub fn to_i64(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:50:21
    |
 LL |     pub fn from_i64(self) {}
@@ -95,7 +95,7 @@ LL |     pub fn from_i64(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `as_*` usually take self by reference or self by mutable reference
+error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
   --> $DIR/wrong_self_convention.rs:95:19
    |
 LL |         fn as_i32(self) {}
@@ -103,7 +103,7 @@ LL |         fn as_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `into_*` usually take self by value
+error: methods called `into_*` usually take `self` by value
   --> $DIR/wrong_self_convention.rs:98:25
    |
 LL |         fn into_i32_ref(&self) {}
@@ -111,7 +111,7 @@ LL |         fn into_i32_ref(&self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `is_*` usually take self by reference or no self
+error: methods called `is_*` usually take `self` by reference or no `self`
   --> $DIR/wrong_self_convention.rs:100:19
    |
 LL |         fn is_i32(self) {}
@@ -119,7 +119,7 @@ LL |         fn is_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:104:21
    |
 LL |         fn from_i32(self) {}
@@ -127,7 +127,7 @@ LL |         fn from_i32(self) {}
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `as_*` usually take self by reference or self by mutable reference
+error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
   --> $DIR/wrong_self_convention.rs:119:19
    |
 LL |         fn as_i32(self);
@@ -135,7 +135,7 @@ LL |         fn as_i32(self);
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `into_*` usually take self by value
+error: methods called `into_*` usually take `self` by value
   --> $DIR/wrong_self_convention.rs:122:25
    |
 LL |         fn into_i32_ref(&self);
@@ -143,7 +143,7 @@ LL |         fn into_i32_ref(&self);
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `is_*` usually take self by reference or no self
+error: methods called `is_*` usually take `self` by reference or no `self`
   --> $DIR/wrong_self_convention.rs:124:19
    |
 LL |         fn is_i32(self);
@@ -151,7 +151,7 @@ LL |         fn is_i32(self);
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:128:21
    |
 LL |         fn from_i32(self);
@@ -159,7 +159,7 @@ LL |         fn from_i32(self);
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `into_*` usually take self by value
+error: methods called `into_*` usually take `self` by value
   --> $DIR/wrong_self_convention.rs:146:25
    |
 LL |         fn into_i32_ref(&self);
@@ -167,7 +167,7 @@ LL |         fn into_i32_ref(&self);
    |
    = help: consider choosing a less ambiguous name
 
-error: methods called `from_*` usually take no self
+error: methods called `from_*` usually take no `self`
   --> $DIR/wrong_self_convention.rs:152:21
    |
 LL |         fn from_i32(self);
@@ -175,7 +175,7 @@ LL |         fn from_i32(self);
    |
    = help: consider choosing a less ambiguous name
 
-error: methods with the following characteristics: (`to_*` and `self type is  Copy`) usually take self by value
+error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
   --> $DIR/wrong_self_convention.rs:181:22
    |
 LL |         fn to_u64_v2(&self) -> u64 {
@@ -183,7 +183,7 @@ LL |         fn to_u64_v2(&self) -> u64 {
    |
    = help: consider choosing a less ambiguous name
 
-error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference
+error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
   --> $DIR/wrong_self_convention.rs:190:19
    |
 LL |         fn to_u64(self) -> u64 {
diff --git a/tests/ui/wrong_self_conventions_mut.stderr b/tests/ui/wrong_self_conventions_mut.stderr
index 8095188758c..6ce37c59491 100644
--- a/tests/ui/wrong_self_conventions_mut.stderr
+++ b/tests/ui/wrong_self_conventions_mut.stderr
@@ -1,4 +1,4 @@
-error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference
+error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
   --> $DIR/wrong_self_conventions_mut.rs:15:24
    |
 LL |         pub fn to_many(&mut self) -> Option<&mut [T]> {
@@ -7,7 +7,7 @@ LL |         pub fn to_many(&mut self) -> Option<&mut [T]> {
    = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
    = help: consider choosing a less ambiguous name
 
-error: methods with the following characteristics: (`to_*` and `*_mut`) usually take self by mutable reference
+error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference
   --> $DIR/wrong_self_conventions_mut.rs:23:28
    |
 LL |         pub fn to_many_mut(&self) -> Option<&[T]> {