Rollup merge of #106855 - klensy:rd-s, r=notriddle
rustdoc: few small cleanups
This commit is contained in:
commit
bc0c816410
7 changed files with 33 additions and 28 deletions
|
@ -242,7 +242,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index this method for searching later on.
|
// Index this method for searching later on.
|
||||||
if let Some(ref s) = item.name.or_else(|| {
|
if let Some(s) = item.name.or_else(|| {
|
||||||
if item.is_stripped() {
|
if item.is_stripped() {
|
||||||
None
|
None
|
||||||
} else if let clean::ImportItem(ref i) = *item.kind &&
|
} else if let clean::ImportItem(ref i) = *item.kind &&
|
||||||
|
@ -317,14 +317,15 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
|
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
|
||||||
});
|
});
|
||||||
let ty = item.type_();
|
let ty = item.type_();
|
||||||
let name = s.to_string();
|
if ty != ItemType::StructField
|
||||||
if ty != ItemType::StructField || u16::from_str_radix(&name, 10).is_err() {
|
|| u16::from_str_radix(s.as_str(), 10).is_err()
|
||||||
|
{
|
||||||
// In case this is a field from a tuple struct, we don't add it into
|
// In case this is a field from a tuple struct, we don't add it into
|
||||||
// the search index because its name is something like "0", which is
|
// the search index because its name is something like "0", which is
|
||||||
// not useful for rustdoc search.
|
// not useful for rustdoc search.
|
||||||
self.cache.search_index.push(IndexItem {
|
self.cache.search_index.push(IndexItem {
|
||||||
ty,
|
ty,
|
||||||
name,
|
name: s,
|
||||||
path: join_with_double_colon(path),
|
path: join_with_double_colon(path),
|
||||||
desc,
|
desc,
|
||||||
parent,
|
parent,
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -1050,7 +1055,7 @@ fn fmt_type<'cx>(
|
||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
};
|
};
|
||||||
let m = mutability.print_with_space();
|
let m = mutability.print_with_space();
|
||||||
let amp = if f.alternate() { "&".to_string() } else { "&".to_string() };
|
let amp = if f.alternate() { "&" } else { "&" };
|
||||||
match **ty {
|
match **ty {
|
||||||
clean::DynTrait(ref bounds, ref trait_lt)
|
clean::DynTrait(ref bounds, ref trait_lt)
|
||||||
if bounds.len() > 1 || trait_lt.is_some() =>
|
if bounds.len() > 1 || trait_lt.is_some() =>
|
||||||
|
|
|
@ -30,7 +30,7 @@ use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::Span;
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -198,7 +198,7 @@ fn slugify(c: char) -> Option<char> {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Playground {
|
pub struct Playground {
|
||||||
pub crate_name: Option<String>,
|
pub crate_name: Option<Symbol>,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
|
||||||
.map(|l| map_line(l).for_code())
|
.map(|l| map_line(l).for_code())
|
||||||
.intersperse("\n".into())
|
.intersperse("\n".into())
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
let krate = krate.as_ref().map(|s| &**s);
|
let krate = krate.as_ref().map(|s| s.as_str());
|
||||||
let (test, _, _) =
|
let (test, _, _) =
|
||||||
doctest::make_test(&test, krate, false, &Default::default(), edition, None);
|
doctest::make_test(&test, krate, false, &Default::default(), edition, None);
|
||||||
let channel = if test.contains("#![feature(") { "&version=nightly" } else { "" };
|
let channel = if test.contains("#![feature(") { "&version=nightly" } else { "" };
|
||||||
|
|
|
@ -464,8 +464,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
// If user passed in `--playground-url` arg, we fill in crate name here
|
// If user passed in `--playground-url` arg, we fill in crate name here
|
||||||
let mut playground = None;
|
let mut playground = None;
|
||||||
if let Some(url) = playground_url {
|
if let Some(url) = playground_url {
|
||||||
playground =
|
playground = Some(markdown::Playground { crate_name: Some(krate.name(tcx)), url });
|
||||||
Some(markdown::Playground { crate_name: Some(krate.name(tcx).to_string()), url });
|
|
||||||
}
|
}
|
||||||
let mut layout = layout::Layout {
|
let mut layout = layout::Layout {
|
||||||
logo: String::new(),
|
logo: String::new(),
|
||||||
|
@ -491,7 +490,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
}
|
}
|
||||||
(sym::html_playground_url, Some(s)) => {
|
(sym::html_playground_url, Some(s)) => {
|
||||||
playground = Some(markdown::Playground {
|
playground = Some(markdown::Playground {
|
||||||
crate_name: Some(krate.name(tcx).to_string()),
|
crate_name: Some(krate.name(tcx)),
|
||||||
url: s.to_string(),
|
url: s.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct IndexItem {
|
pub(crate) struct IndexItem {
|
||||||
pub(crate) ty: ItemType,
|
pub(crate) ty: ItemType,
|
||||||
pub(crate) name: String,
|
pub(crate) name: Symbol,
|
||||||
pub(crate) path: String,
|
pub(crate) path: String,
|
||||||
pub(crate) desc: String,
|
pub(crate) desc: String,
|
||||||
pub(crate) parent: Option<DefId>,
|
pub(crate) parent: Option<DefId>,
|
||||||
|
@ -2769,8 +2769,8 @@ fn collect_paths_for_type(first_ty: clean::Type, cache: &Cache) -> Vec<String> {
|
||||||
let mut work = VecDeque::new();
|
let mut work = VecDeque::new();
|
||||||
|
|
||||||
let mut process_path = |did: DefId| {
|
let mut process_path = |did: DefId| {
|
||||||
let get_extern = || cache.external_paths.get(&did).map(|s| s.0.clone());
|
let get_extern = || cache.external_paths.get(&did).map(|s| &s.0);
|
||||||
let fqp = cache.exact_paths.get(&did).cloned().or_else(get_extern);
|
let fqp = cache.exact_paths.get(&did).or_else(get_extern);
|
||||||
|
|
||||||
if let Some(path) = fqp {
|
if let Some(path) = fqp {
|
||||||
out.push(join_with_double_colon(&path));
|
out.push(join_with_double_colon(&path));
|
||||||
|
|
|
@ -1027,8 +1027,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||||
.chain(std::iter::once("implementors"))
|
.chain(std::iter::once("implementors"))
|
||||||
.collect();
|
.collect();
|
||||||
if let Some(did) = it.item_id.as_def_id() &&
|
if let Some(did) = it.item_id.as_def_id() &&
|
||||||
let get_extern = { || cache.external_paths.get(&did).map(|s| s.0.clone()) } &&
|
let get_extern = { || cache.external_paths.get(&did).map(|s| &s.0) } &&
|
||||||
let Some(fqp) = cache.exact_paths.get(&did).cloned().or_else(get_extern) {
|
let Some(fqp) = cache.exact_paths.get(&did).or_else(get_extern) {
|
||||||
js_src_path.extend(fqp[..fqp.len() - 1].iter().copied());
|
js_src_path.extend(fqp[..fqp.len() - 1].iter().copied());
|
||||||
js_src_path.push_fmt(format_args!("{}.{}.js", it.type_(), fqp.last().unwrap()));
|
js_src_path.push_fmt(format_args!("{}.{}.js", it.type_(), fqp.last().unwrap()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub(crate) fn build_index<'tcx>(
|
||||||
.map_or_else(String::new, |s| short_markdown_summary(&s, &item.link_names(cache)));
|
.map_or_else(String::new, |s| short_markdown_summary(&s, &item.link_names(cache)));
|
||||||
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(),
|
||||||
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
|
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
|
||||||
desc,
|
desc,
|
||||||
parent: Some(parent),
|
parent: Some(parent),
|
||||||
|
@ -58,8 +58,8 @@ pub(crate) fn build_index<'tcx>(
|
||||||
// Sort search index items. This improves the compressibility of the search index.
|
// Sort search index items. This improves the compressibility of the search index.
|
||||||
cache.search_index.sort_unstable_by(|k1, k2| {
|
cache.search_index.sort_unstable_by(|k1, k2| {
|
||||||
// `sort_unstable_by_key` produces lifetime errors
|
// `sort_unstable_by_key` produces lifetime errors
|
||||||
let k1 = (&k1.path, &k1.name, &k1.ty, &k1.parent);
|
let k1 = (&k1.path, k1.name.as_str(), &k1.ty, &k1.parent);
|
||||||
let k2 = (&k2.path, &k2.name, &k2.ty, &k2.parent);
|
let k2 = (&k2.path, k2.name.as_str(), &k2.ty, &k2.parent);
|
||||||
std::cmp::Ord::cmp(&k1, &k2)
|
std::cmp::Ord::cmp(&k1, &k2)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ pub(crate) fn build_index<'tcx>(
|
||||||
)?;
|
)?;
|
||||||
crate_data.serialize_field(
|
crate_data.serialize_field(
|
||||||
"n",
|
"n",
|
||||||
&self.items.iter().map(|item| &item.name).collect::<Vec<_>>(),
|
&self.items.iter().map(|item| item.name.as_str()).collect::<Vec<_>>(),
|
||||||
)?;
|
)?;
|
||||||
crate_data.serialize_field(
|
crate_data.serialize_field(
|
||||||
"q",
|
"q",
|
||||||
|
@ -299,7 +299,7 @@ pub(crate) fn build_index<'tcx>(
|
||||||
)?;
|
)?;
|
||||||
crate_data.serialize_field(
|
crate_data.serialize_field(
|
||||||
"p",
|
"p",
|
||||||
&self.paths.iter().map(|(it, s)| (it, s.to_string())).collect::<Vec<_>>(),
|
&self.paths.iter().map(|(it, s)| (it, s.as_str())).collect::<Vec<_>>(),
|
||||||
)?;
|
)?;
|
||||||
if has_aliases {
|
if has_aliases {
|
||||||
crate_data.serialize_field("a", &self.aliases)?;
|
crate_data.serialize_field("a", &self.aliases)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue