Use Symbols for crate names

This commit is contained in:
Joshua Nelson 2020-12-14 23:23:58 -05:00
parent c18c7c7059
commit 7ee8e1816f
8 changed files with 29 additions and 25 deletions

View File

@ -209,7 +209,7 @@ impl Clean<ExternalCrate> for CrateNum {
};
ExternalCrate {
name: cx.tcx.crate_name(*self).to_string(),
name: cx.tcx.crate_name(*self),
src: krate_src,
attrs: cx.tcx.get_attrs(root).clean(cx),
primitives,

View File

@ -51,7 +51,7 @@ thread_local!(crate static MAX_DEF_ID: RefCell<FxHashMap<CrateNum, DefId>> = Def
#[derive(Clone, Debug)]
crate struct Crate {
crate name: String,
crate name: Symbol,
crate version: Option<String>,
crate src: FileName,
crate module: Option<Item>,
@ -66,7 +66,7 @@ crate struct Crate {
#[derive(Clone, Debug)]
crate struct ExternalCrate {
crate name: String,
crate name: Symbol,
crate src: FileName,
crate attrs: Attributes,
crate primitives: Vec<(DefId, PrimitiveType)>,

View File

@ -8,6 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
use rustc_middle::middle::privacy::AccessLevels;
use rustc_span::source_map::FileName;
use rustc_span::Symbol;
use crate::clean::{self, GetDefId};
use crate::config::RenderInfo;
@ -74,7 +75,7 @@ crate struct Cache {
crate implementors: FxHashMap<DefId, Vec<Impl>>,
/// Cache of where external crate documentation can be found.
crate extern_locations: FxHashMap<CrateNum, (String, PathBuf, ExternalLocation)>,
crate extern_locations: FxHashMap<CrateNum, (Symbol, PathBuf, ExternalLocation)>,
/// Cache of where documentation for primitives can be found.
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
@ -173,10 +174,10 @@ impl Cache {
},
_ => PathBuf::new(),
};
let extern_url = extern_html_root_urls.get(&e.name).map(|u| &**u);
let extern_url = extern_html_root_urls.get(&*e.name.as_str()).map(|u| &**u);
cache
.extern_locations
.insert(n, (e.name.clone(), src_root, extern_location(e, extern_url, &dst)));
.insert(n, (e.name, src_root, extern_location(e, extern_url, &dst)));
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
@ -195,7 +196,7 @@ impl Cache {
cache.primitive_locations.insert(prim, def_id);
}
cache.stack.push(krate.name.clone());
cache.stack.push(krate.name.to_string());
krate = cache.fold_crate(krate);
for (trait_did, dids, impl_) in cache.orphan_trait_impls.drain(..) {
@ -340,7 +341,7 @@ impl DocFolder for Cache {
// Keep track of the fully qualified path for this item.
let pushed = match item.name {
Some(ref n) if !n.is_empty() => {
Some(n) if !n.is_empty() => {
self.stack.push(n.to_string());
true
}

View File

@ -3,7 +3,6 @@ use std::sync::Arc;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::Symbol;
use crate::clean;
use crate::config::{RenderInfo, RenderOptions};
@ -76,7 +75,7 @@ crate fn run_format<T: FormatRenderer>(
None => return Ok(()),
};
item.name = Some(Symbol::intern(&krate.name));
item.name = Some(krate.name);
// Render the crate documentation
let mut work = vec![(format_renderer.clone(), item)];

View File

@ -31,7 +31,7 @@ crate fn extern_location(
) -> ExternalLocation {
use ExternalLocation::*;
// See if there's documentation generated into the local directory
let local_location = dst.join(&e.name);
let local_location = dst.join(&*e.name.as_str());
if local_location.is_dir() {
return Local;
}

View File

@ -418,14 +418,15 @@ impl FormatRenderer for Context {
// If user passed in `--playground-url` arg, we fill in crate name here
let mut playground = None;
if let Some(url) = playground_url {
playground = Some(markdown::Playground { crate_name: Some(krate.name.clone()), url });
playground =
Some(markdown::Playground { crate_name: Some(krate.name.to_string()), url });
}
let mut layout = layout::Layout {
logo: String::new(),
favicon: String::new(),
external_html,
default_settings,
krate: krate.name.clone(),
krate: krate.name.to_string(),
css_file_extension: extension_css,
generate_search_filter,
};
@ -445,7 +446,7 @@ impl FormatRenderer for Context {
}
(sym::html_playground_url, Some(s)) => {
playground = Some(markdown::Playground {
crate_name: Some(krate.name.clone()),
crate_name: Some(krate.name.to_string()),
url: s.to_string(),
});
}
@ -530,7 +531,7 @@ impl FormatRenderer for Context {
}
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
let final_file = self.dst.join(&krate.name).join("all.html");
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
let crate_name = krate.name.clone();
@ -1019,7 +1020,8 @@ themePicker.onblur = handleThemeButtonsBlur;
}
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst);
let (mut all_sources, _krates) =
try_err!(collect(&dst, &krate.name.as_str(), "sourcesIndex"), &dst);
all_sources.push(format!(
"sourcesIndex[\"{}\"] = {};",
&krate.name,
@ -1035,7 +1037,7 @@ themePicker.onblur = handleThemeButtonsBlur;
// Update the search index
let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix));
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name), &dst);
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst);
all_indexes.push(search_index);
// Sort the indexes by crate so the file will be generated identically even
@ -1070,7 +1072,7 @@ themePicker.onblur = handleThemeButtonsBlur;
extra_scripts: &[],
static_extra_scripts: &[],
};
krates.push(krate.name.clone());
krates.push(krate.name.to_string());
krates.sort();
krates.dedup();
@ -1162,7 +1164,7 @@ themePicker.onblur = handleThemeButtonsBlur;
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
let (mut all_implementors, _) =
try_err!(collect(&mydst, &krate.name, "implementors"), &mydst);
try_err!(collect(&mydst, &krate.name.as_str(), "implementors"), &mydst);
all_implementors.push(implementors);
// Sort the implementors by crate so the file will be generated
// identically even with rustdoc running in parallel.
@ -1648,16 +1650,17 @@ impl Context {
};
let file = &file;
let symbol;
let (krate, path) = if cnum == LOCAL_CRATE {
if let Some(path) = self.shared.local_sources.get(file) {
(&self.shared.layout.krate, path)
(self.shared.layout.krate.as_str(), path)
} else {
return None;
}
} else {
let (krate, src_root) = match *cache.extern_locations.get(&cnum)? {
(ref name, ref src, ExternalLocation::Local) => (name, src),
(ref name, ref src, ExternalLocation::Remote(ref s)) => {
(name, ref src, ExternalLocation::Local) => (name, src),
(name, ref src, ExternalLocation::Remote(ref s)) => {
root = s.to_string();
(name, src)
}
@ -1671,7 +1674,8 @@ impl Context {
let mut fname = file.file_name().expect("source has no filename").to_os_string();
fname.push(".html");
path.push_str(&fname.to_string_lossy());
(krate, &path)
symbol = krate.as_str();
(&*symbol, &path)
};
let loline = item.source.lo(self.sess()).line;

View File

@ -19,7 +19,7 @@ crate fn render(
krate: clean::Crate,
) -> Result<clean::Crate, Error> {
info!("emitting source files");
let dst = dst.join("src").join(&krate.name);
let dst = dst.join("src").join(&*krate.name.as_str());
scx.ensure_dir(&dst)?;
let mut folder = SourceCollector { dst, scx };
Ok(folder.fold_crate(krate))

View File

@ -223,7 +223,7 @@ impl FormatRenderer for JsonRenderer {
(
k.as_u32(),
types::ExternalCrate {
name: v.0.clone(),
name: v.0.to_string(),
html_root_url: match &v.2 {
ExternalLocation::Remote(s) => Some(s.clone()),
_ => None,