Skip to content

Commit 164a48c

Browse files
jieyouxuMuscraft
authored andcommitted
Rollup merge of rust-lang#144178 - GuillaumeGomez:fix-clippy-lints, r=fmease
Fix clippy lints in librustdoc
2 parents 383e2ea + 797f7aa commit 164a48c

20 files changed

+154
-174
lines changed

src/librustdoc/clean/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ impl Type {
16771677
}
16781678
}
16791679

1680-
pub(crate) fn generics<'a>(&'a self) -> Option<impl Iterator<Item = &'a Type>> {
1680+
pub(crate) fn generics(&self) -> Option<impl Iterator<Item = &Type>> {
16811681
match self {
16821682
Type::Path { path, .. } => path.generics(),
16831683
_ => None,
@@ -2227,7 +2227,7 @@ impl Path {
22272227
self.segments.last().map(|seg| &seg.args)
22282228
}
22292229

2230-
pub(crate) fn generics<'a>(&'a self) -> Option<impl Iterator<Item = &'a Type>> {
2230+
pub(crate) fn generics(&self) -> Option<impl Iterator<Item = &Type>> {
22312231
self.segments.last().and_then(|seg| {
22322232
if let GenericArgs::AngleBracketed { ref args, .. } = seg.args {
22332233
Some(args.iter().filter_map(|arg| match arg {

src/librustdoc/clean/utils.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,11 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
343343
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
344344
match n.kind() {
345345
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args: _ }) => {
346-
let s = if let Some(def) = def.as_local() {
346+
if let Some(def) = def.as_local() {
347347
rendered_const(cx.tcx, cx.tcx.hir_body_owned_by(def), def)
348348
} else {
349349
inline::print_inlined_const(cx.tcx, def)
350-
};
351-
352-
s
350+
}
353351
}
354352
// array lengths are obviously usize
355353
ty::ConstKind::Value(cv) if *cv.ty.kind() == ty::Uint(ty::UintTy::Usize) => {

src/librustdoc/doctest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ fn run_test(
632632
// the user to exploit nightly-only features on stable
633633
runner_compiler.env("RUSTC_BOOTSTRAP", "1");
634634
runner_compiler.args(compiler_args);
635-
runner_compiler.args(&["--crate-type=bin", "-o"]).arg(&output_file);
635+
runner_compiler.args(["--crate-type=bin", "-o"]).arg(&output_file);
636636
let mut extern_path = std::ffi::OsString::from(format!(
637637
"--extern=doctest_bundle_{edition}=",
638638
edition = doctest.edition
@@ -657,7 +657,7 @@ fn run_test(
657657
extern_path.push(&output_bundle_file);
658658
runner_compiler.arg(extern_path);
659659
runner_compiler.arg(&runner_input_file);
660-
if std::fs::write(&runner_input_file, &merged_test_code).is_err() {
660+
if std::fs::write(&runner_input_file, merged_test_code).is_err() {
661661
// If we cannot write this file for any reason, we leave. All combined tests will be
662662
// tested as standalone tests.
663663
return Err(TestFailure::CompileError);

src/librustdoc/doctest/rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl HirCollector<'_> {
140140
.iter()
141141
.filter(|a| a.has_name(sym::attr))
142142
.flat_map(|a| a.meta_item_list().unwrap_or_default())
143-
.map(|i| pprust::meta_list_item_to_string(i))
143+
.map(pprust::meta_list_item_to_string)
144144
{
145145
// Add the additional attributes to the global_crate_attrs vector
146146
self.collector.global_crate_attrs.push(attr);

src/librustdoc/formats/renderer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
8181
let _timer =
8282
prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string());
8383

84-
cx.mod_item_in(&item)?;
84+
cx.mod_item_in(item)?;
8585
let (clean::StrippedItem(box clean::ModuleItem(ref module))
8686
| clean::ModuleItem(ref module)) = item.inner.kind
8787
else {
@@ -99,7 +99,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
9999
} else if let Some(item_name) = item.name
100100
&& !item.is_extern_crate()
101101
{
102-
prof.generic_activity_with_arg("render_item", item_name.as_str()).run(|| cx.item(&item))?;
102+
prof.generic_activity_with_arg("render_item", item_name.as_str()).run(|| cx.item(item))?;
103103
}
104104
Ok(())
105105
}

src/librustdoc/html/format.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ impl clean::Generics {
114114
let real_params =
115115
fmt::from_fn(|f| real_params.clone().map(|g| g.print(cx)).joined(", ", f));
116116
if f.alternate() {
117-
write!(f, "<{:#}>", real_params)
117+
write!(f, "<{real_params:#}>")
118118
} else {
119-
write!(f, "&lt;{}&gt;", real_params)
119+
write!(f, "&lt;{real_params}&gt;")
120120
}
121121
})
122122
}
@@ -594,7 +594,7 @@ pub(crate) fn href_with_root_path(
594594
}
595595
}
596596
};
597-
let url_parts = make_href(root_path, shortty, url_parts, &fqp, is_remote);
597+
let url_parts = make_href(root_path, shortty, url_parts, fqp, is_remote);
598598
Ok((url_parts, shortty, fqp.clone()))
599599
}
600600

@@ -1115,7 +1115,7 @@ impl clean::Impl {
11151115
{
11161116
let last = ty.last();
11171117
if f.alternate() {
1118-
write!(f, "{}<", last)?;
1118+
write!(f, "{last}<")?;
11191119
self.print_type(inner_type, f, use_absolute, cx)?;
11201120
write!(f, ">")?;
11211121
} else {
@@ -1219,7 +1219,7 @@ pub(crate) fn print_params(params: &[clean::Parameter], cx: &Context<'_>) -> imp
12191219
.map(|param| {
12201220
fmt::from_fn(|f| {
12211221
if let Some(name) = param.name {
1222-
write!(f, "{}: ", name)?;
1222+
write!(f, "{name}: ")?;
12231223
}
12241224
param.type_.print(cx).fmt(f)
12251225
})
@@ -1341,7 +1341,7 @@ impl clean::FnDecl {
13411341
write!(f, "const ")?;
13421342
}
13431343
if let Some(name) = param.name {
1344-
write!(f, "{}: ", name)?;
1344+
write!(f, "{name}: ")?;
13451345
}
13461346
param.type_.print(cx).fmt(f)?;
13471347
}

src/librustdoc/html/highlight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a> Iterator for TokenIter<'a> {
547547
fn get_real_ident_class(text: &str, allow_path_keywords: bool) -> Option<Class> {
548548
let ignore: &[&str] =
549549
if allow_path_keywords { &["self", "Self", "super", "crate"] } else { &["self", "Self"] };
550-
if ignore.iter().any(|k| *k == text) {
550+
if ignore.contains(&text) {
551551
return None;
552552
}
553553
Some(match text {
@@ -1159,7 +1159,7 @@ fn string_without_closing_tag<T: Display>(
11591159
return Some("</a>");
11601160
}
11611161
if !open_tag {
1162-
write!(out, "{}", text_s).unwrap();
1162+
out.write_str(&text_s).unwrap();
11631163
return None;
11641164
}
11651165
let klass_s = klass.as_html();

src/librustdoc/html/layout.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,5 @@ pub(crate) fn redirect(url: &str) -> String {
132132
<script>location.replace("{url}" + location.search + location.hash);</script>
133133
</body>
134134
</html>"##,
135-
url = url,
136135
)
137136
}

src/librustdoc/html/markdown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
251251
if !parse_result.rust {
252252
let added_classes = parse_result.added_classes;
253253
let lang_string = if let Some(lang) = parse_result.unknown.first() {
254-
format!("language-{}", lang)
254+
format!("language-{lang}")
255255
} else {
256256
String::new()
257257
};
@@ -999,7 +999,7 @@ impl<'a, 'tcx> TagIterator<'a, 'tcx> {
999999

10001000
if let Some((_, c)) = self.inner.next() {
10011001
if c != '=' {
1002-
self.emit_error(format!("expected `=`, found `{}`", c));
1002+
self.emit_error(format!("expected `=`, found `{c}`"));
10031003
return None;
10041004
}
10051005
} else {

src/librustdoc/html/render/context.rs

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,12 @@ impl<'tcx> Context<'tcx> {
193193
if it.is_stripped()
194194
&& let Some(def_id) = it.def_id()
195195
&& def_id.is_local()
196+
&& (self.info.is_inside_inlined_module
197+
|| self.shared.cache.inlined_items.contains(&def_id))
196198
{
197-
if self.info.is_inside_inlined_module
198-
|| self.shared.cache.inlined_items.contains(&def_id)
199-
{
200-
// For now we're forced to generate a redirect page for stripped items until
201-
// `record_extern_fqn` correctly points to external items.
202-
render_redirect_pages = true;
203-
}
199+
// For now we're forced to generate a redirect page for stripped items until
200+
// `record_extern_fqn` correctly points to external items.
201+
render_redirect_pages = true;
204202
}
205203
let mut title = String::new();
206204
if !is_module {
@@ -254,40 +252,36 @@ impl<'tcx> Context<'tcx> {
254252
&self.shared.style_files,
255253
)
256254
} else {
257-
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id()) {
258-
if self.current.len() + 1 != names.len()
259-
|| self.current.iter().zip(names.iter()).any(|(a, b)| a != b)
260-
{
261-
// We checked that the redirection isn't pointing to the current file,
262-
// preventing an infinite redirection loop in the generated
263-
// documentation.
264-
265-
let path = fmt::from_fn(|f| {
266-
for name in &names[..names.len() - 1] {
267-
write!(f, "{name}/")?;
268-
}
269-
write!(f, "{}", print_item_path(ty, names.last().unwrap().as_str()))
270-
});
271-
match self.shared.redirections {
272-
Some(ref redirections) => {
273-
let mut current_path = String::new();
274-
for name in &self.current {
275-
current_path.push_str(name.as_str());
276-
current_path.push('/');
277-
}
278-
let _ = write!(
279-
current_path,
280-
"{}",
281-
print_item_path(ty, names.last().unwrap().as_str())
282-
);
283-
redirections.borrow_mut().insert(current_path, path.to_string());
284-
}
285-
None => {
286-
return layout::redirect(&format!(
287-
"{root}{path}",
288-
root = self.root_path()
289-
));
255+
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id())
256+
&& (self.current.len() + 1 != names.len()
257+
|| self.current.iter().zip(names.iter()).any(|(a, b)| a != b))
258+
{
259+
// We checked that the redirection isn't pointing to the current file,
260+
// preventing an infinite redirection loop in the generated
261+
// documentation.
262+
263+
let path = fmt::from_fn(|f| {
264+
for name in &names[..names.len() - 1] {
265+
write!(f, "{name}/")?;
266+
}
267+
write!(f, "{}", print_item_path(ty, names.last().unwrap().as_str()))
268+
});
269+
match self.shared.redirections {
270+
Some(ref redirections) => {
271+
let mut current_path = String::new();
272+
for name in &self.current {
273+
current_path.push_str(name.as_str());
274+
current_path.push('/');
290275
}
276+
let _ = write!(
277+
current_path,
278+
"{}",
279+
print_item_path(ty, names.last().unwrap().as_str())
280+
);
281+
redirections.borrow_mut().insert(current_path, path.to_string());
282+
}
283+
None => {
284+
return layout::redirect(&format!("{root}{path}", root = self.root_path()));
291285
}
292286
}
293287
}
@@ -762,11 +756,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
762756
// Flush pending errors.
763757
self.shared.fs.close();
764758
let nb_errors = self.shared.errors.iter().map(|err| self.tcx().dcx().err(err)).count();
765-
if nb_errors > 0 {
766-
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
767-
} else {
768-
Ok(())
769-
}
759+
if nb_errors > 0 { Err(Error::new(io::Error::other("I/O error"), "")) } else { Ok(()) }
770760
}
771761

772762
fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> {
@@ -842,7 +832,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
842832
self.info.render_redirect_pages = item.is_stripped();
843833
}
844834

845-
let buf = self.render_item(&item, false);
835+
let buf = self.render_item(item, false);
846836
// buf will be empty if the item is stripped and there is no redirect for it
847837
if !buf.is_empty() {
848838
let name = item.name.as_ref().unwrap();
@@ -853,7 +843,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
853843
self.shared.fs.write(joint_dst, buf)?;
854844

855845
if !self.info.render_redirect_pages {
856-
self.shared.all.borrow_mut().append(full_path(self, &item), &item_type);
846+
self.shared.all.borrow_mut().append(full_path(self, item), &item_type);
857847
}
858848
// If the item is a macro, redirect from the old macro URL (with !)
859849
// to the new one (without).

0 commit comments

Comments
 (0)