summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/impl.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/impl.rs
parentInitial commit. (diff)
downloadrustc-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 'src/tools/clippy/tests/ui/impl.rs')
-rw-r--r--src/tools/clippy/tests/ui/impl.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/impl.rs b/src/tools/clippy/tests/ui/impl.rs
new file mode 100644
index 000000000..aea52a852
--- /dev/null
+++ b/src/tools/clippy/tests/ui/impl.rs
@@ -0,0 +1,67 @@
+#![allow(dead_code, clippy::extra_unused_lifetimes)]
+#![warn(clippy::multiple_inherent_impl)]
+
+struct MyStruct;
+
+impl MyStruct {
+ fn first() {}
+}
+
+impl MyStruct {
+ fn second() {}
+}
+
+impl<'a> MyStruct {
+ fn lifetimed() {}
+}
+
+mod submod {
+ struct MyStruct;
+ impl MyStruct {
+ fn other() {}
+ }
+
+ impl super::MyStruct {
+ fn third() {}
+ }
+}
+
+use std::fmt;
+impl fmt::Debug for MyStruct {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "MyStruct {{ }}")
+ }
+}
+
+// issue #5772
+struct WithArgs<T>(T);
+impl WithArgs<u32> {
+ fn f1() {}
+}
+impl WithArgs<u64> {
+ fn f2() {}
+}
+impl WithArgs<u64> {
+ fn f3() {}
+}
+
+// Ok, the struct is allowed to have multiple impls.
+#[allow(clippy::multiple_inherent_impl)]
+struct Allowed;
+impl Allowed {}
+impl Allowed {}
+impl Allowed {}
+
+struct AllowedImpl;
+#[allow(clippy::multiple_inherent_impl)]
+impl AllowedImpl {}
+// Ok, the first block is skipped by this lint.
+impl AllowedImpl {}
+
+struct OneAllowedImpl;
+impl OneAllowedImpl {}
+#[allow(clippy::multiple_inherent_impl)]
+impl OneAllowedImpl {}
+impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed.
+
+fn main() {}