Rollup merge of #134772 - GuillaumeGomez:improve-rustdoc, r=notriddle
Improve/cleanup rustdoc code Ran clippy on rustdoc, always beneficial. :) r? `@notriddle`
This commit is contained in:
commit
3e02ddb234
12 changed files with 22 additions and 24 deletions
|
@ -894,7 +894,7 @@ fn clean_ty_generics<'tcx>(
|
||||||
|
|
||||||
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
|
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
|
||||||
// Since all potential trait bounds are at the front we can just check the first bound.
|
// Since all potential trait bounds are at the front we can just check the first bound.
|
||||||
if bounds.first().map_or(true, |b| !b.is_trait_bound()) {
|
if bounds.first().is_none_or(|b| !b.is_trait_bound()) {
|
||||||
bounds.insert(0, GenericBound::sized(cx));
|
bounds.insert(0, GenericBound::sized(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1811,7 +1811,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
||||||
}
|
}
|
||||||
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
||||||
TyKind::Pat(ty, pat) => Type::Pat(Box::new(clean_ty(ty, cx)), format!("{pat:?}").into()),
|
TyKind::Pat(ty, pat) => Type::Pat(Box::new(clean_ty(ty, cx)), format!("{pat:?}").into()),
|
||||||
TyKind::Array(ty, ref const_arg) => {
|
TyKind::Array(ty, const_arg) => {
|
||||||
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
||||||
// as we currently do not supply the parent generics to anonymous constants
|
// as we currently do not supply the parent generics to anonymous constants
|
||||||
// but do allow `ConstKind::Param`.
|
// but do allow `ConstKind::Param`.
|
||||||
|
@ -2337,7 +2337,7 @@ fn clean_middle_opaque_bounds<'tcx>(
|
||||||
|
|
||||||
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
|
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
|
||||||
// Since all potential trait bounds are at the front we can just check the first bound.
|
// Since all potential trait bounds are at the front we can just check the first bound.
|
||||||
if bounds.first().map_or(true, |b| !b.is_trait_bound()) {
|
if bounds.first().is_none_or(|b| !b.is_trait_bound()) {
|
||||||
bounds.insert(0, GenericBound::sized(cx));
|
bounds.insert(0, GenericBound::sized(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
|
||||||
} = interface::run_compiler(config, |compiler| {
|
} = interface::run_compiler(config, |compiler| {
|
||||||
let krate = rustc_interface::passes::parse(&compiler.sess);
|
let krate = rustc_interface::passes::parse(&compiler.sess);
|
||||||
|
|
||||||
let collector = rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
let collector = rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| {
|
||||||
let crate_name = tcx.crate_name(LOCAL_CRATE).to_string();
|
let crate_name = tcx.crate_name(LOCAL_CRATE).to_string();
|
||||||
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
||||||
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
|
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
|
||||||
|
|
|
@ -538,7 +538,7 @@ fn handle_attr(mod_attr_pending: &mut String, source_info: &mut SourceInfo, edit
|
||||||
// If it's complete, then we can clear the pending content.
|
// If it's complete, then we can clear the pending content.
|
||||||
mod_attr_pending.clear();
|
mod_attr_pending.clear();
|
||||||
} else {
|
} else {
|
||||||
mod_attr_pending.push_str("\n");
|
mod_attr_pending.push('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,7 +413,7 @@ impl DocFolder for CacheBuilder<'_, '_> {
|
||||||
let impl_item = Impl { impl_item: item };
|
let impl_item = Impl { impl_item: item };
|
||||||
let impl_did = impl_item.def_id();
|
let impl_did = impl_item.def_id();
|
||||||
let trait_did = impl_item.trait_did();
|
let trait_did = impl_item.trait_did();
|
||||||
if trait_did.map_or(true, |d| self.cache.traits.contains_key(&d)) {
|
if trait_did.is_none_or(|d| self.cache.traits.contains_key(&d)) {
|
||||||
for did in dids {
|
for did in dids {
|
||||||
if self.impl_ids.entry(did).or_default().insert(impl_did) {
|
if self.impl_ids.entry(did).or_default().insert(impl_did) {
|
||||||
self.cache.impls.entry(did).or_default().push(impl_item.clone());
|
self.cache.impls.entry(did).or_default().push(impl_item.clone());
|
||||||
|
|
|
@ -104,10 +104,9 @@ impl fmt::Display for EscapeBodyTextWithWbr<'_> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let is_uppercase = || s.chars().any(|c| c.is_uppercase());
|
let is_uppercase = || s.chars().any(|c| c.is_uppercase());
|
||||||
let next_is_uppercase =
|
let next_is_uppercase = || pk.is_none_or(|(_, t)| t.chars().any(|c| c.is_uppercase()));
|
||||||
|| pk.map_or(true, |(_, t)| t.chars().any(|c| c.is_uppercase()));
|
let next_is_underscore = || pk.is_none_or(|(_, t)| t.contains('_'));
|
||||||
let next_is_underscore = || pk.map_or(true, |(_, t)| t.contains('_'));
|
let next_is_colon = || pk.is_none_or(|(_, t)| t.contains(':'));
|
||||||
let next_is_colon = || pk.map_or(true, |(_, t)| t.contains(':'));
|
|
||||||
// Check for CamelCase.
|
// Check for CamelCase.
|
||||||
//
|
//
|
||||||
// `i - last > 3` avoids turning FmRadio into Fm<wbr>Radio, which is technically
|
// `i - last > 3` avoids turning FmRadio into Fm<wbr>Radio, which is technically
|
||||||
|
|
|
@ -480,7 +480,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for SpannedLinkReplacer<
|
||||||
type Item = SpannedEvent<'a>;
|
type Item = SpannedEvent<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let Some((mut event, range)) = self.iter.next() else { return None };
|
let (mut event, range) = self.iter.next()?;
|
||||||
self.inner.handle_event(&mut event);
|
self.inner.handle_event(&mut event);
|
||||||
// Yield the modified event
|
// Yield the modified event
|
||||||
Some((event, range))
|
Some((event, range))
|
||||||
|
@ -2039,7 +2039,7 @@ impl IdMap {
|
||||||
let candidate = candidate.to_string();
|
let candidate = candidate.to_string();
|
||||||
if is_default_id(&candidate) {
|
if is_default_id(&candidate) {
|
||||||
let id = format!("{}-{}", candidate, 1);
|
let id = format!("{}-{}", candidate, 1);
|
||||||
self.map.insert(candidate.into(), 2);
|
self.map.insert(candidate, 2);
|
||||||
id
|
id
|
||||||
} else {
|
} else {
|
||||||
candidate
|
candidate
|
||||||
|
@ -2052,7 +2052,7 @@ impl IdMap {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.map.insert(id.clone().into(), 1);
|
self.map.insert(id.clone(), 1);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -748,7 +748,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
&shared.layout,
|
&shared.layout,
|
||||||
&page,
|
&page,
|
||||||
"",
|
"",
|
||||||
scrape_examples_help(&shared),
|
scrape_examples_help(shared),
|
||||||
&shared.style_files,
|
&shared.style_files,
|
||||||
);
|
);
|
||||||
shared.fs.write(scrape_examples_help_file, v)?;
|
shared.fs.write(scrape_examples_help_file, v)?;
|
||||||
|
|
|
@ -1974,7 +1974,7 @@ fn render_impl(
|
||||||
.opt_doc_value()
|
.opt_doc_value()
|
||||||
.map(|dox| {
|
.map(|dox| {
|
||||||
Markdown {
|
Markdown {
|
||||||
content: &*dox,
|
content: &dox,
|
||||||
links: &i.impl_item.links(cx),
|
links: &i.impl_item.links(cx),
|
||||||
ids: &mut cx.id_map.borrow_mut(),
|
ids: &mut cx.id_map.borrow_mut(),
|
||||||
error_codes: cx.shared.codes,
|
error_codes: cx.shared.codes,
|
||||||
|
|
|
@ -1420,7 +1420,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
|
||||||
ty: &'a clean::Type,
|
ty: &'a clean::Type,
|
||||||
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
|
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
|
||||||
display_fn(move |f| {
|
display_fn(move |f| {
|
||||||
let v = ty.print(&self.cx);
|
let v = ty.print(self.cx);
|
||||||
write!(f, "{v}")
|
write!(f, "{v}")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,15 +312,15 @@ fn from_clean_item(item: clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum {
|
||||||
StructFieldItem(f) => ItemEnum::StructField(f.into_json(renderer)),
|
StructFieldItem(f) => ItemEnum::StructField(f.into_json(renderer)),
|
||||||
EnumItem(e) => ItemEnum::Enum(e.into_json(renderer)),
|
EnumItem(e) => ItemEnum::Enum(e.into_json(renderer)),
|
||||||
VariantItem(v) => ItemEnum::Variant(v.into_json(renderer)),
|
VariantItem(v) => ItemEnum::Variant(v.into_json(renderer)),
|
||||||
FunctionItem(f) => ItemEnum::Function(from_function(f, true, header.unwrap(), renderer)),
|
FunctionItem(f) => ItemEnum::Function(from_function(*f, true, header.unwrap(), renderer)),
|
||||||
ForeignFunctionItem(f, _) => {
|
ForeignFunctionItem(f, _) => {
|
||||||
ItemEnum::Function(from_function(f, false, header.unwrap(), renderer))
|
ItemEnum::Function(from_function(*f, false, header.unwrap(), renderer))
|
||||||
}
|
}
|
||||||
TraitItem(t) => ItemEnum::Trait((*t).into_json(renderer)),
|
TraitItem(t) => ItemEnum::Trait((*t).into_json(renderer)),
|
||||||
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_json(renderer)),
|
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_json(renderer)),
|
||||||
MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), renderer)),
|
MethodItem(m, _) => ItemEnum::Function(from_function(*m, true, header.unwrap(), renderer)),
|
||||||
RequiredMethodItem(m) => {
|
RequiredMethodItem(m) => {
|
||||||
ItemEnum::Function(from_function(m, false, header.unwrap(), renderer))
|
ItemEnum::Function(from_function(*m, false, header.unwrap(), renderer))
|
||||||
}
|
}
|
||||||
ImplItem(i) => ItemEnum::Impl((*i).into_json(renderer)),
|
ImplItem(i) => ItemEnum::Impl((*i).into_json(renderer)),
|
||||||
StaticItem(s) => ItemEnum::Static(convert_static(s, rustc_hir::Safety::Safe, renderer)),
|
StaticItem(s) => ItemEnum::Static(convert_static(s, rustc_hir::Safety::Safe, renderer)),
|
||||||
|
@ -730,12 +730,11 @@ impl FromClean<clean::Impl> for Impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_function(
|
pub(crate) fn from_function(
|
||||||
function: Box<clean::Function>,
|
clean::Function { decl, generics }: clean::Function,
|
||||||
has_body: bool,
|
has_body: bool,
|
||||||
header: rustc_hir::FnHeader,
|
header: rustc_hir::FnHeader,
|
||||||
renderer: &JsonRenderer<'_>,
|
renderer: &JsonRenderer<'_>,
|
||||||
) -> Function {
|
) -> Function {
|
||||||
let clean::Function { decl, generics } = *function;
|
|
||||||
Function {
|
Function {
|
||||||
sig: decl.into_json(renderer),
|
sig: decl.into_json(renderer),
|
||||||
generics: generics.into_json(renderer),
|
generics: generics.into_json(renderer),
|
||||||
|
|
|
@ -869,7 +869,7 @@ fn main_args(
|
||||||
sess.dcx().fatal("Compilation failed, aborting rustdoc");
|
sess.dcx().fatal("Compilation failed, aborting rustdoc");
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_interface::create_and_enter_global_ctxt(&compiler, krate, |tcx| {
|
rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| {
|
||||||
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
|
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
|
||||||
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
|
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
|
||||||
});
|
});
|
||||||
|
|
|
@ -1977,7 +1977,7 @@ fn resolution_failure(
|
||||||
}
|
}
|
||||||
|
|
||||||
if !path_str.contains("::") {
|
if !path_str.contains("::") {
|
||||||
if disambiguator.map_or(true, |d| d.ns() == MacroNS)
|
if disambiguator.is_none_or(|d| d.ns() == MacroNS)
|
||||||
&& collector
|
&& collector
|
||||||
.cx
|
.cx
|
||||||
.tcx
|
.tcx
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue