1
Fork 0

x clippy src/librustdoc --fix

This commit is contained in:
Yotam Ofek 2025-03-06 16:06:41 +00:00
parent 30f168ef81
commit ccfbfe2292
12 changed files with 24 additions and 29 deletions

View file

@ -2539,7 +2539,7 @@ fn clean_generic_args<'tcx>(
) -> GenericArgs {
// FIXME(return_type_notation): Fix RTN parens rendering
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<ThinVec<_>>().into();
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<ThinVec<_>>();
let output = match output.kind {
hir::TyKind::Tup(&[]) => None,
_ => Some(Box::new(clean_ty(output, cx))),
@ -2560,8 +2560,7 @@ fn clean_generic_args<'tcx>(
}
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect::<ThinVec<_>>()
.into();
.collect::<ThinVec<_>>();
let constraints = generic_args
.constraints
.iter()

View file

@ -2419,7 +2419,7 @@ impl ConstantKind {
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
rendered_const(tcx, tcx.hir_body(body), tcx.hir_body_owner_def_id(body))
}
ConstantKind::Infer { .. } => "_".to_string(),
ConstantKind::Infer => "_".to_string(),
}
}

View file

@ -223,7 +223,7 @@ fn clean_middle_generic_args_with_constraints<'tcx>(
let args = clean_middle_generic_args(cx, args.map_bound(|args| &args[..]), has_self, did);
GenericArgs::AngleBracketed { args: args.into(), constraints }
GenericArgs::AngleBracketed { args: args, constraints }
}
pub(super) fn clean_middle_path<'tcx>(
@ -524,7 +524,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
| AssocConst
| Variant
| Fn
| TyAlias { .. }
| TyAlias
| Enum
| Trait
| Struct

View file

@ -22,7 +22,7 @@ where
let mut iter = self.into_iter();
let Some(first) = iter.next() else { return Ok(()) };
first.fmt(f)?;
while let Some(item) = iter.next() {
for item in iter {
f.write_str(sep)?;
item.fmt(f)?;
}

View file

@ -33,7 +33,7 @@ impl ExtractedDocTests {
opts: &super::GlobalTestOptions,
options: &RustdocOptions,
) {
let edition = scraped_test.edition(&options);
let edition = scraped_test.edition(options);
let ScrapedDocTest { filename, line, langstr, text, name } = scraped_test;
@ -48,7 +48,7 @@ impl ExtractedDocTests {
let (full_test_code, size) = doctest.generate_unique_doctest(
&text,
langstr.test_harness,
&opts,
opts,
Some(&opts.crate_name),
);
self.doctests.push(ExtractedDocTest {

View file

@ -625,8 +625,7 @@ pub(crate) fn href_relative_parts<'fqp>(
let dissimilar_part_count = relative_to_fqp.len() - i;
let fqp_module = &fqp[i..fqp.len()];
return Box::new(
iter::repeat(sym::dotdot)
.take(dissimilar_part_count)
std::iter::repeat_n(sym::dotdot, dissimilar_part_count)
.chain(fqp_module.iter().copied()),
);
}
@ -639,7 +638,7 @@ pub(crate) fn href_relative_parts<'fqp>(
Ordering::Greater => {
// e.g. linking to std::sync from std::sync::atomic
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
Box::new(std::iter::repeat_n(sym::dotdot, dissimilar_part_count))
}
Ordering::Equal => {
// linking to the same module
@ -770,10 +769,9 @@ fn primitive_link_fragment(
ExternalLocation::Local => {
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
Some(if cx.current.first() == Some(&cname_sym) {
iter::repeat(sym::dotdot).take(cx.current.len() - 1).collect()
std::iter::repeat_n(sym::dotdot, cx.current.len() - 1).collect()
} else {
iter::repeat(sym::dotdot)
.take(cx.current.len())
std::iter::repeat_n(sym::dotdot, cx.current.len())
.chain(iter::once(cname_sym))
.collect()
})

View file

@ -100,7 +100,7 @@ fn write_header(
}
if let Some(extra) = extra_content {
out.push_str(&extra);
out.push_str(extra);
}
if class.is_empty() {
write_str(
@ -233,7 +233,7 @@ impl<F: Write> TokenHandler<'_, '_, F> {
#[inline]
fn write_line_number(&mut self, line: u32, extra: &'static str) {
(self.write_line_number)(&mut self.out, line, extra);
(self.write_line_number)(self.out, line, extra);
}
}
@ -610,7 +610,7 @@ impl Decorations {
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
.0
.iter()
.flat_map(|(&kind, ranges)| ranges.into_iter().map(move |&(lo, hi)| ((lo, kind), hi)))
.flat_map(|(&kind, ranges)| ranges.iter().map(move |&(lo, hi)| ((lo, kind), hi)))
.unzip();
// Sort the sequences in document order.

View file

@ -1792,7 +1792,7 @@ pub(crate) fn markdown_links<'md, R>(
}
}
} else if !c.is_ascii_whitespace() {
while let Some((j, c)) = iter.next() {
for (j, c) in iter.by_ref() {
if c.is_ascii_whitespace() {
return MarkdownLinkRange::Destination(i + span.start..j + span.start);
}

View file

@ -1192,8 +1192,7 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt:
// to already be in the HTML, and will be ignored.
//
// [JSONP]: https://en.wikipedia.org/wiki/JSONP
let mut js_src_path: UrlPartsBuilder = std::iter::repeat("..")
.take(cx.current.len())
let mut js_src_path: UrlPartsBuilder = std::iter::repeat_n("..", cx.current.len())
.chain(std::iter::once("trait.impl"))
.collect();
if let Some(did) = it.item_id.as_def_id()
@ -1446,8 +1445,7 @@ fn item_type_alias(cx: &Context<'_>, it: &clean::Item, t: &clean::TypeAlias) ->
&& let get_local = { || cache.paths.get(&self_did).map(|(p, _)| p) }
&& let Some(self_fqp) = cache.exact_paths.get(&self_did).or_else(get_local)
{
let mut js_src_path: UrlPartsBuilder = std::iter::repeat("..")
.take(cx.current.len())
let mut js_src_path: UrlPartsBuilder = std::iter::repeat_n("..", cx.current.len())
.chain(std::iter::once("type.impl"))
.collect();
js_src_path.extend(target_fqp[..target_fqp.len() - 1].iter().copied());

View file

@ -182,9 +182,9 @@ pub(crate) fn write_bitmap_to_bytes(
out.write_all(&[b])?;
}
if size < NO_OFFSET_THRESHOLD {
4 + 4 * size + ((size + 7) / 8)
4 + 4 * size + size.div_ceil(8)
} else {
4 + 8 * size + ((size + 7) / 8)
4 + 8 * size + size.div_ceil(8)
}
} else {
out.write_all(&u32::to_le_bytes(SERIAL_COOKIE_NO_RUNCONTAINER))?;

View file

@ -2060,7 +2060,7 @@ fn resolution_failure(
return;
}
Trait
| TyAlias { .. }
| TyAlias
| ForeignTy
| OpaqueTy
| TraitAlias

View file

@ -39,15 +39,15 @@ impl DocFolder for StabilityPropagator<'_, '_> {
let item_stability = self.cx.tcx.lookup_stability(def_id);
let inline_stability =
item.inline_stmt_id.and_then(|did| self.cx.tcx.lookup_stability(did));
let is_glob_export = item.inline_stmt_id.and_then(|id| {
let is_glob_export = item.inline_stmt_id.map(|id| {
let hir_id = self.cx.tcx.local_def_id_to_hir_id(id);
Some(matches!(
matches!(
self.cx.tcx.hir_node(hir_id),
rustc_hir::Node::Item(rustc_hir::Item {
kind: rustc_hir::ItemKind::Use(_, rustc_hir::UseKind::Glob),
..
})
))
)
});
let own_stability = if let Some(item_stab) = item_stability
&& let StabilityLevel::Stable { since: _, allowed_through_unstable_modules } =