diff options
Diffstat (limited to 'src/tools/clippy/tests/ui/return_self_not_must_use.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/return_self_not_must_use.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/return_self_not_must_use.rs b/src/tools/clippy/tests/ui/return_self_not_must_use.rs new file mode 100644 index 000000000..9b33ad6d3 --- /dev/null +++ b/src/tools/clippy/tests/ui/return_self_not_must_use.rs @@ -0,0 +1,58 @@ +#![crate_type = "lib"] +#![warn(clippy::return_self_not_must_use)] + +#[derive(Clone)] +pub struct Bar; + +pub trait Whatever { + fn what(&self) -> Self; + // There should be no warning here! (returns a reference) + fn what2(&self) -> &Self; +} + +impl Bar { + // There should be no warning here! (note taking a self argument) + pub fn not_new() -> Self { + Self + } + pub fn foo(&self) -> Self { + Self + } + pub fn bar(self) -> Self { + self + } + // There should be no warning here! (private method) + fn foo2(&self) -> Self { + Self + } + // There should be no warning here! (returns a reference) + pub fn foo3(&self) -> &Self { + self + } + // There should be no warning here! (already a `must_use` attribute) + #[must_use] + pub fn foo4(&self) -> Self { + Self + } +} + +impl Whatever for Bar { + // There should be no warning here! (comes from the trait) + fn what(&self) -> Self { + self.foo2() + } + // There should be no warning here! (comes from the trait) + fn what2(&self) -> &Self { + self + } +} + +#[must_use] +pub struct Foo; + +impl Foo { + // There should be no warning here! (`Foo` already implements `#[must_use]`) + fn foo(&self) -> Self { + Self + } +} |