Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ impl Attrs {
})
}

pub fn has_doc_notable_trait(&self) -> bool {
self.by_key("doc").tt_values().any(|tt| {
tt.delimiter.kind == DelimiterKind::Parenthesis &&
matches!(&*tt.token_trees, [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "notable_trait")
})
}

pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> + '_ {
self.by_key("doc").tt_values().map(DocExpr::parse)
}
Expand Down
29 changes: 25 additions & 4 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct ImportInfo {
pub container: ModuleId,
/// Whether this item is annotated with `#[doc(hidden)]`.
pub is_doc_hidden: bool,
/// Whether this item is annotated with `#[doc(notable_trait)]`
pub is_doc_notable_trait: bool,
/// Whether this item is annotated with `#[unstable(..)]`.
pub is_unstable: bool,
}
Expand All @@ -49,6 +51,7 @@ pub struct ImportMap {
///
/// The [`u32`] is the index into the smallvec in the value of [`Self::item_to_info_map`].
importables: Vec<(ItemInNs, u32)>,
notable_traits: Vec<(ItemInNs, u32)>,
fst: fst::Map<Vec<u8>>,
}

Expand Down Expand Up @@ -79,6 +82,16 @@ impl ImportMap {

let map = Self::collect_import_map(db, krate);

let notable_traits: Vec<_> = map
.iter()
.flat_map(|(&item, (info, _))| {
info.iter().enumerate().map(move |(idx, info)| (item, info, idx as u32))
})
.filter(|(_, info, _)| info.is_doc_notable_trait)
.map(|(item, _, idx)| (item, idx))
.collect();
dbg!(&notable_traits);

let mut importables: Vec<_> = map
.iter()
// We've only collected items, whose name cannot be tuple field so unwrapping is fine.
Expand All @@ -105,6 +118,7 @@ impl ImportMap {
item_to_info_map: map,
fst: builder.into_map(),
importables: importables.into_iter().map(|(item, _, idx)| (item, idx)).collect(),
notable_traits,
})
}

Expand Down Expand Up @@ -158,15 +172,21 @@ impl ImportMap {
ItemInNs::Macros(id) => Some(id.into()),
}
};
let (is_doc_hidden, is_unstable) = attr_id.map_or((false, false), |attr_id| {
let attrs = db.attrs(attr_id);
(attrs.has_doc_hidden(), attrs.is_unstable())
});
let (is_doc_hidden, is_doc_notable_trait, is_unstable) =
attr_id.map_or((false, false, false), |attr_id| {
let attrs = db.attrs(attr_id);
(
attrs.has_doc_hidden(),
attrs.has_doc_notable_trait(),
attrs.is_unstable(),
)
});

let import_info = ImportInfo {
name: name.clone(),
container: module,
is_doc_hidden,
is_doc_notable_trait,
is_unstable,
};

Expand Down Expand Up @@ -226,6 +246,7 @@ impl ImportMap {
container: trait_import_info.container,
name: assoc_item_name.clone(),
is_doc_hidden: attrs.has_doc_hidden(),
is_doc_notable_trait: attrs.has_doc_notable_trait(),
is_unstable: attrs.is_unstable(),
};

Expand Down