rustdoc: avoid many Symbol
to String
conversions.
Particularly when constructing file paths and fully qualified paths. This avoids a lot of allocations, speeding things up on almost all examples.
This commit is contained in:
parent
02c9e73e6c
commit
10b1c9aa8b
13 changed files with 198 additions and 120 deletions
|
@ -567,6 +567,7 @@ symbols! {
|
||||||
doc_spotlight,
|
doc_spotlight,
|
||||||
doctest,
|
doctest,
|
||||||
document_private_items,
|
document_private_items,
|
||||||
|
dotdot: "..",
|
||||||
dotdot_in_tuple_patterns,
|
dotdot_in_tuple_patterns,
|
||||||
dotdoteq_in_patterns,
|
dotdoteq_in_patterns,
|
||||||
dreg,
|
dreg,
|
||||||
|
|
|
@ -9,7 +9,6 @@ use rustc_data_structures::thin_vec::ThinVec;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
use rustc_metadata::creader::{CStore, LoadedMacro};
|
use rustc_metadata::creader::{CStore, LoadedMacro};
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
@ -164,12 +163,10 @@ crate fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> {
|
||||||
/// These names are used later on by HTML rendering to generate things like
|
/// These names are used later on by HTML rendering to generate things like
|
||||||
/// source links back to the original item.
|
/// source links back to the original item.
|
||||||
crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) {
|
crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) {
|
||||||
let crate_name = cx.tcx.crate_name(did.krate).to_string();
|
let crate_name = cx.tcx.crate_name(did.krate);
|
||||||
|
|
||||||
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
|
let relative =
|
||||||
// Filter out extern blocks
|
cx.tcx.def_path(did).data.into_iter().filter_map(|elem| elem.data.get_opt_name());
|
||||||
(elem.data != DefPathData::ForeignMod).then(|| elem.data.to_string())
|
|
||||||
});
|
|
||||||
let fqn = if let ItemType::Macro = kind {
|
let fqn = if let ItemType::Macro = kind {
|
||||||
// Check to see if it is a macro 2.0 or built-in macro
|
// Check to see if it is a macro 2.0 or built-in macro
|
||||||
if matches!(
|
if matches!(
|
||||||
|
|
|
@ -4,13 +4,14 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
|
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
|
||||||
use rustc_middle::middle::privacy::AccessLevels;
|
use rustc_middle::middle::privacy::AccessLevels;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::{sym, Symbol};
|
||||||
|
|
||||||
use crate::clean::{self, types::ExternalLocation, ExternalCrate, ItemId, PrimitiveType};
|
use crate::clean::{self, types::ExternalLocation, ExternalCrate, ItemId, PrimitiveType};
|
||||||
use crate::core::DocContext;
|
use crate::core::DocContext;
|
||||||
use crate::fold::DocFolder;
|
use crate::fold::DocFolder;
|
||||||
use crate::formats::item_type::ItemType;
|
use crate::formats::item_type::ItemType;
|
||||||
use crate::formats::Impl;
|
use crate::formats::Impl;
|
||||||
|
use crate::html::format::join_with_double_colon;
|
||||||
use crate::html::markdown::short_markdown_summary;
|
use crate::html::markdown::short_markdown_summary;
|
||||||
use crate::html::render::search_index::get_function_type_for_search;
|
use crate::html::render::search_index::get_function_type_for_search;
|
||||||
use crate::html::render::IndexItem;
|
use crate::html::render::IndexItem;
|
||||||
|
@ -39,11 +40,11 @@ crate struct Cache {
|
||||||
/// URLs when a type is being linked to. External paths are not located in
|
/// URLs when a type is being linked to. External paths are not located in
|
||||||
/// this map because the `External` type itself has all the information
|
/// this map because the `External` type itself has all the information
|
||||||
/// necessary.
|
/// necessary.
|
||||||
crate paths: FxHashMap<DefId, (Vec<String>, ItemType)>,
|
crate paths: FxHashMap<DefId, (Vec<Symbol>, ItemType)>,
|
||||||
|
|
||||||
/// Similar to `paths`, but only holds external paths. This is only used for
|
/// Similar to `paths`, but only holds external paths. This is only used for
|
||||||
/// generating explicit hyperlinks to other crates.
|
/// generating explicit hyperlinks to other crates.
|
||||||
crate external_paths: FxHashMap<DefId, (Vec<String>, ItemType)>,
|
crate external_paths: FxHashMap<DefId, (Vec<Symbol>, ItemType)>,
|
||||||
|
|
||||||
/// Maps local `DefId`s of exported types to fully qualified paths.
|
/// Maps local `DefId`s of exported types to fully qualified paths.
|
||||||
/// Unlike 'paths', this mapping ignores any renames that occur
|
/// Unlike 'paths', this mapping ignores any renames that occur
|
||||||
|
@ -55,7 +56,7 @@ crate struct Cache {
|
||||||
/// to the path used if the corresponding type is inlined. By
|
/// to the path used if the corresponding type is inlined. By
|
||||||
/// doing this, we can detect duplicate impls on a trait page, and only display
|
/// doing this, we can detect duplicate impls on a trait page, and only display
|
||||||
/// the impl for the inlined type.
|
/// the impl for the inlined type.
|
||||||
crate exact_paths: FxHashMap<DefId, Vec<String>>,
|
crate exact_paths: FxHashMap<DefId, Vec<Symbol>>,
|
||||||
|
|
||||||
/// This map contains information about all known traits of this crate.
|
/// This map contains information about all known traits of this crate.
|
||||||
/// Implementations of a crate should inherit the documentation of the
|
/// Implementations of a crate should inherit the documentation of the
|
||||||
|
@ -92,7 +93,7 @@ crate struct Cache {
|
||||||
crate masked_crates: FxHashSet<CrateNum>,
|
crate masked_crates: FxHashSet<CrateNum>,
|
||||||
|
|
||||||
// Private fields only used when initially crawling a crate to build a cache
|
// Private fields only used when initially crawling a crate to build a cache
|
||||||
stack: Vec<String>,
|
stack: Vec<Symbol>,
|
||||||
parent_stack: Vec<DefId>,
|
parent_stack: Vec<DefId>,
|
||||||
parent_is_trait_impl: bool,
|
parent_is_trait_impl: bool,
|
||||||
stripped_mod: bool,
|
stripped_mod: bool,
|
||||||
|
@ -155,7 +156,7 @@ impl Cache {
|
||||||
let dst = &render_options.output;
|
let dst = &render_options.output;
|
||||||
let location = e.location(extern_url, extern_url_takes_precedence, dst, tcx);
|
let location = e.location(extern_url, extern_url_takes_precedence, dst, tcx);
|
||||||
cx.cache.extern_locations.insert(e.crate_num, location);
|
cx.cache.extern_locations.insert(e.crate_num, location);
|
||||||
cx.cache.external_paths.insert(e.def_id(), (vec![name.to_string()], ItemType::Module));
|
cx.cache.external_paths.insert(e.def_id(), (vec![name], ItemType::Module));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: avoid this clone (requires implementing Default manually)
|
// FIXME: avoid this clone (requires implementing Default manually)
|
||||||
|
@ -164,10 +165,9 @@ impl Cache {
|
||||||
let crate_name = tcx.crate_name(def_id.krate);
|
let crate_name = tcx.crate_name(def_id.krate);
|
||||||
// Recall that we only allow primitive modules to be at the root-level of the crate.
|
// Recall that we only allow primitive modules to be at the root-level of the crate.
|
||||||
// If that restriction is ever lifted, this will have to include the relative paths instead.
|
// If that restriction is ever lifted, this will have to include the relative paths instead.
|
||||||
cx.cache.external_paths.insert(
|
cx.cache
|
||||||
def_id,
|
.external_paths
|
||||||
(vec![crate_name.to_string(), prim.as_sym().to_string()], ItemType::Primitive),
|
.insert(def_id, (vec![crate_name, prim.as_sym()], ItemType::Primitive));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
krate = CacheBuilder { tcx, cache: &mut cx.cache }.fold_crate(krate);
|
krate = CacheBuilder { tcx, cache: &mut cx.cache }.fold_crate(krate);
|
||||||
|
@ -299,7 +299,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
self.cache.search_index.push(IndexItem {
|
self.cache.search_index.push(IndexItem {
|
||||||
ty: item.type_(),
|
ty: item.type_(),
|
||||||
name: s.to_string(),
|
name: s.to_string(),
|
||||||
path: path.join("::"),
|
path: join_with_double_colon(path),
|
||||||
desc,
|
desc,
|
||||||
parent,
|
parent,
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
|
@ -320,7 +320,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
// Keep track of the fully qualified path for this item.
|
// Keep track of the fully qualified path for this item.
|
||||||
let pushed = match item.name {
|
let pushed = match item.name {
|
||||||
Some(n) if !n.is_empty() => {
|
Some(n) if !n.is_empty() => {
|
||||||
self.cache.stack.push(n.to_string());
|
self.cache.stack.push(n);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -19,6 +19,7 @@ use rustc_middle::ty;
|
||||||
use rustc_middle::ty::DefIdTree;
|
use rustc_middle::ty::DefIdTree;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::def_id::CRATE_DEF_INDEX;
|
use rustc_span::def_id::CRATE_DEF_INDEX;
|
||||||
|
use rustc_span::{sym, Symbol};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
use crate::clean::{
|
use crate::clean::{
|
||||||
|
@ -502,11 +503,45 @@ crate enum HrefError {
|
||||||
NotInExternalCache,
|
NotInExternalCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This mostly works with sequences of symbols, but sometimes the first item
|
||||||
|
// comes from a string, and in that case we want to trim any trailing `/`.
|
||||||
|
// `syms` can be empty.
|
||||||
|
crate fn join_with_slash(first: Option<&str>, syms: &[Symbol]) -> String {
|
||||||
|
// 64 bytes covers 99.9%+ of cases.
|
||||||
|
let mut s = String::with_capacity(64);
|
||||||
|
if let Some(first) = first {
|
||||||
|
s.push_str(first.trim_end_matches('/'));
|
||||||
|
if !syms.is_empty() {
|
||||||
|
s.push('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !syms.is_empty() {
|
||||||
|
s.push_str(&syms[0].as_str());
|
||||||
|
for sym in &syms[1..] {
|
||||||
|
s.push('/');
|
||||||
|
s.push_str(&sym.as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panics if `syms` is empty.
|
||||||
|
crate fn join_with_double_colon(syms: &[Symbol]) -> String {
|
||||||
|
// 64 bytes covers 99.9%+ of cases.
|
||||||
|
let mut s = String::with_capacity(64);
|
||||||
|
s.push_str(&syms[0].as_str());
|
||||||
|
for sym in &syms[1..] {
|
||||||
|
s.push_str("::");
|
||||||
|
s.push_str(&sym.as_str());
|
||||||
|
}
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
crate fn href_with_root_path(
|
crate fn href_with_root_path(
|
||||||
did: DefId,
|
did: DefId,
|
||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
root_path: Option<&str>,
|
root_path: Option<&str>,
|
||||||
) -> Result<(String, ItemType, Vec<String>), HrefError> {
|
) -> Result<(String, ItemType, Vec<Symbol>), HrefError> {
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
let def_kind = tcx.def_kind(did);
|
let def_kind = tcx.def_kind(did);
|
||||||
let did = match def_kind {
|
let did = match def_kind {
|
||||||
|
@ -518,7 +553,7 @@ crate fn href_with_root_path(
|
||||||
};
|
};
|
||||||
let cache = cx.cache();
|
let cache = cx.cache();
|
||||||
let relative_to = &cx.current;
|
let relative_to = &cx.current;
|
||||||
fn to_module_fqp(shortty: ItemType, fqp: &[String]) -> &[String] {
|
fn to_module_fqp(shortty: ItemType, fqp: &[Symbol]) -> &[Symbol] {
|
||||||
if shortty == ItemType::Module { fqp } else { &fqp[..fqp.len() - 1] }
|
if shortty == ItemType::Module { fqp } else { &fqp[..fqp.len() - 1] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,9 +568,9 @@ crate fn href_with_root_path(
|
||||||
let mut is_remote = false;
|
let mut is_remote = false;
|
||||||
let (fqp, shortty, mut url_parts) = match cache.paths.get(&did) {
|
let (fqp, shortty, mut url_parts) = match cache.paths.get(&did) {
|
||||||
Some(&(ref fqp, shortty)) => (fqp, shortty, {
|
Some(&(ref fqp, shortty)) => (fqp, shortty, {
|
||||||
let module_fqp = to_module_fqp(shortty, fqp);
|
let module_fqp = to_module_fqp(shortty, fqp.as_slice());
|
||||||
debug!(?fqp, ?shortty, ?module_fqp);
|
debug!(?fqp, ?shortty, ?module_fqp);
|
||||||
href_relative_parts(module_fqp, relative_to)
|
href_relative_parts(module_fqp, relative_to).collect()
|
||||||
}),
|
}),
|
||||||
None => {
|
None => {
|
||||||
if let Some(&(ref fqp, shortty)) = cache.external_paths.get(&did) {
|
if let Some(&(ref fqp, shortty)) = cache.external_paths.get(&did) {
|
||||||
|
@ -548,10 +583,12 @@ crate fn href_with_root_path(
|
||||||
is_remote = true;
|
is_remote = true;
|
||||||
let s = s.trim_end_matches('/');
|
let s = s.trim_end_matches('/');
|
||||||
let mut builder = UrlPartsBuilder::singleton(s);
|
let mut builder = UrlPartsBuilder::singleton(s);
|
||||||
builder.extend(module_fqp.iter().map(String::as_str));
|
builder.extend(module_fqp.iter().copied());
|
||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
ExternalLocation::Local => href_relative_parts(module_fqp, relative_to),
|
ExternalLocation::Local => {
|
||||||
|
href_relative_parts(module_fqp, relative_to).collect()
|
||||||
|
}
|
||||||
ExternalLocation::Unknown => return Err(HrefError::DocumentationNotBuilt),
|
ExternalLocation::Unknown => return Err(HrefError::DocumentationNotBuilt),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -567,45 +604,50 @@ crate fn href_with_root_path(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug!(?url_parts);
|
debug!(?url_parts);
|
||||||
let last = &fqp.last().unwrap()[..];
|
|
||||||
match shortty {
|
match shortty {
|
||||||
ItemType::Module => {
|
ItemType::Module => {
|
||||||
url_parts.push("index.html");
|
url_parts.push("index.html");
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let filename = format!("{}.{}.html", shortty.as_str(), last);
|
let prefix = shortty.as_str();
|
||||||
url_parts.push(&filename);
|
let last = fqp.last().unwrap();
|
||||||
|
url_parts.push_fmt(format_args!("{}.{}.html", prefix, last));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok((url_parts.finish(), shortty, fqp.to_vec()))
|
Ok((url_parts.finish(), shortty, fqp.to_vec()))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<String>), HrefError> {
|
crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Symbol>), HrefError> {
|
||||||
href_with_root_path(did, cx, None)
|
href_with_root_path(did, cx, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Both paths should only be modules.
|
/// Both paths should only be modules.
|
||||||
/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
|
/// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will
|
||||||
/// both need `../iter/trait.Iterator.html` to get at the iterator trait.
|
/// both need `../iter/trait.Iterator.html` to get at the iterator trait.
|
||||||
crate fn href_relative_parts(fqp: &[String], relative_to_fqp: &[String]) -> UrlPartsBuilder {
|
crate fn href_relative_parts<'fqp>(
|
||||||
|
fqp: &'fqp [Symbol],
|
||||||
|
relative_to_fqp: &[Symbol],
|
||||||
|
) -> Box<dyn Iterator<Item = Symbol> + 'fqp> {
|
||||||
for (i, (f, r)) in fqp.iter().zip(relative_to_fqp.iter()).enumerate() {
|
for (i, (f, r)) in fqp.iter().zip(relative_to_fqp.iter()).enumerate() {
|
||||||
// e.g. linking to std::iter from std::vec (`dissimilar_part_count` will be 1)
|
// e.g. linking to std::iter from std::vec (`dissimilar_part_count` will be 1)
|
||||||
if f != r {
|
if f != r {
|
||||||
let dissimilar_part_count = relative_to_fqp.len() - i;
|
let dissimilar_part_count = relative_to_fqp.len() - i;
|
||||||
let fqp_module = fqp[i..fqp.len()].iter().map(String::as_str);
|
let fqp_module = &fqp[i..fqp.len()];
|
||||||
return iter::repeat("..").take(dissimilar_part_count).chain(fqp_module).collect();
|
return box iter::repeat(sym::dotdot)
|
||||||
|
.take(dissimilar_part_count)
|
||||||
|
.chain(fqp_module.iter().copied());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// e.g. linking to std::sync::atomic from std::sync
|
// e.g. linking to std::sync::atomic from std::sync
|
||||||
if relative_to_fqp.len() < fqp.len() {
|
if relative_to_fqp.len() < fqp.len() {
|
||||||
fqp[relative_to_fqp.len()..fqp.len()].iter().map(String::as_str).collect()
|
box fqp[relative_to_fqp.len()..fqp.len()].iter().copied()
|
||||||
// e.g. linking to std::sync from std::sync::atomic
|
// e.g. linking to std::sync from std::sync::atomic
|
||||||
} else if fqp.len() < relative_to_fqp.len() {
|
} else if fqp.len() < relative_to_fqp.len() {
|
||||||
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
|
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
|
||||||
iter::repeat("..").take(dissimilar_part_count).collect()
|
box iter::repeat(sym::dotdot).take(dissimilar_part_count)
|
||||||
// linking to the same module
|
// linking to the same module
|
||||||
} else {
|
} else {
|
||||||
UrlPartsBuilder::new()
|
box iter::empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,14 +674,14 @@ fn resolved_path<'cx>(
|
||||||
if let Ok((_, _, fqp)) = href(did, cx) {
|
if let Ok((_, _, fqp)) = href(did, cx) {
|
||||||
format!(
|
format!(
|
||||||
"{}::{}",
|
"{}::{}",
|
||||||
fqp[..fqp.len() - 1].join("::"),
|
join_with_double_colon(&fqp[..fqp.len() - 1]),
|
||||||
anchor(did, fqp.last().unwrap(), cx)
|
anchor(did, *fqp.last().unwrap(), cx)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
last.name.to_string()
|
last.name.to_string()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
anchor(did, last.name.as_str(), cx).to_string()
|
anchor(did, last.name, cx).to_string()
|
||||||
};
|
};
|
||||||
write!(w, "{}{}", path, last.args.print(cx))?;
|
write!(w, "{}{}", path, last.args.print(cx))?;
|
||||||
}
|
}
|
||||||
|
@ -668,30 +710,31 @@ fn primitive_link(
|
||||||
needs_termination = true;
|
needs_termination = true;
|
||||||
}
|
}
|
||||||
Some(&def_id) => {
|
Some(&def_id) => {
|
||||||
let cname_sym;
|
|
||||||
let loc = match m.extern_locations[&def_id.krate] {
|
let loc = match m.extern_locations[&def_id.krate] {
|
||||||
ExternalLocation::Remote(ref s) => {
|
ExternalLocation::Remote(ref s) => {
|
||||||
cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
|
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
|
||||||
Some(vec![s.trim_end_matches('/'), cname_sym.as_str()])
|
let builder: UrlPartsBuilder =
|
||||||
|
[s.as_str().trim_end_matches('/'), cname_sym.as_str()]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
Some(builder)
|
||||||
}
|
}
|
||||||
ExternalLocation::Local => {
|
ExternalLocation::Local => {
|
||||||
cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
|
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
|
||||||
Some(if cx.current.first().map(|x| &x[..]) == Some(cname_sym.as_str()) {
|
Some(if cx.current.first() == Some(&cname_sym) {
|
||||||
iter::repeat("..").take(cx.current.len() - 1).collect()
|
iter::repeat(sym::dotdot).take(cx.current.len() - 1).collect()
|
||||||
} else {
|
} else {
|
||||||
let cname = iter::once(cname_sym.as_str());
|
iter::repeat(sym::dotdot)
|
||||||
iter::repeat("..").take(cx.current.len()).chain(cname).collect()
|
.take(cx.current.len())
|
||||||
|
.chain(iter::once(cname_sym))
|
||||||
|
.collect()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ExternalLocation::Unknown => None,
|
ExternalLocation::Unknown => None,
|
||||||
};
|
};
|
||||||
if let Some(loc) = loc {
|
if let Some(mut loc) = loc {
|
||||||
write!(
|
loc.push_fmt(format_args!("primitive.{}.html", prim.as_sym()));
|
||||||
f,
|
write!(f, "<a class=\"primitive\" href=\"{}\">", loc.finish())?;
|
||||||
"<a class=\"primitive\" href=\"{}/primitive.{}.html\">",
|
|
||||||
loc.join("/"),
|
|
||||||
prim.as_sym()
|
|
||||||
)?;
|
|
||||||
needs_termination = true;
|
needs_termination = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -730,7 +773,7 @@ fn tybounds<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
crate fn anchor<'a, 'cx: 'a>(
|
crate fn anchor<'a, 'cx: 'a>(
|
||||||
did: DefId,
|
did: DefId,
|
||||||
text: &'a str,
|
text: Symbol,
|
||||||
cx: &'cx Context<'_>,
|
cx: &'cx Context<'_>,
|
||||||
) -> impl fmt::Display + 'a {
|
) -> impl fmt::Display + 'a {
|
||||||
let parts = href(did, cx);
|
let parts = href(did, cx);
|
||||||
|
@ -742,8 +785,8 @@ crate fn anchor<'a, 'cx: 'a>(
|
||||||
short_ty,
|
short_ty,
|
||||||
url,
|
url,
|
||||||
short_ty,
|
short_ty,
|
||||||
fqp.join("::"),
|
join_with_double_colon(&fqp),
|
||||||
text
|
&*text.as_str()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{}", text)
|
write!(f, "{}", text)
|
||||||
|
@ -960,7 +1003,7 @@ fn fmt_type<'cx>(
|
||||||
url = url,
|
url = url,
|
||||||
shortty = ItemType::AssocType,
|
shortty = ItemType::AssocType,
|
||||||
name = name,
|
name = name,
|
||||||
path = path.join("::")
|
path = join_with_double_colon(path),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
_ => write!(f, "{}", name)?,
|
_ => write!(f, "{}", name)?,
|
||||||
|
@ -1270,7 +1313,7 @@ impl clean::Visibility {
|
||||||
debug!("path={:?}", path);
|
debug!("path={:?}", path);
|
||||||
// modified from `resolved_path()` to work with `DefPathData`
|
// modified from `resolved_path()` to work with `DefPathData`
|
||||||
let last_name = path.data.last().unwrap().data.get_opt_name().unwrap();
|
let last_name = path.data.last().unwrap().data.get_opt_name().unwrap();
|
||||||
let anchor = anchor(vis_did, last_name.as_str(), cx).to_string();
|
let anchor = anchor(vis_did, last_name, cx).to_string();
|
||||||
|
|
||||||
let mut s = "pub(in ".to_owned();
|
let mut s = "pub(in ".to_owned();
|
||||||
for seg in &path.data[..path.data.len() - 1] {
|
for seg in &path.data[..path.data.len() - 1] {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::source_map::FileName;
|
use rustc_span::source_map::FileName;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::{sym, Symbol};
|
||||||
|
|
||||||
use super::print_item::{full_path, item_path, print_item};
|
use super::print_item::{full_path, item_path, print_item};
|
||||||
use super::search_index::build_index;
|
use super::search_index::build_index;
|
||||||
|
@ -29,7 +29,7 @@ use crate::formats::cache::Cache;
|
||||||
use crate::formats::item_type::ItemType;
|
use crate::formats::item_type::ItemType;
|
||||||
use crate::formats::FormatRenderer;
|
use crate::formats::FormatRenderer;
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::Buffer;
|
use crate::html::format::{join_with_double_colon, Buffer};
|
||||||
use crate::html::markdown::{self, plain_text_summary, ErrorCodes, IdMap};
|
use crate::html::markdown::{self, plain_text_summary, ErrorCodes, IdMap};
|
||||||
use crate::html::{layout, sources};
|
use crate::html::{layout, sources};
|
||||||
use crate::scrape_examples::AllCallLocations;
|
use crate::scrape_examples::AllCallLocations;
|
||||||
|
@ -45,7 +45,7 @@ use crate::try_err;
|
||||||
crate struct Context<'tcx> {
|
crate struct Context<'tcx> {
|
||||||
/// Current hierarchy of components leading down to what's currently being
|
/// Current hierarchy of components leading down to what's currently being
|
||||||
/// rendered
|
/// rendered
|
||||||
pub(crate) current: Vec<String>,
|
pub(crate) current: Vec<Symbol>,
|
||||||
/// The current destination folder of where HTML artifacts should be placed.
|
/// The current destination folder of where HTML artifacts should be placed.
|
||||||
/// This changes as the context descends into the module hierarchy.
|
/// This changes as the context descends into the module hierarchy.
|
||||||
crate dst: PathBuf,
|
crate dst: PathBuf,
|
||||||
|
@ -176,7 +176,7 @@ impl<'tcx> Context<'tcx> {
|
||||||
title.push_str(" in ");
|
title.push_str(" in ");
|
||||||
}
|
}
|
||||||
// No need to include the namespace for primitive types and keywords
|
// No need to include the namespace for primitive types and keywords
|
||||||
title.push_str(&self.current.join("::"));
|
title.push_str(&join_with_double_colon(&self.current));
|
||||||
};
|
};
|
||||||
title.push_str(" - Rust");
|
title.push_str(" - Rust");
|
||||||
let tyname = it.type_();
|
let tyname = it.type_();
|
||||||
|
@ -225,18 +225,18 @@ impl<'tcx> Context<'tcx> {
|
||||||
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.def_id.expect_def_id()) {
|
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.def_id.expect_def_id()) {
|
||||||
let mut path = String::new();
|
let mut path = String::new();
|
||||||
for name in &names[..names.len() - 1] {
|
for name in &names[..names.len() - 1] {
|
||||||
path.push_str(name);
|
path.push_str(&name.as_str());
|
||||||
path.push('/');
|
path.push('/');
|
||||||
}
|
}
|
||||||
path.push_str(&item_path(ty, names.last().unwrap()));
|
path.push_str(&item_path(ty, &names.last().unwrap().as_str()));
|
||||||
match self.shared.redirections {
|
match self.shared.redirections {
|
||||||
Some(ref redirections) => {
|
Some(ref redirections) => {
|
||||||
let mut current_path = String::new();
|
let mut current_path = String::new();
|
||||||
for name in &self.current {
|
for name in &self.current {
|
||||||
current_path.push_str(name);
|
current_path.push_str(&name.as_str());
|
||||||
current_path.push('/');
|
current_path.push('/');
|
||||||
}
|
}
|
||||||
current_path.push_str(&item_path(ty, names.last().unwrap()));
|
current_path.push_str(&item_path(ty, &names.last().unwrap().as_str()));
|
||||||
redirections.borrow_mut().insert(current_path, path);
|
redirections.borrow_mut().insert(current_path, path);
|
||||||
}
|
}
|
||||||
None => return layout::redirect(&format!("{}{}", self.root_path(), path)),
|
None => return layout::redirect(&format!("{}{}", self.root_path(), path)),
|
||||||
|
@ -634,8 +634,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
self.render_redirect_pages = item.is_stripped();
|
self.render_redirect_pages = item.is_stripped();
|
||||||
}
|
}
|
||||||
let scx = &self.shared;
|
let scx = &self.shared;
|
||||||
let item_name = item.name.as_ref().unwrap().to_string();
|
let item_name = item.name.unwrap();
|
||||||
self.dst.push(&item_name);
|
self.dst.push(&*item_name.as_str());
|
||||||
self.current.push(item_name);
|
self.current.push(item_name);
|
||||||
|
|
||||||
info!("Recursing into {}", self.dst.display());
|
info!("Recursing into {}", self.dst.display());
|
||||||
|
|
|
@ -69,8 +69,9 @@ use crate::formats::item_type::ItemType;
|
||||||
use crate::formats::{AssocItemRender, Impl, RenderMode};
|
use crate::formats::{AssocItemRender, Impl, RenderMode};
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{
|
use crate::html::format::{
|
||||||
href, print_abi_with_space, print_constness_with_space, print_default_space,
|
href, join_with_double_colon, print_abi_with_space, print_constness_with_space,
|
||||||
print_generic_bounds, print_where_clause, Buffer, HrefError, PrintWithSpace,
|
print_default_space, print_generic_bounds, print_where_clause, Buffer, HrefError,
|
||||||
|
PrintWithSpace,
|
||||||
};
|
};
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine};
|
use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine};
|
||||||
|
@ -2515,7 +2516,7 @@ fn collect_paths_for_type(first_ty: clean::Type, cache: &Cache) -> Vec<String> {
|
||||||
let fqp = cache.exact_paths.get(&did).cloned().or_else(get_extern);
|
let fqp = cache.exact_paths.get(&did).cloned().or_else(get_extern);
|
||||||
|
|
||||||
if let Some(path) = fqp {
|
if let Some(path) = fqp {
|
||||||
out.push(path.join("::"));
|
out.push(join_with_double_colon(&path));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ use crate::formats::item_type::ItemType;
|
||||||
use crate::formats::{AssocItemRender, Impl, RenderMode};
|
use crate::formats::{AssocItemRender, Impl, RenderMode};
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{
|
use crate::html::format::{
|
||||||
print_abi_with_space, print_constness_with_space, print_where_clause, Buffer, PrintWithSpace,
|
join_with_double_colon, join_with_slash, print_abi_with_space, print_constness_with_space,
|
||||||
|
print_where_clause, Buffer, PrintWithSpace,
|
||||||
};
|
};
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
use crate::html::layout::Page;
|
use crate::html::layout::Page;
|
||||||
|
@ -40,9 +41,9 @@ const ITEM_TABLE_ROW_OPEN: &str = "<div class=\"item-row\">";
|
||||||
const ITEM_TABLE_ROW_CLOSE: &str = "</div>";
|
const ITEM_TABLE_ROW_CLOSE: &str = "</div>";
|
||||||
|
|
||||||
// A component in a `use` path, like `string` in std::string::ToString
|
// A component in a `use` path, like `string` in std::string::ToString
|
||||||
struct PathComponent<'a> {
|
struct PathComponent {
|
||||||
path: String,
|
path: String,
|
||||||
name: &'a str,
|
name: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -53,7 +54,7 @@ struct ItemVars<'a> {
|
||||||
typ: &'a str,
|
typ: &'a str,
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
item_type: &'a str,
|
item_type: &'a str,
|
||||||
path_components: Vec<PathComponent<'a>>,
|
path_components: Vec<PathComponent>,
|
||||||
stability_since_raw: &'a str,
|
stability_since_raw: &'a str,
|
||||||
src_href: Option<&'a str>,
|
src_href: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
@ -121,7 +122,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
|
||||||
.take(amt)
|
.take(amt)
|
||||||
.map(|(i, component)| PathComponent {
|
.map(|(i, component)| PathComponent {
|
||||||
path: "../".repeat(cur.len() - i - 1),
|
path: "../".repeat(cur.len() - i - 1),
|
||||||
name: component,
|
name: *component,
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
@ -304,22 +305,18 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
||||||
|
|
||||||
w.write_str(ITEM_TABLE_ROW_OPEN);
|
w.write_str(ITEM_TABLE_ROW_OPEN);
|
||||||
match *src {
|
match *src {
|
||||||
Some(ref src) => write!(
|
Some(src) => write!(
|
||||||
w,
|
w,
|
||||||
"<div class=\"item-left\"><code>{}extern crate {} as {};",
|
"<div class=\"item-left\"><code>{}extern crate {} as {};",
|
||||||
myitem.visibility.print_with_space(myitem.def_id, cx),
|
myitem.visibility.print_with_space(myitem.def_id, cx),
|
||||||
anchor(myitem.def_id.expect_def_id(), src.as_str(), cx),
|
anchor(myitem.def_id.expect_def_id(), src, cx),
|
||||||
myitem.name.as_ref().unwrap(),
|
myitem.name.as_ref().unwrap(),
|
||||||
),
|
),
|
||||||
None => write!(
|
None => write!(
|
||||||
w,
|
w,
|
||||||
"<div class=\"item-left\"><code>{}extern crate {};",
|
"<div class=\"item-left\"><code>{}extern crate {};",
|
||||||
myitem.visibility.print_with_space(myitem.def_id, cx),
|
myitem.visibility.print_with_space(myitem.def_id, cx),
|
||||||
anchor(
|
anchor(myitem.def_id.expect_def_id(), *myitem.name.as_ref().unwrap(), cx),
|
||||||
myitem.def_id.expect_def_id(),
|
|
||||||
myitem.name.as_ref().unwrap().as_str(),
|
|
||||||
cx
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
w.write_str("</code></div>");
|
w.write_str("</code></div>");
|
||||||
|
@ -864,10 +861,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
</script>",
|
</script>",
|
||||||
root_path = vec![".."; cx.current.len()].join("/"),
|
root_path = vec![".."; cx.current.len()].join("/"),
|
||||||
path = if it.def_id.is_local() {
|
path = if it.def_id.is_local() {
|
||||||
cx.current.join("/")
|
join_with_slash(None, &cx.current)
|
||||||
} else {
|
} else {
|
||||||
let (ref path, _) = cache.external_paths[&it.def_id.expect_def_id()];
|
let (ref path, _) = cache.external_paths[&it.def_id.expect_def_id()];
|
||||||
path[..path.len() - 1].join("/")
|
join_with_slash(None, &path[..path.len() - 1])
|
||||||
},
|
},
|
||||||
ty = it.type_(),
|
ty = it.type_(),
|
||||||
name = *it.name.as_ref().unwrap()
|
name = *it.name.as_ref().unwrap()
|
||||||
|
@ -1410,7 +1407,7 @@ crate fn compare_names(mut lhs: &str, mut rhs: &str) -> Ordering {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String {
|
pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String {
|
||||||
let mut s = cx.current.join("::");
|
let mut s = join_with_double_colon(&cx.current);
|
||||||
s.push_str("::");
|
s.push_str("::");
|
||||||
s.push_str(item.name.unwrap().as_str());
|
s.push_str(item.name.unwrap().as_str());
|
||||||
s
|
s
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::clean;
|
||||||
use crate::clean::types::{FnRetTy, Function, GenericBound, Generics, Type, WherePredicate};
|
use crate::clean::types::{FnRetTy, Function, GenericBound, Generics, Type, WherePredicate};
|
||||||
use crate::formats::cache::Cache;
|
use crate::formats::cache::Cache;
|
||||||
use crate::formats::item_type::ItemType;
|
use crate::formats::item_type::ItemType;
|
||||||
|
use crate::html::format::join_with_double_colon;
|
||||||
use crate::html::markdown::short_markdown_summary;
|
use crate::html::markdown::short_markdown_summary;
|
||||||
use crate::html::render::{IndexItem, IndexItemFunctionType, RenderType, TypeWithKind};
|
use crate::html::render::{IndexItem, IndexItemFunctionType, RenderType, TypeWithKind};
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
||||||
cache.search_index.push(IndexItem {
|
cache.search_index.push(IndexItem {
|
||||||
ty: item.type_(),
|
ty: item.type_(),
|
||||||
name: item.name.unwrap().to_string(),
|
name: item.name.unwrap().to_string(),
|
||||||
path: fqp[..fqp.len() - 1].join("::"),
|
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
|
||||||
desc,
|
desc,
|
||||||
parent: Some(did),
|
parent: Some(did),
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
|
@ -102,7 +103,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
||||||
struct CrateData<'a> {
|
struct CrateData<'a> {
|
||||||
doc: String,
|
doc: String,
|
||||||
items: Vec<&'a IndexItem>,
|
items: Vec<&'a IndexItem>,
|
||||||
paths: Vec<(ItemType, String)>,
|
paths: Vec<(ItemType, Symbol)>,
|
||||||
// The String is alias name and the vec is the list of the elements with this alias.
|
// The String is alias name and the vec is the list of the elements with this alias.
|
||||||
//
|
//
|
||||||
// To be noted: the `usize` elements are indexes to `items`.
|
// To be noted: the `usize` elements are indexes to `items`.
|
||||||
|
@ -154,7 +155,10 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
|
||||||
"f",
|
"f",
|
||||||
&self.items.iter().map(|item| &item.search_type).collect::<Vec<_>>(),
|
&self.items.iter().map(|item| &item.search_type).collect::<Vec<_>>(),
|
||||||
)?;
|
)?;
|
||||||
crate_data.serialize_field("p", &self.paths)?;
|
crate_data.serialize_field(
|
||||||
|
"p",
|
||||||
|
&self.paths.iter().map(|(it, s)| (it, s.to_string())).collect::<Vec<_>>(),
|
||||||
|
)?;
|
||||||
if has_aliases {
|
if has_aliases {
|
||||||
crate_data.serialize_field("a", &self.aliases)?;
|
crate_data.serialize_field("a", &self.aliases)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,7 +562,7 @@ pub(super) fn write_shared(
|
||||||
|
|
||||||
let mut mydst = dst.clone();
|
let mut mydst = dst.clone();
|
||||||
for part in &remote_path[..remote_path.len() - 1] {
|
for part in &remote_path[..remote_path.len() - 1] {
|
||||||
mydst.push(part);
|
mydst.push(part.to_string());
|
||||||
}
|
}
|
||||||
cx.shared.ensure_dir(&mydst)?;
|
cx.shared.ensure_dir(&mydst)?;
|
||||||
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
|
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
|
||||||
|
|
|
@ -1,44 +1,50 @@
|
||||||
use crate::html::format::href_relative_parts;
|
use crate::html::format::href_relative_parts;
|
||||||
|
use rustc_span::{sym, Symbol};
|
||||||
|
|
||||||
fn assert_relative_path(expected: &str, relative_to_fqp: &[&str], fqp: &[&str]) {
|
fn assert_relative_path(expected: &[Symbol], relative_to_fqp: &[Symbol], fqp: &[Symbol]) {
|
||||||
let relative_to_fqp: Vec<String> = relative_to_fqp.iter().copied().map(String::from).collect();
|
// No `create_default_session_globals_then` call is needed here because all
|
||||||
let fqp: Vec<String> = fqp.iter().copied().map(String::from).collect();
|
// the symbols used are static, and no `Symbol::intern` calls occur.
|
||||||
assert_eq!(expected, href_relative_parts(&fqp, &relative_to_fqp).finish());
|
assert_eq!(expected, href_relative_parts(&fqp, &relative_to_fqp).collect::<Vec<_>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href_relative_parts_basic() {
|
fn href_relative_parts_basic() {
|
||||||
let relative_to_fqp = &["std", "vec"];
|
let relative_to_fqp = &[sym::std, sym::vec];
|
||||||
let fqp = &["std", "iter"];
|
let fqp = &[sym::std, sym::iter];
|
||||||
assert_relative_path("../iter", relative_to_fqp, fqp);
|
assert_relative_path(&[sym::dotdot, sym::iter], relative_to_fqp, fqp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href_relative_parts_parent_module() {
|
fn href_relative_parts_parent_module() {
|
||||||
let relative_to_fqp = &["std", "vec"];
|
let relative_to_fqp = &[sym::std, sym::vec];
|
||||||
let fqp = &["std"];
|
let fqp = &[sym::std];
|
||||||
assert_relative_path("..", relative_to_fqp, fqp);
|
assert_relative_path(&[sym::dotdot], relative_to_fqp, fqp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href_relative_parts_different_crate() {
|
fn href_relative_parts_different_crate() {
|
||||||
let relative_to_fqp = &["std", "vec"];
|
let relative_to_fqp = &[sym::std, sym::vec];
|
||||||
let fqp = &["core", "iter"];
|
let fqp = &[sym::core, sym::iter];
|
||||||
assert_relative_path("../../core/iter", relative_to_fqp, fqp);
|
assert_relative_path(&[sym::dotdot, sym::dotdot, sym::core, sym::iter], relative_to_fqp, fqp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href_relative_parts_same_module() {
|
fn href_relative_parts_same_module() {
|
||||||
let relative_to_fqp = &["std", "vec"];
|
let relative_to_fqp = &[sym::std, sym::vec];
|
||||||
let fqp = &["std", "vec"];
|
let fqp = &[sym::std, sym::vec];
|
||||||
assert_relative_path("", relative_to_fqp, fqp);
|
assert_relative_path(&[], relative_to_fqp, fqp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href_relative_parts_child_module() {
|
fn href_relative_parts_child_module() {
|
||||||
let relative_to_fqp = &["std"];
|
let relative_to_fqp = &[sym::std];
|
||||||
let fqp = &["std", "vec"];
|
let fqp = &[sym::std, sym::vec];
|
||||||
assert_relative_path("vec", relative_to_fqp, fqp);
|
assert_relative_path(&[sym::vec], relative_to_fqp, fqp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href_relative_parts_root() {
|
fn href_relative_parts_root() {
|
||||||
let relative_to_fqp = &[];
|
let relative_to_fqp = &[];
|
||||||
let fqp = &["std"];
|
let fqp = &[sym::std];
|
||||||
assert_relative_path("std", relative_to_fqp, fqp);
|
assert_relative_path(&[sym::std], relative_to_fqp, fqp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
|
||||||
|
use rustc_span::Symbol;
|
||||||
|
|
||||||
/// A builder that allows efficiently and easily constructing the part of a URL
|
/// A builder that allows efficiently and easily constructing the part of a URL
|
||||||
/// after the domain: `nightly/core/str/struct.Bytes.html`.
|
/// after the domain: `nightly/core/str/struct.Bytes.html`.
|
||||||
///
|
///
|
||||||
|
@ -10,6 +14,7 @@ crate struct UrlPartsBuilder {
|
||||||
|
|
||||||
impl UrlPartsBuilder {
|
impl UrlPartsBuilder {
|
||||||
/// Create an empty buffer.
|
/// Create an empty buffer.
|
||||||
|
#[allow(dead_code)]
|
||||||
crate fn new() -> Self {
|
crate fn new() -> Self {
|
||||||
Self { buf: String::new() }
|
Self { buf: String::new() }
|
||||||
}
|
}
|
||||||
|
@ -62,6 +67,13 @@ impl UrlPartsBuilder {
|
||||||
self.buf.push_str(part);
|
self.buf.push_str(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate fn push_fmt(&mut self, args: fmt::Arguments<'_>) {
|
||||||
|
if !self.buf.is_empty() {
|
||||||
|
self.buf.push('/');
|
||||||
|
}
|
||||||
|
self.buf.write_fmt(args).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// Push a component onto the front of the buffer.
|
/// Push a component onto the front of the buffer.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -115,5 +127,26 @@ impl<'a> Extend<&'a str> for UrlPartsBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromIterator<Symbol> for UrlPartsBuilder {
|
||||||
|
fn from_iter<T: IntoIterator<Item = Symbol>>(iter: T) -> Self {
|
||||||
|
// This code has to be duplicated from the `&str` impl because of
|
||||||
|
// `Symbol::as_str`'s lifetimes.
|
||||||
|
let iter = iter.into_iter();
|
||||||
|
let mut builder = Self::with_capacity_bytes(AVG_PART_LENGTH * iter.size_hint().0);
|
||||||
|
iter.for_each(|part| builder.push(part.as_str()));
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Extend<Symbol> for UrlPartsBuilder {
|
||||||
|
fn extend<T: IntoIterator<Item = Symbol>>(&mut self, iter: T) {
|
||||||
|
// This code has to be duplicated from the `&str` impl because of
|
||||||
|
// `Symbol::as_str`'s lifetimes.
|
||||||
|
let iter = iter.into_iter();
|
||||||
|
self.buf.reserve(AVG_PART_LENGTH * iter.size_hint().0);
|
||||||
|
iter.for_each(|part| self.push(part.as_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'tcx> JsonRenderer<'tcx> {
|
||||||
})
|
})
|
||||||
.0
|
.0
|
||||||
.last()
|
.last()
|
||||||
.map(Clone::clone),
|
.map(|s| s.to_string()),
|
||||||
visibility: types::Visibility::Public,
|
visibility: types::Visibility::Public,
|
||||||
inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
|
inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
|
||||||
span: None,
|
span: None,
|
||||||
|
@ -230,7 +230,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
||||||
from_item_id(k.into()),
|
from_item_id(k.into()),
|
||||||
types::ItemSummary {
|
types::ItemSummary {
|
||||||
crate_id: k.krate.as_u32(),
|
crate_id: k.krate.as_u32(),
|
||||||
path,
|
path: path.iter().map(|s| s.to_string()).collect(),
|
||||||
kind: kind.into_tcx(self.tcx),
|
kind: kind.into_tcx(self.tcx),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::definitions::DefPathData;
|
|
||||||
use rustc_hir::Node;
|
use rustc_hir::Node;
|
||||||
use rustc_hir::CRATE_HIR_ID;
|
use rustc_hir::CRATE_HIR_ID;
|
||||||
use rustc_middle::middle::privacy::AccessLevel;
|
use rustc_middle::middle::privacy::AccessLevel;
|
||||||
|
@ -43,12 +42,9 @@ impl Module<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Should this be replaced with tcx.def_path_str?
|
// FIXME: Should this be replaced with tcx.def_path_str?
|
||||||
fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<String> {
|
fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<Symbol> {
|
||||||
let crate_name = tcx.crate_name(did.krate).to_string();
|
let crate_name = tcx.crate_name(did.krate);
|
||||||
let relative = tcx.def_path(did).data.into_iter().filter_map(|elem| {
|
let relative = tcx.def_path(did).data.into_iter().filter_map(|elem| elem.data.get_opt_name());
|
||||||
// Filter out extern blocks
|
|
||||||
(elem.data != DefPathData::ForeignMod).then(|| elem.data.to_string())
|
|
||||||
});
|
|
||||||
std::iter::once(crate_name).chain(relative).collect()
|
std::iter::once(crate_name).chain(relative).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +67,7 @@ crate struct RustdocVisitor<'a, 'tcx> {
|
||||||
inlining: bool,
|
inlining: bool,
|
||||||
/// Are the current module and all of its parents public?
|
/// Are the current module and all of its parents public?
|
||||||
inside_public_path: bool,
|
inside_public_path: bool,
|
||||||
exact_paths: FxHashMap<DefId, Vec<String>>,
|
exact_paths: FxHashMap<DefId, Vec<Symbol>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue