Skip to content

Commit 022ee7d

Browse files
committed
add notable_traits and is_notable_trait field in import structs
1 parent 9279c65 commit 022ee7d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

crates/hir-def/src/attr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ impl Attrs {
207207
})
208208
}
209209

210+
pub fn has_doc_notable_trait(&self) -> bool {
211+
self.by_key("doc").tt_values().any(|tt| {
212+
tt.delimiter.kind == DelimiterKind::Parenthesis &&
213+
matches!(&*tt.token_trees, [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "notable_trait")
214+
})
215+
}
216+
210217
pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> + '_ {
211218
self.by_key("doc").tt_values().map(DocExpr::parse)
212219
}

crates/hir-def/src/import_map.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub struct ImportInfo {
3131
pub container: ModuleId,
3232
/// Whether this item is annotated with `#[doc(hidden)]`.
3333
pub is_doc_hidden: bool,
34+
/// Whether this item is annoated with `#[doc(hidden)]`
35+
pub is_doc_notable_trait: bool,
3436
/// Whether this item is annotated with `#[unstable(..)]`.
3537
pub is_unstable: bool,
3638
}
@@ -51,6 +53,7 @@ pub struct ImportMap {
5153
/// same name right after each other. This allows us to find all items after the FST gives us
5254
/// the index of the first one.
5355
importables: Vec<ItemInNs>,
56+
notable_traits: Vec<ItemInNs>,
5457
fst: fst::Map<Vec<u8>>,
5558
}
5659

@@ -78,6 +81,18 @@ impl ImportMap {
7881

7982
let map = collect_import_map(db, krate);
8083

84+
let notable_traits: Vec<_> = map
85+
.iter()
86+
.filter_map(|(&item, (info, _))| {
87+
let is_notable_trait = info.iter().any(|info| info.is_doc_notable_trait);
88+
if is_notable_trait {
89+
Some(item)
90+
} else {
91+
None
92+
}
93+
})
94+
.collect();
95+
8196
let mut importables: Vec<_> = map
8297
.iter()
8398
// We've only collected items, whose name cannot be tuple field.
@@ -104,6 +119,7 @@ impl ImportMap {
104119

105120
Arc::new(ImportMap {
106121
map,
122+
notable_traits,
107123
fst: builder.into_map(),
108124
importables: importables.into_iter().map(|(item, _, _)| item).collect(),
109125
})
@@ -160,15 +176,17 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> ImportMapIndex {
160176
ItemInNs::Macros(id) => Some(id.into()),
161177
}
162178
};
163-
let (is_doc_hidden, is_unstable) = attr_id.map_or((false, false), |attr_id| {
164-
let attrs = db.attrs(attr_id);
165-
(attrs.has_doc_hidden(), attrs.is_unstable())
166-
});
179+
let (is_doc_hidden, is_doc_notable_trait, is_unstable) =
180+
attr_id.map_or((false, false, false), |attr_id| {
181+
let attrs = db.attrs(attr_id);
182+
(attrs.has_doc_hidden(), attrs.has_doc_notable_trait(), attrs.is_unstable())
183+
});
167184

168185
let import_info = ImportInfo {
169186
name: name.clone(),
170187
container: module,
171188
is_doc_hidden,
189+
is_doc_notable_trait,
172190
is_unstable,
173191
};
174192

@@ -228,6 +246,7 @@ fn collect_trait_assoc_items(
228246
container: trait_import_info.container,
229247
name: assoc_item_name.clone(),
230248
is_doc_hidden: attrs.has_doc_hidden(),
249+
is_doc_notable_trait: attrs.has_doc_notable_trait(),
231250
is_unstable: attrs.is_unstable(),
232251
};
233252

0 commit comments

Comments
 (0)