Repository: rust-lang/rust-analyzer (rust)

Issue:
"Implement Missing Members" assist shouldn't ignore `doc(hidden)` methods
<!--
Troubleshooting guide: https://rust-analyzer.github.io/manual.html#troubleshooting
Forum for questions: https://users.rust-lang.org/c/ide/14

Before submitting, please make sure that you're not running into one of these known issues:

 1. on-the-fly diagnostics are mostly unimplemented (`cargo check` diagnostics will be shown when saving a file): #3107

Otherwise please try to provide information which will help us to fix the issue faster. Minimal reproducible examples with few dependencies are especially lovely <3.
-->

**rust-analyzer version**: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via <kbd>Ctrl/⌘</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>) `rust-analyzer 0.0.0 (4586a6b26 2023-10-18)`

**rustc version**: (eg. output of `rustc -V`) rustc 1.73.0 (cc66ad468 2023-10-03)

**relevant settings**: (eg. client settings, or environment variables like `CARGO`, `RUSTC`, `RUSTUP_HOME` or `CARGO_HOME`)

I'm trying to implement [`prost::Message`](https://docs.rs/prost/0.12.1/prost/trait.Message.html) for a type and using `Implement Missing Members` to generate the methods I need to actually write. It's missing the [two `doc(hidden)` methods](https://docs.rs/prost/0.12.1/src/prost/message.rs.html#23) on the trait.

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"alibektas"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->

Pull request description:
fix: Ignore doc(hidden) attr if no body is present
fixes #15782 

Patch:
diff --git a/Cargo.lock b/Cargo.lock
index fcb188c0df..0a3d38645f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1454,12 +1454,12 @@ dependencies = [
 
 [[package]]
 name = "ra-ap-rustc_abi"
-version = "0.18.0"
+version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7082716cb2bbcd8b5f062fe950cbbc87f3aba022d6da4168db35af6732a7f15d"
+checksum = "a51b7a02377b3246ec5c095b852b5cf1678bd9ed6b572b2a79efbf7ad711c292"
 dependencies = [
  "bitflags 1.3.2",
- "ra-ap-rustc_index 0.18.0",
+ "ra-ap-rustc_index",
  "tracing",
 ]
 
@@ -1473,16 +1473,6 @@ dependencies = [
  "smallvec",
 ]
 
-[[package]]
-name = "ra-ap-rustc_index"
-version = "0.18.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19e14b1fc835d6992b128a03a3f3a8365ba9f03e1c656a1670305f63f30d786d"
-dependencies = [
- "arrayvec",
- "smallvec",
-]
-
 [[package]]
 name = "ra-ap-rustc_lexer"
 version = "0.14.0"
@@ -1493,24 +1483,14 @@ dependencies = [
  "unicode-xid",
 ]
 
-[[package]]
-name = "ra-ap-rustc_lexer"
-version = "0.18.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1762abb25eb1e37c1823f62b5da0821bbcd870812318db084c9516c2f78d2dcd"
-dependencies = [
- "unicode-properties",
- "unicode-xid",
-]
-
 [[package]]
 name = "ra-ap-rustc_parse_format"
 version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "207b5ac1a21d4926695e03b605ffb9f63d4968e0488e9197c04c512c37303aa7"
 dependencies = [
- "ra-ap-rustc_index 0.14.0",
- "ra-ap-rustc_lexer 0.14.0",
+ "ra-ap-rustc_index",
+ "ra-ap-rustc_lexer",
 ]
 
 [[package]]
@@ -1634,8 +1614,8 @@ name = "rustc-dependencies"
 version = "0.0.0"
 dependencies = [
  "ra-ap-rustc_abi",
- "ra-ap-rustc_index 0.18.0",
- "ra-ap-rustc_lexer 0.18.0",
+ "ra-ap-rustc_index",
+ "ra-ap-rustc_lexer",
  "ra-ap-rustc_parse_format",
 ]
 
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs
index c5c4afa30f..af204e44e6 100644
--- a/crates/base-db/src/lib.rs
+++ b/crates/base-db/src/lib.rs
@@ -75,7 +75,7 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
     #[salsa::input]
     fn crate_graph(&self) -> Arc<CrateGraph>;
 
-    /// The proc macros.
+    /// The crate graph.
     #[salsa::input]
     fn proc_macros(&self) -> Arc<ProcMacros>;
 }
diff --git a/crates/hir-def/src/data/adt.rs b/crates/hir-def/src/data/adt.rs
index b163112db9..76c8d9a0c3 100644
--- a/crates/hir-def/src/data/adt.rs
+++ b/crates/hir-def/src/data/adt.rs
@@ -178,7 +178,7 @@ fn parse_repr_tt(tt: &Subtree) -> Option<ReprOptions> {
         }
     }
 
-    Some(ReprOptions { int, align: max_align, pack: min_pack, flags, field_shuffle_seed: 0 })
+    Some(ReprOptions { int, align: max_align, pack: min_pack, flags })
 }
 
 impl StructData {
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index cf3ff62fc6..ac171026d5 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -1,6 +1,6 @@
 //! HirDisplay implementations for various hir types.
 use hir_def::{
-    data::adt::{StructKind, VariantData},
+    data::adt::VariantData,
     generics::{
         TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
     },
@@ -163,40 +163,7 @@ impl HirDisplay for Struct {
         write!(f, "{}", self.name(f.db).display(f.db.upcast()))?;
         let def_id = GenericDefId::AdtId(AdtId::StructId(self.id));
         write_generic_params(def_id, f)?;
-
-        let variant_data = self.variant_data(f.db);
-        if let StructKind::Tuple = variant_data.kind() {
-            f.write_char('(')?;
-            let mut it = variant_data.fields().iter().peekable();
-
-            while let Some((id, _)) = it.next() {
-                let field = Field { parent: (*self).into(), id };
-                field.ty(f.db).hir_fmt(f)?;
-                if it.peek().is_some() {
-                    f.write_str(", ")?;
-                }
-            }
-
-            f.write_str(");")?;
-        }
-
         write_where_clause(def_id, f)?;
-
-        if let StructKind::Record = variant_data.kind() {
-            let fields = self.fields(f.db);
-            if fields.is_empty() {
-                f.write_str(" {}")?;
-            } else {
-                f.write_str(" {\n")?;
-                for field in self.fields(f.db) {
-                    f.write_str("    ")?;
-                    field.hir_fmt(f)?;
-                    f.write_str(",\n")?;
-                }
-                f.write_str("}")?;
-            }
-        }
-
         Ok(())
     }
 }
@@ -209,18 +176,6 @@ impl HirDisplay for Enum {
         let def_id = GenericDefId::AdtId(AdtId::EnumId(self.id));
         write_generic_params(def_id, f)?;
         write_where_clause(def_id, f)?;
-
-        let variants = self.variants(f.db);
-        if !variants.is_empty() {
-            f.write_str(" {\n")?;
-            for variant in variants {
-                f.write_str("    ")?;
-                variant.hir_fmt(f)?;
-                f.write_str(",\n")?;
-            }
-            f.write_str("}")?;
-        }
-
         Ok(())
     }
 }
@@ -233,18 +188,6 @@ impl HirDisplay for Union {
         let def_id = GenericDefId::AdtId(AdtId::UnionId(self.id));
         write_generic_params(def_id, f)?;
         write_where_clause(def_id, f)?;
-
-        let fields = self.fields(f.db);
-        if !fields.is_empty() {
-            f.write_str(" {\n")?;
-            for field in self.fields(f.db) {
-                f.write_str("    ")?;
-                field.hir_fmt(f)?;
-                f.write_str(",\n")?;
-            }
-            f.write_str("}")?;
-        }
-
         Ok(())
     }
 }
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 c0e5429a22..410c623109 100644
--- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
@@ -2245,6 +2245,37 @@ impl b::LocalTrait for B {
     fn no_skip_default_2() -> Option<()> {
         todo!()
     }
+}
+            "#,
+        )
+    }
+
+    #[test]
+    fn doc_hidden_nondefault_member() {
+        check_assist(
+            add_missing_impl_members,
+            r#"
+//- /lib.rs crate:b new_source_root:local
+trait LocalTrait {
+    #[doc(hidden)]
+    fn no_skip_non_default() -> Option<()>;
+
+    #[doc(hidden)]
+    fn skip_default() -> Option<()> {
+        todo!()
+    }
+}
+
+//- /main.rs crate:a deps:b
+struct B;
+impl b::Loc$0alTrait for B {}
+            "#,
+            r#"
+struct B;
+impl b::LocalTrait for B {
+    fn no_skip_non_default() -> Option<()> {
+        ${0:todo!()}
+    }
 }
             "#,
         )
diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs
index a262570d94..f51e99a914 100644
--- a/crates/ide-assists/src/utils.rs
+++ b/crates/ide-assists/src/utils.rs
@@ -106,8 +106,18 @@ pub fn filter_assoc_items(
         .iter()
         .copied()
         .filter(|assoc_item| {
-            !(ignore_items == IgnoreAssocItems::DocHiddenAttrPresent
-                && assoc_item.attrs(sema.db).has_doc_hidden())
+            if ignore_items == IgnoreAssocItems::DocHiddenAttrPresent
+                && assoc_item.attrs(sema.db).has_doc_hidden()
+            {
+                if let hir::AssocItem::Function(f) = assoc_item {
+                    if !f.has_body(sema.db) {
+                        return true;
+                    }
+                }
+                return false;
+            }
+
+            return true;
         })
         // Note: This throws away items with no source.
         .filter_map(|assoc_item| {
diff --git a/crates/rustc-dependencies/Cargo.toml b/crates/rustc-dependencies/Cargo.toml
index a313507bff..7ead3d84cd 100644
--- a/crates/rustc-dependencies/Cargo.toml
+++ b/crates/rustc-dependencies/Cargo.toml
@@ -11,10 +11,10 @@ authors.workspace = true
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-ra-ap-rustc_lexer = { version = "0.18.0" }
+ra-ap-rustc_lexer = { version = "0.14.0" }
 ra-ap-rustc_parse_format = { version = "0.14.0", default-features = false }
-ra-ap-rustc_index = { version = "0.18.0", default-features = false }
-ra-ap-rustc_abi = { version = "0.18.0", default-features = false }
+ra-ap-rustc_index = { version = "0.14.0", default-features = false }
+ra-ap-rustc_abi = { version = "0.14.0", default-features = false }
 
 [features]
 in-rust-tree = []


Test patch:
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index d3d492f3fd..e54bc48d55 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -1136,9 +1136,7 @@ impl Thing {
                 ```
 
                 ```rust
-                struct Thing {
-                    x: u32,
-                }
+                struct Thing
                 ```
             "#]],
     );
@@ -1157,9 +1155,7 @@ impl Thing {
                 ```
 
                 ```rust
-                struct Thing {
-                    x: u32,
-                }
+                struct Thing
                 ```
             "#]],
     );
@@ -1178,9 +1174,7 @@ impl Thing {
                 ```
 
                 ```rust
-                enum Thing {
-                    A,
-                }
+                enum Thing
                 ```
             "#]],
     );
@@ -1199,9 +1193,7 @@ impl Thing {
                 ```
 
                 ```rust
-                enum Thing {
-                    A,
-                }
+                enum Thing
                 ```
             "#]],
     );
@@ -2013,10 +2005,7 @@ fn test_hover_layout_of_enum() {
             ```
 
             ```rust
-            enum Foo {
-                Variant1(u8, u16),
-                Variant2(i32, u8, i64),
-            } // size = 16 (0x10), align = 8, niches = 254
+            enum Foo // size = 16 (0x10), align = 8, niches = 254
             ```
         "#]],
     );
@@ -2357,7 +2346,7 @@ fn main() { let s$0t = S{ f1:0 }; }
                                     focus_range: 7..8,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S {\n    f1: u32,\n}",
+                                    description: "struct S",
                                 },
                             },
                         ],
@@ -2390,7 +2379,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
                                     focus_range: 24..25,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S<T> {\n    f1: T,\n}",
+                                    description: "struct S<T>",
                                 },
                             },
                             HoverGotoTypeData {
@@ -2403,7 +2392,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
                                     focus_range: 7..10,
                                     name: "Arg",
                                     kind: Struct,
-                                    description: "struct Arg(u32);",
+                                    description: "struct Arg",
                                 },
                             },
                         ],
@@ -2449,7 +2438,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
                                     focus_range: 24..25,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S<T> {\n    f1: T,\n}",
+                                    description: "struct S<T>",
                                 },
                             },
                             HoverGotoTypeData {
@@ -2462,7 +2451,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
                                     focus_range: 7..10,
                                     name: "Arg",
                                     kind: Struct,
-                                    description: "struct Arg(u32);",
+                                    description: "struct Arg",
                                 },
                             },
                         ],
@@ -2498,7 +2487,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
                                 focus_range: 7..8,
                                 name: "A",
                                 kind: Struct,
-                                description: "struct A(u32);",
+                                description: "struct A",
                             },
                         },
                         HoverGotoTypeData {
@@ -2511,7 +2500,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
                                 focus_range: 22..23,
                                 name: "B",
                                 kind: Struct,
-                                description: "struct B(u32);",
+                                description: "struct B",
                             },
                         },
                         HoverGotoTypeData {
@@ -2525,7 +2514,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
                                 name: "C",
                                 kind: Struct,
                                 container_name: "M",
-                                description: "pub struct C(u32);",
+                                description: "pub struct C",
                             },
                         },
                     ],
@@ -2715,7 +2704,7 @@ fn main() { let s$0t = foo(); }
                                     focus_range: 39..41,
                                     name: "S1",
                                     kind: Struct,
-                                    description: "struct S1 {}",
+                                    description: "struct S1",
                                 },
                             },
                             HoverGotoTypeData {
@@ -2728,7 +2717,7 @@ fn main() { let s$0t = foo(); }
                                     focus_range: 52..54,
                                     name: "S2",
                                     kind: Struct,
-                                    description: "struct S2 {}",
+                                    description: "struct S2",
                                 },
                             },
                         ],
@@ -2819,7 +2808,7 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {}
                                     focus_range: 36..37,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S {}",
+                                    description: "struct S",
                                 },
                             },
                         ],
@@ -2919,7 +2908,7 @@ fn foo(ar$0g: &impl Foo<S>) {}
                                     focus_range: 23..24,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S {}",
+                                    description: "struct S",
                                 },
                             },
                         ],
@@ -2956,7 +2945,7 @@ fn main() { let s$0t = foo(); }
                                     focus_range: 49..50,
                                     name: "B",
                                     kind: Struct,
-                                    description: "struct B<T> {}",
+                                    description: "struct B<T>",
                                 },
                             },
                             HoverGotoTypeData {
@@ -3045,7 +3034,7 @@ fn foo(ar$0g: &dyn Foo<S>) {}
                                     focus_range: 23..24,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S {}",
+                                    description: "struct S",
                                 },
                             },
                         ],
@@ -3093,7 +3082,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
                                     focus_range: 50..51,
                                     name: "B",
                                     kind: Struct,
-                                    description: "struct B<T> {}",
+                                    description: "struct B<T>",
                                 },
                             },
                             HoverGotoTypeData {
@@ -3119,7 +3108,7 @@ fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
                                     focus_range: 65..66,
                                     name: "S",
                                     kind: Struct,
-                                    description: "struct S {}",
+                                    description: "struct S",
                                 },
                             },
                         ],
@@ -3346,7 +3335,7 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
             ```
 
             ```rust
-            struct ST<const C: usize = 1, T = Foo>(T);
+            struct ST<const C: usize = 1, T = Foo>
             ```
         "#]],
     );
@@ -3367,7 +3356,7 @@ struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
             ```
 
             ```rust
-            struct ST<const C: usize = {const}, T = Foo>(T);
+            struct ST<const C: usize = {const}, T = Foo>
             ```
         "#]],
     );
@@ -3389,7 +3378,7 @@ struct S$0T<const C: usize = VAL, T = Foo>(T);
             ```
 
             ```rust
-            struct ST<const C: usize = VAL, T = Foo>(T);
+            struct ST<const C: usize = VAL, T = Foo>
             ```
         "#]],
     );
@@ -5946,7 +5935,7 @@ pub struct Foo(i32);
             ```
 
             ```rust
-            pub struct Foo(i32); // size = 4, align = 4
+            pub struct Foo // size = 4, align = 4
             ```
 
             ---