From 7ee8e1816f6603502e36b105990bca0f7e440816 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 14 Dec 2020 23:23:58 -0500 Subject: [PATCH] Use `Symbol`s for crate names --- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/types.rs | 4 ++-- src/librustdoc/formats/cache.rs | 11 ++++++----- src/librustdoc/formats/renderer.rs | 3 +-- src/librustdoc/html/render/cache.rs | 2 +- src/librustdoc/html/render/mod.rs | 28 ++++++++++++++++------------ src/librustdoc/html/sources.rs | 2 +- src/librustdoc/json/mod.rs | 2 +- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2d2465e56f376..a531956fb96da 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -209,7 +209,7 @@ impl Clean 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, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2c353a1e0819e..cf9e81f30b1fa 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -51,7 +51,7 @@ thread_local!(crate static MAX_DEF_ID: RefCell> = Def #[derive(Clone, Debug)] crate struct Crate { - crate name: String, + crate name: Symbol, crate version: Option, crate src: FileName, crate module: Option, @@ -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)>, diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index e82bc540e95af..77a3e9fa9549b 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -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>, /// Cache of where external crate documentation can be found. - crate extern_locations: FxHashMap, + crate extern_locations: FxHashMap, /// Cache of where documentation for primitives can be found. crate primitive_locations: FxHashMap, @@ -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 } diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index c332da4db4ee9..f61919d78a092 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -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( 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)]; diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 91037bc160ab4..ba06b6b182b00 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -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; } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 00f3723ce2398..d517151bc31ea 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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; diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index ef9e9f350fb84..b6c3300906bfd 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -19,7 +19,7 @@ crate fn render( krate: clean::Crate, ) -> Result { 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)) diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 5c5239d1b6a26..7af26558b76ec 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -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,