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.rs124
1 files changed, 122 insertions, 2 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 6fa15b28e4..a6693d7d79 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
@@ -907,7 +907,34 @@ impl PartialEq for Foo {
}
#[test]
- fn add_custom_impl_partial_eq_tuple_enum() {
+ fn add_custom_impl_partial_eq_single_variant_tuple_enum() {
+ check_assist(
+ replace_derive_with_manual_impl,
+ r#"
+//- minicore: eq, derive
+#[derive(Partial$0Eq)]
+enum Foo {
+ Bar(String),
+}
+"#,
+ r#"
+enum Foo {
+ Bar(String),
+}
+
+impl PartialEq for Foo {
+ $0fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::Bar(l0), Self::Bar(r0)) => l0 == r0,
+ }
+ }
+}
+"#,
+ )
+ }
+
+ #[test]
+ fn add_custom_impl_partial_eq_partial_tuple_enum() {
check_assist(
replace_derive_with_manual_impl,
r#"
@@ -937,6 +964,99 @@ impl PartialEq for Foo {
}
#[test]
+ fn add_custom_impl_partial_eq_tuple_enum() {
+ check_assist(
+ replace_derive_with_manual_impl,
+ r#"
+//- minicore: eq, derive
+#[derive(Partial$0Eq)]
+enum Foo {
+ Bar(String),
+ Baz(i32),
+}
+"#,
+ r#"
+enum Foo {
+ Bar(String),
+ Baz(i32),
+}
+
+impl PartialEq for Foo {
+ $0fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::Bar(l0), Self::Bar(r0)) => l0 == r0,
+ (Self::Baz(l0), Self::Baz(r0)) => l0 == r0,
+ _ => false,
+ }
+ }
+}
+"#,
+ )
+ }
+
+ #[test]
+ fn add_custom_impl_partial_eq_tuple_enum_generic() {
+ check_assist(
+ replace_derive_with_manual_impl,
+ r#"
+//- minicore: eq, derive
+#[derive(Partial$0Eq)]
+enum Either<T, U> {
+ Left(T),
+ Right(U),
+}
+"#,
+ r#"
+enum Either<T, U> {
+ Left(T),
+ Right(U),
+}
+
+impl<T: PartialEq, U: PartialEq> PartialEq for Either<T, U> {
+ $0fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::Left(l0), Self::Left(r0)) => l0 == r0,
+ (Self::Right(l0), Self::Right(r0)) => l0 == r0,
+ _ => false,
+ }
+ }
+}
+"#,
+ )
+ }
+
+ #[test]
+ fn add_custom_impl_partial_eq_tuple_enum_generic_existing_bounds() {
+ check_assist(
+ replace_derive_with_manual_impl,
+ r#"
+//- minicore: eq, derive
+#[derive(Partial$0Eq)]
+enum Either<T: PartialEq + Error, U: Clone> {
+ Left(T),
+ Right(U),
+}
+"#,
+ r#"
+enum Either<T: PartialEq + Error, U: Clone> {
+ Left(T),
+ Right(U),
+}
+
+impl<T: PartialEq + Error, U: Clone + PartialEq> PartialEq for Either<T, U> {
+ $0fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::Left(l0), Self::Left(r0)) => l0 == r0,
+ (Self::Right(l0), Self::Right(r0)) => l0 == r0,
+ _ => false,
+ }
+ }
+}
+"#,
+ )
+ }
+
+ #[test]
fn add_custom_impl_partial_eq_record_enum() {
check_assist(
replace_derive_with_manual_impl,
@@ -1112,7 +1232,7 @@ struct Foo<T, U> {
bar: U,
}
-impl<T, U> Default for Foo<T, U> {
+impl<T: Default, U: Default> Default for Foo<T, U> {
$0fn default() -> Self {
Self { foo: Default::default(), bar: Default::default() }
}