1
Fork 0

generate_macro_def_id_path: don't eagerly stringify Symbols

This commit is contained in:
klensy 2023-01-13 17:33:07 +03:00
parent 4e1258c6b6
commit cda6efeeb8

View file

@ -569,7 +569,7 @@ fn generate_macro_def_id_path(
root_path: Option<&str>, root_path: Option<&str>,
) -> Result<(String, ItemType, Vec<Symbol>), HrefError> { ) -> Result<(String, ItemType, Vec<Symbol>), HrefError> {
let tcx = cx.shared.tcx; let tcx = cx.shared.tcx;
let crate_name = tcx.crate_name(def_id.krate).to_string(); let crate_name = tcx.crate_name(def_id.krate);
let cache = cx.cache(); let cache = cx.cache();
let fqp: Vec<Symbol> = tcx let fqp: Vec<Symbol> = tcx
@ -584,7 +584,7 @@ fn generate_macro_def_id_path(
} }
}) })
.collect(); .collect();
let mut relative = fqp.iter().map(|elem| elem.to_string()); let mut relative = fqp.iter().copied();
let cstore = CStore::from_tcx(tcx); let cstore = CStore::from_tcx(tcx);
// We need this to prevent a `panic` when this function is used from intra doc links... // We need this to prevent a `panic` when this function is used from intra doc links...
if !cstore.has_crate_data(def_id.krate) { if !cstore.has_crate_data(def_id.krate) {
@ -602,9 +602,9 @@ fn generate_macro_def_id_path(
}; };
let mut path = if is_macro_2 { let mut path = if is_macro_2 {
once(crate_name.clone()).chain(relative).collect() once(crate_name).chain(relative).collect()
} else { } else {
vec![crate_name.clone(), relative.next_back().unwrap()] vec![crate_name, relative.next_back().unwrap()]
}; };
if path.len() < 2 { if path.len() < 2 {
// The minimum we can have is the crate name followed by the macro name. If shorter, then // The minimum we can have is the crate name followed by the macro name. If shorter, then
@ -614,17 +614,22 @@ fn generate_macro_def_id_path(
} }
if let Some(last) = path.last_mut() { if let Some(last) = path.last_mut() {
*last = format!("macro.{}.html", last); *last = Symbol::intern(&format!("macro.{}.html", last.as_str()));
} }
let url = match cache.extern_locations[&def_id.krate] { let url = match cache.extern_locations[&def_id.krate] {
ExternalLocation::Remote(ref s) => { ExternalLocation::Remote(ref s) => {
// `ExternalLocation::Remote` always end with a `/`. // `ExternalLocation::Remote` always end with a `/`.
format!("{}{}", s, path.join("/")) format!("{}{}", s, path.iter().map(|p| p.as_str()).join("/"))
} }
ExternalLocation::Local => { ExternalLocation::Local => {
// `root_path` always end with a `/`. // `root_path` always end with a `/`.
format!("{}{}/{}", root_path.unwrap_or(""), crate_name, path.join("/")) format!(
"{}{}/{}",
root_path.unwrap_or(""),
crate_name,
path.iter().map(|p| p.as_str()).join("/")
)
} }
ExternalLocation::Unknown => { ExternalLocation::Unknown => {
debug!("crate {} not in cache when linkifying macros", crate_name); debug!("crate {} not in cache when linkifying macros", crate_name);