diff options
Diffstat (limited to 'src/tools/clippy/tests/ui/unconditional_recursion.rs')
| -rw-r--r-- | src/tools/clippy/tests/ui/unconditional_recursion.rs | 59 |
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() {} |
