diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/wrong_self_convention2.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/tests/ui/wrong_self_convention2.rs | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/wrong_self_convention2.rs b/src/tools/clippy/tests/ui/wrong_self_convention2.rs new file mode 100644 index 000000000..0dcf4743e --- /dev/null +++ b/src/tools/clippy/tests/ui/wrong_self_convention2.rs @@ -0,0 +1,116 @@ +#![warn(clippy::wrong_self_convention)] +#![allow(dead_code)] + +fn main() {} + +mod issue6983 { + pub struct Thing; + pub trait Trait { + fn to_thing(&self) -> Thing; + } + + impl Trait for u8 { + // don't trigger, e.g. `ToString` from `std` requires `&self` + fn to_thing(&self) -> Thing { + Thing + } + } + + trait ToU64 { + fn to_u64(self) -> u64; + } + + struct FooNoCopy; + // don't trigger + impl ToU64 for FooNoCopy { + fn to_u64(self) -> u64 { + 2 + } + } +} + +mod issue7032 { + trait Foo { + fn from_usize(x: usize) -> Self; + } + // don't trigger + impl Foo for usize { + fn from_usize(x: usize) -> Self { + x + } + } +} + +mod issue7179 { + pub struct S(i32); + + impl S { + // don't trigger (`s` is not `self`) + pub fn from_be(s: Self) -> Self { + S(i32::from_be(s.0)) + } + + // lint + pub fn from_be_self(self) -> Self { + S(i32::from_be(self.0)) + } + } + + trait T { + // don't trigger (`s` is not `self`) + fn from_be(s: Self) -> Self; + // lint + fn from_be_self(self) -> Self; + } + + trait Foo: Sized { + fn as_byte_slice(slice: &[Self]) -> &[u8]; + } +} + +mod issue3414 { + struct CellLikeThing<T>(T); + + impl<T> CellLikeThing<T> { + // don't trigger + fn into_inner(this: Self) -> T { + this.0 + } + } + + impl<T> std::ops::Deref for CellLikeThing<T> { + type Target = T; + + fn deref(&self) -> &T { + &self.0 + } + } +} + +// don't trigger +mod issue4546 { + use std::pin::Pin; + + struct S; + impl S { + pub fn as_mut(self: Pin<&mut Self>) {} + + pub fn as_other_thingy(self: Pin<&Self>) {} + + pub fn is_other_thingy(self: Pin<&Self>) {} + + pub fn to_mut(self: Pin<&mut Self>) {} + + pub fn to_other_thingy(self: Pin<&Self>) {} + } +} + +mod issue_8480_8513 { + struct Cat(String); + + impl Cat { + fn is_animal(&mut self) -> bool { + todo!(); + } + } +} |