Skip to content

Commit

Permalink
Unrolled build for rust-lang#134772
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#134772 - GuillaumeGomez:improve-rustdoc, r=notriddle

Improve/cleanup rustdoc code

Ran clippy on rustdoc, always beneficial. :)

r? `@notriddle`
  • Loading branch information
rust-timer authored Dec 26, 2024
2 parents 19e75f4 + bdc8df4 commit a71d4b1
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ fn clean_ty_generics<'tcx>(

// 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.
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));
}

Expand Down Expand Up @@ -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::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
// as we currently do not supply the parent generics to anonymous constants
// but do allow `ConstKind::Param`.
Expand Down Expand Up @@ -2337,7 +2337,7 @@ fn clean_middle_opaque_bounds<'tcx>(

// 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.
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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
} = interface::run_compiler(config, |compiler| {
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_attrs = tcx.hir().attrs(CRATE_HIR_ID);
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
mod_attr_pending.clear();
} else {
mod_attr_pending.push_str("\n");
mod_attr_pending.push('\n');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl DocFolder for CacheBuilder<'_, '_> {
let impl_item = Impl { impl_item: item };
let impl_did = impl_item.def_id();
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 {
if self.impl_ids.entry(did).or_default().insert(impl_did) {
self.cache.impls.entry(did).or_default().push(impl_item.clone());
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/html/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ impl fmt::Display for EscapeBodyTextWithWbr<'_> {
continue;
}
let is_uppercase = || s.chars().any(|c| c.is_uppercase());
let next_is_uppercase =
|| pk.map_or(true, |(_, t)| t.chars().any(|c| c.is_uppercase()));
let next_is_underscore = || pk.map_or(true, |(_, t)| t.contains('_'));
let next_is_colon = || pk.map_or(true, |(_, t)| t.contains(':'));
let next_is_uppercase = || pk.is_none_or(|(_, t)| t.chars().any(|c| c.is_uppercase()));
let next_is_underscore = || pk.is_none_or(|(_, t)| t.contains('_'));
let next_is_colon = || pk.is_none_or(|(_, t)| t.contains(':'));
// Check for CamelCase.
//
// `i - last > 3` avoids turning FmRadio into Fm<wbr>Radio, which is technically
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for SpannedLinkReplacer<
type Item = SpannedEvent<'a>;

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);
// Yield the modified event
Some((event, range))
Expand Down Expand Up @@ -2039,7 +2039,7 @@ impl IdMap {
let candidate = candidate.to_string();
if is_default_id(&candidate) {
let id = format!("{}-{}", candidate, 1);
self.map.insert(candidate.into(), 2);
self.map.insert(candidate, 2);
id
} else {
candidate
Expand All @@ -2052,7 +2052,7 @@ impl IdMap {
}
};

self.map.insert(id.clone().into(), 1);
self.map.insert(id.clone(), 1);
id
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
&shared.layout,
&page,
"",
scrape_examples_help(&shared),
scrape_examples_help(shared),
&shared.style_files,
);
shared.fs.write(scrape_examples_help_file, v)?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ fn render_impl(
.opt_doc_value()
.map(|dox| {
Markdown {
content: &*dox,
content: &dox,
links: &i.impl_item.links(cx),
ids: &mut cx.id_map.borrow_mut(),
error_codes: cx.shared.codes,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
ty: &'a clean::Type,
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
let v = ty.print(&self.cx);
let v = ty.print(self.cx);
write!(f, "{v}")
})
}
Expand Down
11 changes: 5 additions & 6 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ fn from_clean_item(item: clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum {
StructFieldItem(f) => ItemEnum::StructField(f.into_json(renderer)),
EnumItem(e) => ItemEnum::Enum(e.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, _) => {
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)),
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) => {
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)),
StaticItem(s) => ItemEnum::Static(convert_static(s, rustc_hir::Safety::Safe, renderer)),
Expand Down Expand Up @@ -730,12 +730,11 @@ impl FromClean<clean::Impl> for Impl {
}

pub(crate) fn from_function(
function: Box<clean::Function>,
clean::Function { decl, generics }: clean::Function,
has_body: bool,
header: rustc_hir::FnHeader,
renderer: &JsonRenderer<'_>,
) -> Function {
let clean::Function { decl, generics } = *function;
Function {
sig: decl.into_json(renderer),
generics: generics.into_json(renderer),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ fn main_args(
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", || {
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ fn resolution_failure(
}

if !path_str.contains("::") {
if disambiguator.map_or(true, |d| d.ns() == MacroNS)
if disambiguator.is_none_or(|d| d.ns() == MacroNS)
&& collector
.cx
.tcx
Expand Down

0 comments on commit a71d4b1

Please sign in to comment.