Skip to content

Commit d207e21

Browse files
authored
Rollup merge of rust-lang#138107 - yotamofek:pr/rustdoc/clippy, r=GuillaumeGomez
`librustdoc`: clippy fixes First commit is all machine-generated fixes, next two are some more lints fixed by hand/misc. cleanups Inspired by the redundant `.and_then()` added in rust-lang#137320 , and [this comment](rust-lang#138090 (comment)) r? ``@GuillaumeGomez``
2 parents 327ead3 + 5d25922 commit d207e21

14 files changed

+45
-49
lines changed

src/librustdoc/clean/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ fn clean_generic_args<'tcx>(
25322532
) -> GenericArgs {
25332533
// FIXME(return_type_notation): Fix RTN parens rendering
25342534
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
2535-
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<ThinVec<_>>().into();
2535+
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect();
25362536
let output = match output.kind {
25372537
hir::TyKind::Tup(&[]) => None,
25382538
_ => Some(Box::new(clean_ty(output, cx))),
@@ -2553,8 +2553,7 @@ fn clean_generic_args<'tcx>(
25532553
}
25542554
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
25552555
})
2556-
.collect::<ThinVec<_>>()
2557-
.into();
2556+
.collect();
25582557
let constraints = generic_args
25592558
.constraints
25602559
.iter()

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ impl ConstantKind {
24172417
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
24182418
rendered_const(tcx, tcx.hir_body(body), tcx.hir_body_owner_def_id(body))
24192419
}
2420-
ConstantKind::Infer { .. } => "_".to_string(),
2420+
ConstantKind::Infer => "_".to_string(),
24212421
}
24222422
}
24232423

src/librustdoc/clean/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn clean_middle_generic_args_with_constraints<'tcx>(
223223

224224
let args = clean_middle_generic_args(cx, args.map_bound(|args| &args[..]), has_self, did);
225225

226-
GenericArgs::AngleBracketed { args: args.into(), constraints }
226+
GenericArgs::AngleBracketed { args, constraints }
227227
}
228228

229229
pub(super) fn clean_middle_path<'tcx>(
@@ -394,7 +394,7 @@ pub(crate) fn print_evaluated_const(
394394
fn format_integer_with_underscore_sep(num: &str) -> String {
395395
let num_chars: Vec<_> = num.chars().collect();
396396
let mut num_start_index = if num_chars.first() == Some(&'-') { 1 } else { 0 };
397-
let chunk_size = match num[num_start_index..].as_bytes() {
397+
let chunk_size = match &num.as_bytes()[num_start_index..] {
398398
[b'0', b'b' | b'x', ..] => {
399399
num_start_index += 2;
400400
4
@@ -524,7 +524,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
524524
| AssocConst
525525
| Variant
526526
| Fn
527-
| TyAlias { .. }
527+
| TyAlias
528528
| Enum
529529
| Trait
530530
| Struct

src/librustdoc/display.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ where
2222
let mut iter = self.into_iter();
2323
let Some(first) = iter.next() else { return Ok(()) };
2424
first.fmt(f)?;
25-
while let Some(item) = iter.next() {
25+
for item in iter {
2626
f.write_str(sep)?;
2727
item.fmt(f)?;
2828
}

src/librustdoc/doctest/extracted.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ExtractedDocTests {
3333
opts: &super::GlobalTestOptions,
3434
options: &RustdocOptions,
3535
) {
36-
let edition = scraped_test.edition(&options);
36+
let edition = scraped_test.edition(options);
3737

3838
let ScrapedDocTest { filename, line, langstr, text, name } = scraped_test;
3939

@@ -48,7 +48,7 @@ impl ExtractedDocTests {
4848
let (full_test_code, size) = doctest.generate_unique_doctest(
4949
&text,
5050
langstr.test_harness,
51-
&opts,
51+
opts,
5252
Some(&opts.crate_name),
5353
);
5454
self.doctests.push(ExtractedDocTest {

src/librustdoc/html/format.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,9 @@ pub(crate) fn href_relative_parts<'fqp>(
623623
// e.g. linking to std::iter from std::vec (`dissimilar_part_count` will be 1)
624624
if f != r {
625625
let dissimilar_part_count = relative_to_fqp.len() - i;
626-
let fqp_module = &fqp[i..fqp.len()];
626+
let fqp_module = &fqp[i..];
627627
return Box::new(
628-
iter::repeat(sym::dotdot)
629-
.take(dissimilar_part_count)
628+
iter::repeat_n(sym::dotdot, dissimilar_part_count)
630629
.chain(fqp_module.iter().copied()),
631630
);
632631
}
@@ -639,7 +638,7 @@ pub(crate) fn href_relative_parts<'fqp>(
639638
Ordering::Greater => {
640639
// e.g. linking to std::sync from std::sync::atomic
641640
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
642-
Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
641+
Box::new(iter::repeat_n(sym::dotdot, dissimilar_part_count))
643642
}
644643
Ordering::Equal => {
645644
// linking to the same module
@@ -770,10 +769,9 @@ fn primitive_link_fragment(
770769
ExternalLocation::Local => {
771770
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
772771
Some(if cx.current.first() == Some(&cname_sym) {
773-
iter::repeat(sym::dotdot).take(cx.current.len() - 1).collect()
772+
iter::repeat_n(sym::dotdot, cx.current.len() - 1).collect()
774773
} else {
775-
iter::repeat(sym::dotdot)
776-
.take(cx.current.len())
774+
iter::repeat_n(sym::dotdot, cx.current.len())
777775
.chain(iter::once(cname_sym))
778776
.collect()
779777
})

src/librustdoc/html/highlight.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn write_header(
100100
}
101101

102102
if let Some(extra) = extra_content {
103-
out.push_str(&extra);
103+
out.push_str(extra);
104104
}
105105
if class.is_empty() {
106106
write_str(
@@ -131,7 +131,7 @@ fn write_header(
131131
/// * If the other `Class` is unclassified and only contains white characters (backline,
132132
/// whitespace, etc), it can be merged.
133133
/// * `Class::Ident` is considered the same as unclassified (because it doesn't have an associated
134-
/// CSS class).
134+
/// CSS class).
135135
fn can_merge(class1: Option<Class>, class2: Option<Class>, text: &str) -> bool {
136136
match (class1, class2) {
137137
(Some(c1), Some(c2)) => c1.is_equal_to(c2),
@@ -233,7 +233,7 @@ impl<F: Write> TokenHandler<'_, '_, F> {
233233

234234
#[inline]
235235
fn write_line_number(&mut self, line: u32, extra: &'static str) {
236-
(self.write_line_number)(&mut self.out, line, extra);
236+
(self.write_line_number)(self.out, line, extra);
237237
}
238238
}
239239

@@ -610,7 +610,7 @@ impl Decorations {
610610
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
611611
.0
612612
.iter()
613-
.flat_map(|(&kind, ranges)| ranges.into_iter().map(move |&(lo, hi)| ((lo, kind), hi)))
613+
.flat_map(|(&kind, ranges)| ranges.iter().map(move |&(lo, hi)| ((lo, kind), hi)))
614614
.unzip();
615615

616616
// Sort the sequences in document order.

src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ pub(crate) fn markdown_links<'md, R>(
17911791
}
17921792
}
17931793
} else if !c.is_ascii_whitespace() {
1794-
while let Some((j, c)) = iter.next() {
1794+
for (j, c) in iter.by_ref() {
17951795
if c.is_ascii_whitespace() {
17961796
return MarkdownLinkRange::Destination(i + span.start..j + span.start);
17971797
}

src/librustdoc/html/render/print_item.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cmp::Ordering;
2-
use std::fmt;
3-
use std::fmt::{Display, Write as _};
2+
use std::fmt::{self, Display, Write as _};
3+
use std::iter;
44

55
use rinja::Template;
66
use rustc_abi::VariantIdx;
@@ -1192,10 +1192,8 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt:
11921192
// to already be in the HTML, and will be ignored.
11931193
//
11941194
// [JSONP]: https://en.wikipedia.org/wiki/JSONP
1195-
let mut js_src_path: UrlPartsBuilder = std::iter::repeat("..")
1196-
.take(cx.current.len())
1197-
.chain(std::iter::once("trait.impl"))
1198-
.collect();
1195+
let mut js_src_path: UrlPartsBuilder =
1196+
iter::repeat_n("..", cx.current.len()).chain(iter::once("trait.impl")).collect();
11991197
if let Some(did) = it.item_id.as_def_id()
12001198
&& let get_extern = { || cx.shared.cache.external_paths.get(&did).map(|s| &s.0) }
12011199
&& let Some(fqp) = cx.shared.cache.exact_paths.get(&did).or_else(get_extern)
@@ -1446,10 +1444,8 @@ fn item_type_alias(cx: &Context<'_>, it: &clean::Item, t: &clean::TypeAlias) ->
14461444
&& let get_local = { || cache.paths.get(&self_did).map(|(p, _)| p) }
14471445
&& let Some(self_fqp) = cache.exact_paths.get(&self_did).or_else(get_local)
14481446
{
1449-
let mut js_src_path: UrlPartsBuilder = std::iter::repeat("..")
1450-
.take(cx.current.len())
1451-
.chain(std::iter::once("type.impl"))
1452-
.collect();
1447+
let mut js_src_path: UrlPartsBuilder =
1448+
iter::repeat_n("..", cx.current.len()).chain(iter::once("type.impl")).collect();
14531449
js_src_path.extend(target_fqp[..target_fqp.len() - 1].iter().copied());
14541450
js_src_path.push_fmt(format_args!("{target_type}.{}.js", target_fqp.last().unwrap()));
14551451
let self_path = fmt::from_fn(|f| self_fqp.iter().joined("::", f));
@@ -1493,7 +1489,7 @@ fn item_union(cx: &Context<'_>, it: &clean::Item, s: &clean::Union) -> impl fmt:
14931489

14941490
fn fields_iter(
14951491
&self,
1496-
) -> std::iter::Peekable<impl Iterator<Item = (&'a clean::Item, &'a clean::Type)>> {
1492+
) -> iter::Peekable<impl Iterator<Item = (&'a clean::Item, &'a clean::Type)>> {
14971493
self.s
14981494
.fields
14991495
.iter()

src/librustdoc/html/render/search_index.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,7 @@ pub(crate) fn get_function_type_for_search(
842842
}
843843
clean::ConstantItem(ref c) => make_nullary_fn(&c.type_),
844844
clean::StaticItem(ref s) => make_nullary_fn(&s.type_),
845-
clean::StructFieldItem(ref t) => {
846-
let Some(parent) = parent else {
847-
return None;
848-
};
845+
clean::StructFieldItem(ref t) if let Some(parent) = parent => {
849846
let mut rgen: FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)> =
850847
Default::default();
851848
let output = get_index_type(t, vec![], &mut rgen);

src/librustdoc/html/render/search_index/encode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ pub(crate) fn write_bitmap_to_bytes(
182182
out.write_all(&[b])?;
183183
}
184184
if size < NO_OFFSET_THRESHOLD {
185-
4 + 4 * size + ((size + 7) / 8)
185+
4 + 4 * size + size.div_ceil(8)
186186
} else {
187-
4 + 8 * size + ((size + 7) / 8)
187+
4 + 8 * size + size.div_ceil(8)
188188
}
189189
} else {
190190
out.write_all(&u32::to_le_bytes(SERIAL_COOKIE_NO_RUNCONTAINER))?;

src/librustdoc/html/render/sidebar.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a> LinkBlock<'a> {
7979
}
8080

8181
/// A link to an item. Content should not be escaped.
82-
#[derive(Ord, PartialEq, Eq, Hash, Clone)]
82+
#[derive(PartialEq, Eq, Hash, Clone)]
8383
pub(crate) struct Link<'a> {
8484
/// The content for the anchor tag and title attr
8585
name: Cow<'a, str>,
@@ -91,20 +91,26 @@ pub(crate) struct Link<'a> {
9191
children: Vec<Link<'a>>,
9292
}
9393

94-
impl PartialOrd for Link<'_> {
95-
fn partial_cmp(&self, other: &Link<'_>) -> Option<Ordering> {
94+
impl Ord for Link<'_> {
95+
fn cmp(&self, other: &Self) -> Ordering {
9696
match compare_names(&self.name, &other.name) {
97-
Ordering::Equal => (),
98-
result => return Some(result),
97+
Ordering::Equal => {}
98+
result => return result,
9999
}
100-
(&self.name_html, &self.href, &self.children).partial_cmp(&(
100+
(&self.name_html, &self.href, &self.children).cmp(&(
101101
&other.name_html,
102102
&other.href,
103103
&other.children,
104104
))
105105
}
106106
}
107107

108+
impl PartialOrd for Link<'_> {
109+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
110+
Some(self.cmp(other))
111+
}
112+
}
113+
108114
impl<'a> Link<'a> {
109115
pub fn new(href: impl Into<Cow<'a, str>>, name: impl Into<Cow<'a, str>>) -> Self {
110116
Self { href: href.into(), name: name.into(), children: vec![], name_html: None }

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ fn resolution_failure(
20572057
return;
20582058
}
20592059
Trait
2060-
| TyAlias { .. }
2060+
| TyAlias
20612061
| ForeignTy
20622062
| OpaqueTy
20632063
| TraitAlias

src/librustdoc/passes/propagate_stability.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ impl DocFolder for StabilityPropagator<'_, '_> {
3939
let item_stability = self.cx.tcx.lookup_stability(def_id);
4040
let inline_stability =
4141
item.inline_stmt_id.and_then(|did| self.cx.tcx.lookup_stability(did));
42-
let is_glob_export = item.inline_stmt_id.and_then(|id| {
42+
let is_glob_export = item.inline_stmt_id.map(|id| {
4343
let hir_id = self.cx.tcx.local_def_id_to_hir_id(id);
44-
Some(matches!(
44+
matches!(
4545
self.cx.tcx.hir_node(hir_id),
4646
rustc_hir::Node::Item(rustc_hir::Item {
4747
kind: rustc_hir::ItemKind::Use(_, rustc_hir::UseKind::Glob),
4848
..
4949
})
50-
))
50+
)
5151
});
5252
let own_stability = if let Some(item_stab) = item_stability
5353
&& let StabilityLevel::Stable { since: _, allowed_through_unstable_modules } =

0 commit comments

Comments
 (0)