Auto merge of #6924 - mgacek8:issue6727_copy_types, r=llogiq
wrong_self_convention: `to_` convention respects `Copy` types fixes #6727 changelog: wrong_self_convention: `to_` convention respects `Copy` types
This commit is contained in:
commit
1d3c539fbb
8 changed files with 157 additions and 103 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ mod lifetimes {
|
|||
|
||||
mod issue2894 {
|
||||
trait IntoBytes {
|
||||
fn to_bytes(&self) -> Vec<u8>;
|
||||
fn to_bytes(self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
// This should not be linted
|
||||
impl IntoBytes for u8 {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
vec![*self]
|
||||
fn to_bytes(self) -> Vec<u8> {
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ mod lifetimes {
|
|||
|
||||
mod issue2894 {
|
||||
trait IntoBytes {
|
||||
fn to_bytes(&self) -> Vec<u8>;
|
||||
fn to_bytes(self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
// This should not be linted
|
||||
impl IntoBytes for u8 {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
vec![*self]
|
||||
fn to_bytes(self) -> Vec<u8> {
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,3 +163,35 @@ mod issue6307 {
|
|||
fn to_mut(&mut self);
|
||||
}
|
||||
}
|
||||
|
||||
mod issue6727 {
|
||||
trait ToU64 {
|
||||
fn to_u64(self) -> u64;
|
||||
fn to_u64_v2(&self) -> u64;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct FooCopy;
|
||||
|
||||
impl ToU64 for FooCopy {
|
||||
fn to_u64(self) -> u64 {
|
||||
1
|
||||
}
|
||||
// trigger lint
|
||||
fn to_u64_v2(&self) -> u64 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
struct FooNoCopy;
|
||||
|
||||
impl ToU64 for FooNoCopy {
|
||||
// trigger lint
|
||||
fn to_u64(self) -> u64 {
|
||||
2
|
||||
}
|
||||
fn to_u64_v2(&self) -> u64 {
|
||||
2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 called `to_*` 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 called `to_*` 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,15 +119,7 @@ LL | fn is_i32(self) {}
|
|||
|
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `to_*` usually take self by reference
|
||||
--> $DIR/wrong_self_convention.rs:102:19
|
||||
|
|
||||
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:104:21
|
||||
|
|
||||
LL | fn from_i32(self) {}
|
||||
|
|
@ -135,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);
|
||||
|
|
@ -143,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);
|
||||
|
|
@ -151,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);
|
||||
|
|
@ -159,15 +151,7 @@ LL | fn is_i32(self);
|
|||
|
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: methods called `to_*` usually take self by reference
|
||||
--> $DIR/wrong_self_convention.rs:126:19
|
||||
|
|
||||
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:128:21
|
||||
|
|
||||
LL | fn from_i32(self);
|
||||
|
|
@ -175,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);
|
||||
|
|
@ -183,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);
|
||||
|
|
@ -191,5 +175,21 @@ 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
|
||||
--> $DIR/wrong_self_convention.rs:181:22
|
||||
|
|
||||
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
|
||||
--> $DIR/wrong_self_convention.rs:190:19
|
||||
|
|
||||
LL | fn to_u64(self) -> u64 {
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider choosing a less ambiguous name
|
||||
|
||||
error: aborting due to 24 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: methods called `to_*` 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 called like this: (`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]> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue