about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-07 08:32:06 +0000
committerbors <bors@rust-lang.org>2021-05-07 08:32:06 +0000
commit475666703f813a58c2b9df0b0395cb5439f3fe43 (patch)
tree96900c833218a5888667efe7d1524c101cce2cf6
parent1e582c3a70463288797a8fba14c94c92fa2ff359 (diff)
parentab3094b3dbf0bf6423a9cf0509a170eee89f106e (diff)
downloadrust-475666703f813a58c2b9df0b0395cb5439f3fe43.tar.gz
rust-475666703f813a58c2b9df0b0395cb5439f3fe43.zip
Auto merge of #7182 - mgacek8:wrong_self_convention_to__variant, r=flip1995
For `to_*` variant don't lint in trait impl taking `self` when non-`Copy` type

Lint name: `wrong_self_convention`.
It relaxes rules for `to_*` variant, so it doesn't lint in trait definitions and implementations anymore.
Although, non-`Copy` type implementing trait's `to_*` method taking
`self` feels not good (consumes ownership, so should be rather named `into_`), it would be better if this case was a pedantic lint (allow-by-default) instead.
More information in the discussion with `@flip1995` [here](https://github.com/rust-lang/rust-clippy/pull/7002#discussion_r627363450)

changelog: `wrong_self_convention`: For `to_*` variant don't lint in trait impl taking `self` when non-`Copy` type
r? `@flip1995`
-rw-r--r--clippy_lints/src/methods/wrong_self_convention.rs2
-rw-r--r--tests/ui/wrong_self_convention2.rs2
-rw-r--r--tests/ui/wrong_self_convention2.stderr11
3 files changed, 2 insertions, 13 deletions
diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs
index 6e2bcb113c2..1773c26c251 100644
--- a/clippy_lints/src/methods/wrong_self_convention.rs
+++ b/clippy_lints/src/methods/wrong_self_convention.rs
@@ -22,7 +22,7 @@ const CONVENTIONS: [(&[Convention], &[SelfKind]); 9] = [
     // Conversion using `to_` can use borrowed (non-Copy types) or owned (Copy types).
     // Source: https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv
     (&[Convention::StartsWith("to_"), Convention::NotEndsWith("_mut"), Convention::IsSelfTypeCopy(false), 
-    Convention::IsTraitItem(false)], &[SelfKind::Ref]),
+    Convention::IsTraitItem(false), Convention::ImplementsTrait(false)], &[SelfKind::Ref]),
     (&[Convention::StartsWith("to_"), Convention::NotEndsWith("_mut"), Convention::IsSelfTypeCopy(true), 
     Convention::IsTraitItem(false), Convention::ImplementsTrait(false)], &[SelfKind::Value]),
 ];
diff --git a/tests/ui/wrong_self_convention2.rs b/tests/ui/wrong_self_convention2.rs
index ae3a740d405..18202ef2989 100644
--- a/tests/ui/wrong_self_convention2.rs
+++ b/tests/ui/wrong_self_convention2.rs
@@ -23,7 +23,7 @@ mod issue6983 {
     }
 
     struct FooNoCopy;
-    // trigger lint
+    // don't trigger
     impl ToU64 for FooNoCopy {
         fn to_u64(self) -> u64 {
             2
diff --git a/tests/ui/wrong_self_convention2.stderr b/tests/ui/wrong_self_convention2.stderr
deleted file mode 100644
index 0ca1a390974..00000000000
--- a/tests/ui/wrong_self_convention2.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference
-  --> $DIR/wrong_self_convention2.rs:28:19
-   |
-LL |         fn to_u64(self) -> u64 {
-   |                   ^^^^
-   |
-   = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
-   = help: consider choosing a less ambiguous name
-
-error: aborting due to previous error
-