Skip to content

Commit f0c301f

Browse files
Fix new clippy lints
1 parent 39cb338 commit f0c301f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+325
-340
lines changed

src/librustdoc/clean/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ fn write_with_opt_paren<T: fmt::Display>(
391391
Ok(())
392392
}
393393

394-
impl<'a> fmt::Display for Display<'a> {
394+
impl fmt::Display for Display<'_> {
395395
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
396396
match *self.0 {
397397
Cfg::Not(ref child) => match **child {

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ pub(crate) fn build_impls(
367367
let tcx = cx.tcx;
368368

369369
// for each implementation of an item represented by `did`, build the clean::Item for that impl
370-
for &did in tcx.inherent_impls(did).into_iter() {
370+
for &did in tcx.inherent_impls(did).iter() {
371371
cx.with_param_env(did, |cx| {
372372
build_impl(cx, did, attrs, ret);
373373
});
@@ -382,7 +382,7 @@ pub(crate) fn build_impls(
382382
if tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
383383
let type_ =
384384
if tcx.is_trait(did) { SimplifiedType::Trait(did) } else { SimplifiedType::Adt(did) };
385-
for &did in tcx.incoherent_impls(type_).into_iter() {
385+
for &did in tcx.incoherent_impls(type_).iter() {
386386
cx.with_param_env(did, |cx| {
387387
build_impl(cx, did, attrs, ret);
388388
});

src/librustdoc/clean/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -2509,16 +2509,14 @@ fn clean_generic_args<'tcx>(
25092509
let args = generic_args
25102510
.args
25112511
.iter()
2512-
.filter_map(|arg| {
2513-
Some(match arg {
2514-
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
2515-
GenericArg::Lifetime(clean_lifetime(lt, cx))
2516-
}
2517-
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
2518-
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
2519-
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
2520-
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
2521-
})
2512+
.map(|arg| match arg {
2513+
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
2514+
GenericArg::Lifetime(clean_lifetime(lt, cx))
2515+
}
2516+
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
2517+
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
2518+
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
2519+
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
25222520
})
25232521
.collect::<Vec<_>>()
25242522
.into();

src/librustdoc/clean/types.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,19 @@ impl ExternalCrate {
264264
// rendering by delegating everything to a hash map.
265265
let as_primitive = |res: Res<!>| {
266266
let Res::Def(DefKind::Mod, def_id) = res else { return None };
267-
tcx.get_attrs(def_id, sym::rustc_doc_primitive).find_map(|attr| {
268-
let attr_value = attr.value_str().expect("syntax should already be validated");
269-
let Some(prim) = PrimitiveType::from_symbol(attr_value) else {
270-
span_bug!(
271-
attr.span,
272-
"primitive `{attr_value}` is not a member of `PrimitiveType`"
273-
);
274-
};
267+
tcx.get_attrs(def_id, sym::rustc_doc_primitive)
268+
.map(|attr| {
269+
let attr_value = attr.value_str().expect("syntax should already be validated");
270+
let Some(prim) = PrimitiveType::from_symbol(attr_value) else {
271+
span_bug!(
272+
attr.span,
273+
"primitive `{attr_value}` is not a member of `PrimitiveType`"
274+
);
275+
};
275276

276-
Some((def_id, prim))
277-
})
277+
(def_id, prim)
278+
})
279+
.next()
278280
};
279281

280282
if root.is_local() {
@@ -339,7 +341,7 @@ pub(crate) struct ItemInner {
339341
impl std::ops::Deref for Item {
340342
type Target = ItemInner;
341343
fn deref(&self) -> &ItemInner {
342-
&*self.inner
344+
&self.inner
343345
}
344346
}
345347

@@ -412,7 +414,7 @@ impl Item {
412414

413415
pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
414416
let kind = match &self.kind {
415-
ItemKind::StrippedItem(k) => &*k,
417+
ItemKind::StrippedItem(k) => k,
416418
_ => &self.kind,
417419
};
418420
match kind {
@@ -1870,15 +1872,15 @@ impl PrimitiveType {
18701872
.get(self)
18711873
.into_iter()
18721874
.flatten()
1873-
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter())
1875+
.flat_map(move |&simp| tcx.incoherent_impls(simp).iter())
18741876
.copied()
18751877
}
18761878

18771879
pub(crate) fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> + '_ {
18781880
Self::simplified_types()
18791881
.values()
18801882
.flatten()
1881-
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter())
1883+
.flat_map(move |&simp| tcx.incoherent_impls(simp).iter())
18821884
.copied()
18831885
}
18841886

src/librustdoc/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl fmt::Debug for Options {
178178
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179179
struct FmtExterns<'a>(&'a Externs);
180180

181-
impl<'a> fmt::Debug for FmtExterns<'a> {
181+
impl fmt::Debug for FmtExterns<'_> {
182182
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
183183
f.debug_map().entries(self.0.iter()).finish()
184184
}
@@ -508,7 +508,7 @@ impl Options {
508508
};
509509

510510
let parts_out_dir =
511-
match matches.opt_str("parts-out-dir").map(|p| PathToParts::from_flag(p)).transpose() {
511+
match matches.opt_str("parts-out-dir").map(PathToParts::from_flag).transpose() {
512512
Ok(parts_out_dir) => parts_out_dir,
513513
Err(e) => dcx.fatal(e),
514514
};

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ impl IndividualTestOptions {
700700
fn new(options: &RustdocOptions, test_id: &Option<String>, test_path: PathBuf) -> Self {
701701
let outdir = if let Some(ref path) = options.persist_doctests {
702702
let mut path = path.clone();
703-
path.push(&test_id.as_deref().unwrap_or("<doctest>"));
703+
path.push(test_id.as_deref().unwrap_or("<doctest>"));
704704

705705
if let Err(err) = std::fs::create_dir_all(&path) {
706706
eprintln!("Couldn't create directory for doctest executables: {err}");

src/librustdoc/doctest/rust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> HirCollector<'tcx> {
8888
}
8989
}
9090

91-
impl<'tcx> HirCollector<'tcx> {
91+
impl HirCollector<'_> {
9292
fn visit_testable<F: FnOnce(&mut Self)>(
9393
&mut self,
9494
name: String,

src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Cache {
203203
}
204204
}
205205

206-
impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
206+
impl DocFolder for CacheBuilder<'_, '_> {
207207
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
208208
if item.item_id.is_local() {
209209
debug!(

src/librustdoc/html/escape.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use unicode_segmentation::UnicodeSegmentation;
1111
/// string when passed to a format string.
1212
pub(crate) struct Escape<'a>(pub &'a str);
1313

14-
impl<'a> fmt::Display for Escape<'a> {
14+
impl fmt::Display for Escape<'_> {
1515
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1616
// Because the internet is always right, turns out there's not that many
1717
// characters to escape: http://stackoverflow.com/questions/7381974
@@ -49,7 +49,7 @@ impl<'a> fmt::Display for Escape<'a> {
4949
/// difference, use [`Escape`].
5050
pub(crate) struct EscapeBodyText<'a>(pub &'a str);
5151

52-
impl<'a> fmt::Display for EscapeBodyText<'a> {
52+
impl fmt::Display for EscapeBodyText<'_> {
5353
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5454
// Because the internet is always right, turns out there's not that many
5555
// characters to escape: http://stackoverflow.com/questions/7381974
@@ -86,7 +86,7 @@ impl<'a> fmt::Display for EscapeBodyText<'a> {
8686
/// difference, use [`Escape`].
8787
pub(crate) struct EscapeBodyTextWithWbr<'a>(pub &'a str);
8888

89-
impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
89+
impl fmt::Display for EscapeBodyTextWithWbr<'_> {
9090
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
9191
let EscapeBodyTextWithWbr(text) = *self;
9292
if text.len() < 8 {

src/librustdoc/html/format.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
use std::borrow::Cow;
1111
use std::cell::Cell;
12+
use std::cmp::Ordering;
1213
use std::fmt::{self, Display, Write};
1314
use std::iter::{self, once};
1415

@@ -785,16 +786,20 @@ pub(crate) fn href_relative_parts<'fqp>(
785786
);
786787
}
787788
}
788-
// e.g. linking to std::sync::atomic from std::sync
789-
if relative_to_fqp.len() < fqp.len() {
790-
Box::new(fqp[relative_to_fqp.len()..fqp.len()].iter().copied())
791-
// e.g. linking to std::sync from std::sync::atomic
792-
} else if fqp.len() < relative_to_fqp.len() {
793-
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
794-
Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
795-
// linking to the same module
796-
} else {
797-
Box::new(iter::empty())
789+
match relative_to_fqp.len().cmp(&fqp.len()) {
790+
Ordering::Less => {
791+
// e.g. linking to std::sync::atomic from std::sync
792+
Box::new(fqp[relative_to_fqp.len()..fqp.len()].iter().copied())
793+
}
794+
Ordering::Greater => {
795+
// e.g. linking to std::sync from std::sync::atomic
796+
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
797+
Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
798+
}
799+
Ordering::Equal => {
800+
// linking to the same module
801+
Box::new(iter::empty())
802+
}
798803
}
799804
}
800805

@@ -1384,7 +1389,7 @@ impl clean::Impl {
13841389
write!(f, ">")?;
13851390
}
13861391
} else {
1387-
fmt_type(&type_, f, use_absolute, cx)?;
1392+
fmt_type(type_, f, use_absolute, cx)?;
13881393
}
13891394
Ok(())
13901395
}
@@ -1531,14 +1536,14 @@ impl clean::FnDecl {
15311536
(None, Some(last_i)) if i != last_i => write!(f, ", ")?,
15321537
(None, Some(_)) => (),
15331538
(Some(n), Some(last_i)) if i != last_i => write!(f, ",\n{}", Indent(n + 4))?,
1534-
(Some(_), Some(_)) => write!(f, ",\n")?,
1539+
(Some(_), Some(_)) => writeln!(f, ",")?,
15351540
}
15361541
}
15371542

15381543
if self.c_variadic {
15391544
match line_wrapping_indent {
15401545
None => write!(f, ", ...")?,
1541-
Some(n) => write!(f, "{}...\n", Indent(n + 4))?,
1546+
Some(n) => writeln!(f, "{}...", Indent(n + 4))?,
15421547
};
15431548
}
15441549

src/librustdoc/html/highlight.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct TokenHandler<'a, 'tcx, F: Write> {
144144
href_context: Option<HrefContext<'a, 'tcx>>,
145145
}
146146

147-
impl<'a, 'tcx, F: Write> TokenHandler<'a, 'tcx, F> {
147+
impl<F: Write> TokenHandler<'_, '_, F> {
148148
fn handle_exit_span(&mut self) {
149149
// We can't get the last `closing_tags` element using `pop()` because `closing_tags` is
150150
// being used in `write_pending_elems`.
@@ -207,7 +207,7 @@ impl<'a, 'tcx, F: Write> TokenHandler<'a, 'tcx, F> {
207207
}
208208
}
209209

210-
impl<'a, 'tcx, F: Write> Drop for TokenHandler<'a, 'tcx, F> {
210+
impl<F: Write> Drop for TokenHandler<'_, '_, F> {
211211
/// When leaving, we need to flush all pending data to not have missing content.
212212
fn drop(&mut self) {
213213
if self.pending_exit_span.is_some() {
@@ -1017,7 +1017,7 @@ fn string_without_closing_tag<T: Display>(
10171017
.ok()
10181018
.map(|(url, _, _)| url),
10191019
LinkFromSrc::Doc(def_id) => {
1020-
format::href_with_root_path(*def_id, context, Some(&href_context.root_path))
1020+
format::href_with_root_path(*def_id, context, Some(href_context.root_path))
10211021
.ok()
10221022
.map(|(doc_link, _, _)| doc_link)
10231023
}

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) struct Page<'a> {
3333
pub(crate) rust_logo: bool,
3434
}
3535

36-
impl<'a> Page<'a> {
36+
impl Page<'_> {
3737
pub(crate) fn get_static_root_path(&self) -> String {
3838
match self.static_root_path {
3939
Some(s) => s.to_string(),

src/librustdoc/html/length_limit.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,23 @@ impl HtmlWithLimit {
7777
/// This function will panic if called with a non-alphabetic `tag_name`.
7878
pub(super) fn open_tag(&mut self, tag_name: &'static str) {
7979
assert!(
80-
tag_name.chars().all(|c| ('a'..='z').contains(&c)),
80+
tag_name.chars().all(|c: char| c.is_ascii_lowercase()),
8181
"tag_name contained non-alphabetic chars: {tag_name:?}",
8282
);
8383
self.queued_tags.push(tag_name);
8484
}
8585

8686
/// Close the most recently opened HTML tag.
8787
pub(super) fn close_tag(&mut self) {
88-
match self.unclosed_tags.pop() {
88+
if let Some(tag_name) = self.unclosed_tags.pop() {
8989
// Close the most recently opened tag.
90-
Some(tag_name) => write!(self.buf, "</{tag_name}>").unwrap(),
91-
// There are valid cases where `close_tag()` is called without
92-
// there being any tags to close. For example, this occurs when
93-
// a tag is opened after the length limit is exceeded;
94-
// `flush_queue()` will never be called, and thus, the tag will
95-
// not end up being added to `unclosed_tags`.
96-
None => {}
90+
write!(self.buf, "</{tag_name}>").unwrap()
9791
}
92+
// There are valid cases where `close_tag()` is called without
93+
// there being any tags to close. For example, this occurs when
94+
// a tag is opened after the length limit is exceeded;
95+
// `flush_queue()` will never be called, and thus, the tag will
96+
// not end up being added to `unclosed_tags`.
9897
}
9998

10099
/// Write all queued tags and add them to the `unclosed_tags` list.

0 commit comments

Comments
 (0)