Skip to content

Commit 7cca4e5

Browse files
committed
Auto merge of rust-lang#15854 - alibektas:15782/relax_hidden_attr, r=lnicola
fix: Ignore doc(hidden) attr if no body is present fixes rust-lang#15782
2 parents 5afaf68 + b0101da commit 7cca4e5

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

crates/ide-assists/src/handlers/add_missing_impl_members.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,37 @@ impl b::LocalTrait for B {
22452245
fn no_skip_default_2() -> Option<()> {
22462246
todo!()
22472247
}
2248+
}
2249+
"#,
2250+
)
2251+
}
2252+
2253+
#[test]
2254+
fn doc_hidden_nondefault_member() {
2255+
check_assist(
2256+
add_missing_impl_members,
2257+
r#"
2258+
//- /lib.rs crate:b new_source_root:local
2259+
trait LocalTrait {
2260+
#[doc(hidden)]
2261+
fn no_skip_non_default() -> Option<()>;
2262+
2263+
#[doc(hidden)]
2264+
fn skip_default() -> Option<()> {
2265+
todo!()
2266+
}
2267+
}
2268+
2269+
//- /main.rs crate:a deps:b
2270+
struct B;
2271+
impl b::Loc$0alTrait for B {}
2272+
"#,
2273+
r#"
2274+
struct B;
2275+
impl b::LocalTrait for B {
2276+
fn no_skip_non_default() -> Option<()> {
2277+
${0:todo!()}
2278+
}
22482279
}
22492280
"#,
22502281
)

crates/ide-assists/src/utils.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,18 @@ pub fn filter_assoc_items(
106106
.iter()
107107
.copied()
108108
.filter(|assoc_item| {
109-
!(ignore_items == IgnoreAssocItems::DocHiddenAttrPresent
110-
&& assoc_item.attrs(sema.db).has_doc_hidden())
109+
if ignore_items == IgnoreAssocItems::DocHiddenAttrPresent
110+
&& assoc_item.attrs(sema.db).has_doc_hidden()
111+
{
112+
if let hir::AssocItem::Function(f) = assoc_item {
113+
if !f.has_body(sema.db) {
114+
return true;
115+
}
116+
}
117+
return false;
118+
}
119+
120+
return true;
111121
})
112122
// Note: This throws away items with no source.
113123
.filter_map(|assoc_item| {

0 commit comments

Comments
 (0)