Skip to content

Commit cc65bf3

Browse files
committed
Auto merge of #92088 - camelid:intra-doc-cleanup, r=Manishearth
intra-doc: Use an enum to represent URL fragments This is a step in the direction of computing the links more lazily, which I think will simplify the implementation of intra-doc links. This will also make it easier to eventually use the actual `Res` for associated items, enum variants, and fields, rather than their HTML page's `Res`. r? `@jyn514`
2 parents 41ce641 + ae2bc69 commit cc65bf3

File tree

2 files changed

+114
-79
lines changed

2 files changed

+114
-79
lines changed

src/librustdoc/clean/types.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::cell::RefCell;
22
use std::default::Default;
3+
use std::fmt::Write;
34
use std::hash::Hash;
45
use std::lazy::SyncOnceCell as OnceCell;
56
use std::path::PathBuf;
@@ -40,6 +41,7 @@ use crate::formats::cache::Cache;
4041
use crate::formats::item_type::ItemType;
4142
use crate::html::render::cache::ExternalLocation;
4243
use crate::html::render::Context;
44+
use crate::passes::collect_intra_doc_links::UrlFragment;
4345

4446
crate use self::FnRetTy::*;
4547
crate use self::ItemKind::*;
@@ -485,8 +487,7 @@ impl Item {
485487
if let Ok((mut href, ..)) = href(*did, cx) {
486488
debug!(?href);
487489
if let Some(ref fragment) = *fragment {
488-
href.push('#');
489-
href.push_str(fragment);
490+
write!(href, "{}", fragment).unwrap()
490491
}
491492
Some(RenderedLink {
492493
original_text: s.clone(),
@@ -977,7 +978,7 @@ crate struct ItemLink {
977978
pub(crate) link_text: String,
978979
pub(crate) did: DefId,
979980
/// The url fragment to append to the link
980-
pub(crate) fragment: Option<String>,
981+
pub(crate) fragment: Option<UrlFragment>,
981982
}
982983

983984
pub struct RenderedLink {

0 commit comments

Comments
 (0)