Refactor ItemLink into its own struct

This commit is contained in:
Joshua Nelson 2020-07-05 22:45:44 -04:00
parent 89ae59a360
commit d5495e2155
2 changed files with 17 additions and 5 deletions

View File

@ -425,10 +425,22 @@ pub struct Attributes {
pub cfg: Option<Arc<Cfg>>,
pub span: Option<rustc_span::Span>,
/// map from Rust paths to resolved defs and potential URL fragments
pub links: Vec<(String, Option<DefId>, Option<String>)>,
pub links: Vec<ItemLink>,
pub inner_docs: bool,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
/// A link that has not yet been rendered.
///
/// This link will be turned into a rendered link by [`Attributes::links`]
pub struct ItemLink {
/// The original link written in the markdown
pub(crate) link: String,
pub(crate) did: Option<DefId>,
/// The url fragment to append to the link
pub(crate) fragment: Option<String>,
}
impl Attributes {
/// Extracts the content from an attribute `#[doc(cfg(content))]`.
pub fn extract_cfg(mi: &ast::MetaItem) -> Option<&ast::MetaItem> {
@ -611,8 +623,8 @@ impl Attributes {
self.links
.iter()
.filter_map(|&(ref s, did, ref fragment)| {
match did {
.filter_map(|ItemLink { link: s, did, fragment }| {
match *did {
Some(did) => {
if let Some((mut href, ..)) = href(did) {
if let Some(ref fragment) = *fragment {

View File

@ -904,7 +904,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
if let Res::PrimTy(_) = res {
match disambiguator {
Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => {
item.attrs.links.push((ori_link, None, fragment))
item.attrs.links.push(ItemLink { link: ori_link, did: None, fragment });
}
Some(other) => {
report_mismatch(other, Disambiguator::Primitive);
@ -955,7 +955,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
}
}
let id = register_res(cx, res);
item.attrs.links.push((ori_link, Some(id), fragment));
item.attrs.links.push(ItemLink { link: ori_link, did: Some(id), fragment });
}
}