Skip to content

Commit d5495e2

Browse files
committed
Refactor ItemLink into its own struct
1 parent 89ae59a commit d5495e2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/librustdoc/clean/types.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,22 @@ pub struct Attributes {
425425
pub cfg: Option<Arc<Cfg>>,
426426
pub span: Option<rustc_span::Span>,
427427
/// map from Rust paths to resolved defs and potential URL fragments
428-
pub links: Vec<(String, Option<DefId>, Option<String>)>,
428+
pub links: Vec<ItemLink>,
429429
pub inner_docs: bool,
430430
}
431431

432+
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
433+
/// A link that has not yet been rendered.
434+
///
435+
/// This link will be turned into a rendered link by [`Attributes::links`]
436+
pub struct ItemLink {
437+
/// The original link written in the markdown
438+
pub(crate) link: String,
439+
pub(crate) did: Option<DefId>,
440+
/// The url fragment to append to the link
441+
pub(crate) fragment: Option<String>,
442+
}
443+
432444
impl Attributes {
433445
/// Extracts the content from an attribute `#[doc(cfg(content))]`.
434446
pub fn extract_cfg(mi: &ast::MetaItem) -> Option<&ast::MetaItem> {
@@ -611,8 +623,8 @@ impl Attributes {
611623

612624
self.links
613625
.iter()
614-
.filter_map(|&(ref s, did, ref fragment)| {
615-
match did {
626+
.filter_map(|ItemLink { link: s, did, fragment }| {
627+
match *did {
616628
Some(did) => {
617629
if let Some((mut href, ..)) = href(did) {
618630
if let Some(ref fragment) = *fragment {

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
904904
if let Res::PrimTy(_) = res {
905905
match disambiguator {
906906
Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => {
907-
item.attrs.links.push((ori_link, None, fragment))
907+
item.attrs.links.push(ItemLink { link: ori_link, did: None, fragment });
908908
}
909909
Some(other) => {
910910
report_mismatch(other, Disambiguator::Primitive);
@@ -955,7 +955,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
955955
}
956956
}
957957
let id = register_res(cx, res);
958-
item.attrs.links.push((ori_link, Some(id), fragment));
958+
item.attrs.links.push(ItemLink { link: ori_link, did: Some(id), fragment });
959959
}
960960
}
961961

0 commit comments

Comments
 (0)