about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYoung-Flash <871946895@qq.com>2024-01-01 11:19:12 +0800
committerYoung-Flash <871946895@qq.com>2024-01-01 11:19:12 +0800
commit4eb3d2e279a6466c78fdfb19710898dc04e9a0f0 (patch)
treebf1146867077f01afc08b35170f354077f35d442
parent613774e33123c4b3acc397c697def7a55e405653 (diff)
downloadrust-4eb3d2e279a6466c78fdfb19710898dc04e9a0f0.tar.gz
rust-4eb3d2e279a6466c78fdfb19710898dc04e9a0f0.zip
test: add test case for redundant_assoc_item quickfix
-rw-r--r--crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs97
1 files changed, 94 insertions, 3 deletions
diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
index 9992a0f82c9..be2a7b9ad2e 100644
--- a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
+++ b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
@@ -115,7 +115,98 @@ fn quickfix_for_redundant_assoc_item(
 
 #[cfg(test)]
 mod tests {
-    use crate::tests::check_diagnostics;
+    use crate::tests::{check_diagnostics, check_fix, check_no_fix};
+
+    #[test]
+    fn quickfix_for_assoc_func() {
+        check_fix(
+            r#"
+trait Marker {
+    fn boo();
+}
+struct Foo;
+impl Marker for Foo {
+    fn$0 bar(_a: i32, _b: String) -> String {}
+    fn boo() {}
+}
+            "#,
+            r#"
+trait Marker {
+    fn bar(_a: i32, _b: String) -> String;
+    fn boo();
+}
+struct Foo;
+impl Marker for Foo {
+    fn bar(_a: i32, _b: String) -> String {}
+    fn boo() {}
+}
+            "#,
+        )
+    }
+
+    #[test]
+    fn quickfix_for_assoc_const() {
+        check_fix(
+            r#"
+trait Marker {
+    fn foo () {}
+}
+struct Foo;
+impl Marker for Foo {
+    const FLAG: bool$0 = false;
+}
+            "#,
+            r#"
+trait Marker {
+    const FLAG: bool;
+    fn foo () {}
+}
+struct Foo;
+impl Marker for Foo {
+    const FLAG: bool = false;
+}
+            "#,
+        )
+    }
+
+    #[test]
+    fn quickfix_for_assoc_type() {
+        check_fix(
+            r#"
+trait Marker {
+}
+struct Foo;
+impl Marker for Foo {
+    type T = i32;$0
+}
+            "#,
+            r#"
+trait Marker {
+    type T;
+}
+struct Foo;
+impl Marker for Foo {
+    type T = i32;
+}
+            "#,
+        )
+    }
+
+    #[test]
+    fn quickfix_dont_work() {
+        check_no_fix(
+            r#"
+            //- /dep.rs crate:dep
+            trait Marker {
+            }
+            //- /main.rs crate:main deps:dep
+            struct Foo;
+            impl dep::Marker for Foo {
+                type T = i32;$0
+            }
+            "#,
+        )
+    }
 
     #[test]
     fn trait_with_default_value() {
@@ -129,12 +220,12 @@ trait Marker {
 struct Foo;
 impl Marker for Foo {
     type T = i32;
-  //^^^^^^^^^^^^^ error: `type T` is not a member of trait `Marker`
+  //^^^^^^^^^^^^^ 💡 error: `type T` is not a member of trait `Marker`
 
     const FLAG: bool = true;
 
     fn bar() {}
-  //^^^^^^^^^^^ error: `fn bar` is not a member of trait `Marker`
+  //^^^^^^^^^^^ 💡 error: `fn bar` is not a member of trait `Marker`
 
     fn boo() {}
 }