Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustdoc] Fix new clippy lints #133537

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
@@ -391,7 +391,7 @@ fn write_with_opt_paren<T: fmt::Display>(
Ok(())
}

impl<'a> fmt::Display for Display<'a> {
impl fmt::Display for Display<'_> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self.0 {
Cfg::Not(ref child) => match **child {
4 changes: 2 additions & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
@@ -367,7 +367,7 @@ pub(crate) fn build_impls(
let tcx = cx.tcx;

// for each implementation of an item represented by `did`, build the clean::Item for that impl
for &did in tcx.inherent_impls(did).into_iter() {
for &did in tcx.inherent_impls(did).iter() {
cx.with_param_env(did, |cx| {
build_impl(cx, did, attrs, ret);
});
@@ -382,7 +382,7 @@ pub(crate) fn build_impls(
if tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
let type_ =
if tcx.is_trait(did) { SimplifiedType::Trait(did) } else { SimplifiedType::Adt(did) };
for &did in tcx.incoherent_impls(type_).into_iter() {
for &did in tcx.incoherent_impls(type_).iter() {
cx.with_param_env(did, |cx| {
build_impl(cx, did, attrs, ret);
});
18 changes: 8 additions & 10 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
@@ -2509,16 +2509,14 @@ fn clean_generic_args<'tcx>(
let args = generic_args
.args
.iter()
.filter_map(|arg| {
Some(match arg {
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
GenericArg::Lifetime(clean_lifetime(lt, cx))
}
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.map(|arg| match arg {
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
GenericArg::Lifetime(clean_lifetime(lt, cx))
}
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect::<Vec<_>>()
.into();
30 changes: 16 additions & 14 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
@@ -264,17 +264,19 @@ impl ExternalCrate {
// rendering by delegating everything to a hash map.
let as_primitive = |res: Res<!>| {
let Res::Def(DefKind::Mod, def_id) = res else { return None };
tcx.get_attrs(def_id, sym::rustc_doc_primitive).find_map(|attr| {
let attr_value = attr.value_str().expect("syntax should already be validated");
let Some(prim) = PrimitiveType::from_symbol(attr_value) else {
span_bug!(
attr.span,
"primitive `{attr_value}` is not a member of `PrimitiveType`"
);
};
tcx.get_attrs(def_id, sym::rustc_doc_primitive)
.map(|attr| {
let attr_value = attr.value_str().expect("syntax should already be validated");
let Some(prim) = PrimitiveType::from_symbol(attr_value) else {
span_bug!(
attr.span,
"primitive `{attr_value}` is not a member of `PrimitiveType`"
);
};

Some((def_id, prim))
})
(def_id, prim)
})
.next()
};

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

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

pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
let kind = match &self.kind {
ItemKind::StrippedItem(k) => &*k,
ItemKind::StrippedItem(k) => k,
_ => &self.kind,
};
match kind {
@@ -1870,15 +1872,15 @@ impl PrimitiveType {
.get(self)
.into_iter()
.flatten()
.flat_map(move |&simp| tcx.incoherent_impls(simp).into_iter())
.flat_map(move |&simp| tcx.incoherent_impls(simp).iter())
.copied()
}

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

4 changes: 2 additions & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ impl fmt::Debug for Options {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct FmtExterns<'a>(&'a Externs);

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

let parts_out_dir =
match matches.opt_str("parts-out-dir").map(|p| PathToParts::from_flag(p)).transpose() {
match matches.opt_str("parts-out-dir").map(PathToParts::from_flag).transpose() {
Ok(parts_out_dir) => parts_out_dir,
Err(e) => dcx.fatal(e),
};
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
@@ -700,7 +700,7 @@ impl IndividualTestOptions {
fn new(options: &RustdocOptions, test_id: &Option<String>, test_path: PathBuf) -> Self {
let outdir = if let Some(ref path) = options.persist_doctests {
let mut path = path.clone();
path.push(&test_id.as_deref().unwrap_or("<doctest>"));
path.push(test_id.as_deref().unwrap_or("<doctest>"));

if let Err(err) = std::fs::create_dir_all(&path) {
eprintln!("Couldn't create directory for doctest executables: {err}");
2 changes: 1 addition & 1 deletion src/librustdoc/doctest/rust.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ impl<'tcx> HirCollector<'tcx> {
}
}

impl<'tcx> HirCollector<'tcx> {
impl HirCollector<'_> {
fn visit_testable<F: FnOnce(&mut Self)>(
&mut self,
name: String,
2 changes: 1 addition & 1 deletion src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ impl Cache {
}
}

impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
impl DocFolder for CacheBuilder<'_, '_> {
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
if item.item_id.is_local() {
debug!(
6 changes: 3 additions & 3 deletions src/librustdoc/html/escape.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ use unicode_segmentation::UnicodeSegmentation;
/// string when passed to a format string.
pub(crate) struct Escape<'a>(pub &'a str);

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

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

impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
impl fmt::Display for EscapeBodyTextWithWbr<'_> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let EscapeBodyTextWithWbr(text) = *self;
if text.len() < 8 {
31 changes: 18 additions & 13 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@

use std::borrow::Cow;
use std::cell::Cell;
use std::cmp::Ordering;
use std::fmt::{self, Display, Write};
use std::iter::{self, once};

@@ -785,16 +786,20 @@ pub(crate) fn href_relative_parts<'fqp>(
);
}
}
// e.g. linking to std::sync::atomic from std::sync
if relative_to_fqp.len() < fqp.len() {
Box::new(fqp[relative_to_fqp.len()..fqp.len()].iter().copied())
// e.g. linking to std::sync from std::sync::atomic
} else if fqp.len() < relative_to_fqp.len() {
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
// linking to the same module
} else {
Box::new(iter::empty())
match relative_to_fqp.len().cmp(&fqp.len()) {
Ordering::Less => {
// e.g. linking to std::sync::atomic from std::sync
Box::new(fqp[relative_to_fqp.len()..fqp.len()].iter().copied())
}
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))
}
Ordering::Equal => {
// linking to the same module
Box::new(iter::empty())
}
}
}

@@ -1384,7 +1389,7 @@ impl clean::Impl {
write!(f, ">")?;
}
} else {
fmt_type(&type_, f, use_absolute, cx)?;
fmt_type(type_, f, use_absolute, cx)?;
}
Ok(())
}
@@ -1531,14 +1536,14 @@ impl clean::FnDecl {
(None, Some(last_i)) if i != last_i => write!(f, ", ")?,
(None, Some(_)) => (),
(Some(n), Some(last_i)) if i != last_i => write!(f, ",\n{}", Indent(n + 4))?,
(Some(_), Some(_)) => write!(f, ",\n")?,
(Some(_), Some(_)) => writeln!(f, ",")?,
}
}

if self.c_variadic {
match line_wrapping_indent {
None => write!(f, ", ...")?,
Some(n) => write!(f, "{}...\n", Indent(n + 4))?,
Some(n) => writeln!(f, "{}...", Indent(n + 4))?,
};
}

6 changes: 3 additions & 3 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ struct TokenHandler<'a, 'tcx, F: Write> {
href_context: Option<HrefContext<'a, 'tcx>>,
}

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

impl<'a, 'tcx, F: Write> Drop for TokenHandler<'a, 'tcx, F> {
impl<F: Write> Drop for TokenHandler<'_, '_, F> {
/// When leaving, we need to flush all pending data to not have missing content.
fn drop(&mut self) {
if self.pending_exit_span.is_some() {
@@ -1017,7 +1017,7 @@ fn string_without_closing_tag<T: Display>(
.ok()
.map(|(url, _, _)| url),
LinkFromSrc::Doc(def_id) => {
format::href_with_root_path(*def_id, context, Some(&href_context.root_path))
format::href_with_root_path(*def_id, context, Some(href_context.root_path))
.ok()
.map(|(doc_link, _, _)| doc_link)
}
2 changes: 1 addition & 1 deletion src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ pub(crate) struct Page<'a> {
pub(crate) rust_logo: bool,
}

impl<'a> Page<'a> {
impl Page<'_> {
pub(crate) fn get_static_root_path(&self) -> String {
match self.static_root_path {
Some(s) => s.to_string(),
17 changes: 8 additions & 9 deletions src/librustdoc/html/length_limit.rs
Original file line number Diff line number Diff line change
@@ -77,24 +77,23 @@ impl HtmlWithLimit {
/// This function will panic if called with a non-alphabetic `tag_name`.
pub(super) fn open_tag(&mut self, tag_name: &'static str) {
assert!(
tag_name.chars().all(|c| ('a'..='z').contains(&c)),
tag_name.chars().all(|c: char| c.is_ascii_lowercase()),
"tag_name contained non-alphabetic chars: {tag_name:?}",
);
self.queued_tags.push(tag_name);
}

/// Close the most recently opened HTML tag.
pub(super) fn close_tag(&mut self) {
match self.unclosed_tags.pop() {
if let Some(tag_name) = self.unclosed_tags.pop() {
// Close the most recently opened tag.
Some(tag_name) => write!(self.buf, "</{tag_name}>").unwrap(),
// There are valid cases where `close_tag()` is called without
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was removing this comment deliberate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't. Seems like a wrong clippy suggestion.

// there being any tags to close. For example, this occurs when
// a tag is opened after the length limit is exceeded;
// `flush_queue()` will never be called, and thus, the tag will
// not end up being added to `unclosed_tags`.
None => {}
write!(self.buf, "</{tag_name}>").unwrap()
}
// There are valid cases where `close_tag()` is called without
// there being any tags to close. For example, this occurs when
// a tag is opened after the length limit is exceeded;
// `flush_queue()` will never be called, and thus, the tag will
// not end up being added to `unclosed_tags`.
}

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