Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs')
-rw-r--r--crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs119
1 files changed, 3 insertions, 116 deletions
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
index b04bd6ba09..138c694d49 100644
--- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -693,7 +693,7 @@ struct Foo {
impl PartialOrd for Foo {
$0fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- self.bin.partial_cmp(other.bin)
+ self.bin.partial_cmp(&other.bin)
}
}
"#,
@@ -722,7 +722,7 @@ struct Foo {
impl PartialOrd for Foo {
$0fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- (self.bin, self.bar, self.baz).partial_cmp((other.bin, other.bar, other.baz))
+ (self.bin, self.bar, self.baz).partial_cmp(&(other.bin, other.bar, other.baz))
}
}
"#,
@@ -743,120 +743,7 @@ struct Foo(usize, usize, usize);
impl PartialOrd for Foo {
$0fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- (self.0, self.1, self.2).partial_cmp((other.0, other.1, other.2))
- }
-}
-"#,
- )
- }
-
- #[test]
- fn add_custom_impl_partial_ord_enum() {
- check_assist(
- replace_derive_with_manual_impl,
- r#"
-//- minicore: ord
-#[derive(Partial$0Ord)]
-enum Foo {
- Bin,
- Bar,
- Baz,
-}
-"#,
- r#"
-enum Foo {
- Bin,
- Bar,
- Baz,
-}
-
-impl PartialOrd for Foo {
- $0fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- core::mem::discriminant(self).partial_cmp(core::mem::discriminant(other))
- }
-}
-"#,
- )
- }
-
- #[test]
- fn add_custom_impl_partial_ord_record_enum() {
- check_assist(
- replace_derive_with_manual_impl,
- r#"
-//- minicore: ord
-#[derive(Partial$0Ord)]
-enum Foo {
- Bar {
- bin: String,
- },
- Baz {
- qux: String,
- fez: String,
- },
- Qux {},
- Bin,
-}
-"#,
- r#"
-enum Foo {
- Bar {
- bin: String,
- },
- Baz {
- qux: String,
- fez: String,
- },
- Qux {},
- Bin,
-}
-
-impl PartialOrd for Foo {
- $0fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- match (self, other) {
- (Self::Bar { bin: l_bin }, Self::Bar { bin: r_bin }) => l_bin.partial_cmp(r_bin),
- (Self::Baz { qux: l_qux, fez: l_fez }, Self::Baz { qux: r_qux, fez: r_fez }) => {
- (l_qux, l_fez).partial_cmp((r_qux, r_fez))
- }
- _ => core::mem::discriminant(self).partial_cmp(core::mem::discriminant(other)),
- }
- }
-}
-"#,
- )
- }
-
- #[test]
- fn add_custom_impl_partial_ord_tuple_enum() {
- check_assist(
- replace_derive_with_manual_impl,
- r#"
-//- minicore: ord
-#[derive(Partial$0Ord)]
-enum Foo {
- Bar(String),
- Baz(String, String),
- Qux(),
- Bin,
-}
-"#,
- r#"
-enum Foo {
- Bar(String),
- Baz(String, String),
- Qux(),
- Bin,
-}
-
-impl PartialOrd for Foo {
- $0fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
- match (self, other) {
- (Self::Bar(l0), Self::Bar(r0)) => l0.partial_cmp(r0),
- (Self::Baz(l0, l1), Self::Baz(r0, r1)) => {
- (l0, l1).partial_cmp((r0, r1))
- }
- _ => core::mem::discriminant(self).partial_cmp(core::mem::discriminant(other)),
- }
+ (self.0, self.1, self.2).partial_cmp(&(other.0, other.1, other.2))
}
}
"#,