about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/unconditional_recursion.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-16 15:54:04 +0000
committerbors <bors@rust-lang.org>2024-03-16 15:54:04 +0000
commit28fd269a50a79280e7576986e11081d987072c10 (patch)
tree415a0243e9adde106d9b6ab644addf5d620aee1b /src/tools/clippy/tests/ui/unconditional_recursion.rs
parent2bcca41ad81146744295fada789a2699c72f69ac (diff)
parent046eb84794947d4abfebc0ae329c4f951fef880c (diff)
downloadrust-28fd269a50a79280e7576986e11081d987072c10.tar.gz
rust-28fd269a50a79280e7576986e11081d987072c10.zip
Auto merge of #122510 - flip1995:clippy_backport, r=Mark-Simulacrum
[beta] Clippy backports

Backports included in this PR:

- https://github.com/rust-lang/rust-clippy/pull/12276 Fixing the lint on some platforms before hitting stable
- https://github.com/rust-lang/rust-clippy/pull/12405 Respect MSRV before hitting stable
- https://github.com/rust-lang/rust-clippy/pull/12266 Fixing an (unlikely) ICE
- https://github.com/rust-lang/rust-clippy/pull/12177 Fixing FPs before hitting stable

Each backport on its own might not warrant a backport, but the collection of those are nice QoL fixes for Clippy users, before those bugs hit stable.

All of those commits are already on `master`.

r? `@Mark-Simulacrum`
Diffstat (limited to 'src/tools/clippy/tests/ui/unconditional_recursion.rs')
-rw-r--r--src/tools/clippy/tests/ui/unconditional_recursion.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/unconditional_recursion.rs b/src/tools/clippy/tests/ui/unconditional_recursion.rs
index 7b898a6e0e7..263fdf26d4d 100644
--- a/src/tools/clippy/tests/ui/unconditional_recursion.rs
+++ b/src/tools/clippy/tests/ui/unconditional_recursion.rs
@@ -288,4 +288,63 @@ impl PartialEq for S15<'_> {
     }
 }
 
+mod issue12154 {
+    struct MyBox<T>(T);
+
+    impl<T> std::ops::Deref for MyBox<T> {
+        type Target = T;
+        fn deref(&self) -> &T {
+            &self.0
+        }
+    }
+
+    impl<T: PartialEq> PartialEq for MyBox<T> {
+        fn eq(&self, other: &Self) -> bool {
+            (**self).eq(&**other)
+        }
+    }
+
+    // Not necessarily related to the issue but another FP from the http crate that was fixed with it:
+    // https://docs.rs/http/latest/src/http/header/name.rs.html#1424
+    // We used to simply peel refs from the LHS and RHS, so we couldn't differentiate
+    // between `PartialEq<T> for &T` and `PartialEq<&T> for T` impls.
+    #[derive(PartialEq)]
+    struct HeaderName;
+    impl<'a> PartialEq<&'a HeaderName> for HeaderName {
+        fn eq(&self, other: &&'a HeaderName) -> bool {
+            *self == **other
+        }
+    }
+
+    impl<'a> PartialEq<HeaderName> for &'a HeaderName {
+        fn eq(&self, other: &HeaderName) -> bool {
+            *other == *self
+        }
+    }
+
+    // Issue #12181 but also fixed by the same PR
+    struct Foo;
+
+    impl Foo {
+        fn as_str(&self) -> &str {
+            "Foo"
+        }
+    }
+
+    impl PartialEq for Foo {
+        fn eq(&self, other: &Self) -> bool {
+            self.as_str().eq(other.as_str())
+        }
+    }
+
+    impl<T> PartialEq<T> for Foo
+    where
+        for<'a> &'a str: PartialEq<T>,
+    {
+        fn eq(&self, other: &T) -> bool {
+            (&self.as_str()).eq(other)
+        }
+    }
+}
+
 fn main() {}