about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbvanjoi <bohan-zhang@foxmail.com>2022-11-19 19:38:53 +0800
committerbvanjoi <bohan-zhang@foxmail.com>2022-11-19 19:38:53 +0800
commita4f071afd5ebe8a1fc537136f9e823349cdee526 (patch)
treeca54b71c03c2b50bf161be51477a2c0cb4b27f4e
parentac60077ee5d9aa94b60587029322d35d9f218374 (diff)
downloadrust-a4f071afd5ebe8a1fc537136f9e823349cdee526.tar.gz
rust-a4f071afd5ebe8a1fc537136f9e823349cdee526.zip
fix(assists): remove `item_const` which had default value when implement missing members`
-rw-r--r--crates/ide-assists/src/handlers/add_missing_impl_members.rs10
-rw-r--r--crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs2
-rw-r--r--crates/ide-assists/src/utils.rs4
3 files changed, 12 insertions, 4 deletions
diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
index 722302f991e..2b3793659cf 100644
--- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
@@ -196,6 +196,7 @@ trait Foo {
     type Output;
 
     const CONST: usize = 42;
+    const CONST_2: i32;
 
     fn foo(&self);
     fn bar(&self);
@@ -213,6 +214,7 @@ trait Foo {
     type Output;
 
     const CONST: usize = 42;
+    const CONST_2: i32;
 
     fn foo(&self);
     fn bar(&self);
@@ -226,7 +228,7 @@ impl Foo for S {
 
     $0type Output;
 
-    const CONST: usize = 42;
+    const CONST_2: i32;
 
     fn foo(&self) {
         todo!()
@@ -658,6 +660,7 @@ trait Foo {
     type Output;
 
     const CONST: usize = 42;
+    const CONST_2: i32;
 
     fn valid(some: u32) -> bool { false }
     fn foo(some: u32) -> bool;
@@ -669,13 +672,16 @@ trait Foo {
     type Output;
 
     const CONST: usize = 42;
+    const CONST_2: i32;
 
     fn valid(some: u32) -> bool { false }
     fn foo(some: u32) -> bool;
 }
 struct S;
 impl Foo for S {
-    $0fn valid(some: u32) -> bool { false }
+    $0const CONST: usize = 42;
+
+    fn valid(some: u32) -> bool { false }
 }"#,
         )
     }
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 f9ba289ee17..6fa15b28e4e 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
@@ -1019,8 +1019,6 @@ struct Foo {
 impl foo::Bar for Foo {
     $0type Qux;
 
-    const Baz: usize = 42;
-
     const Fez: usize;
 
     fn foo() {
diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs
index 307e6792705..68c31b4f8e9 100644
--- a/crates/ide-assists/src/utils.rs
+++ b/crates/ide-assists/src/utils.rs
@@ -119,6 +119,10 @@ pub fn filter_assoc_items(
                 (default_methods, def.body()),
                 (DefaultMethods::Only, Some(_)) | (DefaultMethods::No, None)
             ),
+            ast::AssocItem::Const(def) => matches!(
+                (default_methods, def.body()),
+                (DefaultMethods::Only, Some(_)) | (DefaultMethods::No, None)
+            ),
             _ => default_methods == DefaultMethods::No,
         })
         .collect::<Vec<_>>()