Skip to content

Commit 7552dd1

Browse files
authored
Rollup merge of #117625 - nnethercote:clippy-perf, r=cuviper
Fix some clippy perf lints `@matthiaskrgr` gave me the output of a clippy run with perf lints enabled. This PR fixes ones that I thought were worth fixing. r? `@cuviper`
2 parents 3c63072 + e8cf29b commit 7552dd1

File tree

9 files changed

+14
-20
lines changed

9 files changed

+14
-20
lines changed

compiler/rustc_errors/src/emitter.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2362,11 +2362,7 @@ impl FileWithAnnotatedLines {
23622362

23632363
let label = label.as_ref().map(|m| {
23642364
normalize_whitespace(
2365-
&emitter
2366-
.translate_message(m, &args)
2367-
.map_err(Report::new)
2368-
.unwrap()
2369-
.to_string(),
2365+
&emitter.translate_message(m, &args).map_err(Report::new).unwrap(),
23702366
)
23712367
});
23722368

compiler/rustc_middle/src/ty/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub fn suggest_constraining_type_params<'a>(
274274
span,
275275
if span_to_replace.is_some() {
276276
constraint.clone()
277-
} else if constraint.starts_with("<") {
277+
} else if constraint.starts_with('<') {
278278
constraint.to_string()
279279
} else if bound_list_non_empty {
280280
format!(" + {constraint}")

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15451545
let (span, sugg, post) = if let SuggestionTarget::SimilarlyNamed = suggestion.target
15461546
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
15471547
&& let Some(span) = suggestion.span
1548-
&& let Some(candidate) = suggestion.candidate.as_str().strip_prefix("_")
1548+
&& let Some(candidate) = suggestion.candidate.as_str().strip_prefix('_')
15491549
&& snippet == candidate
15501550
{
15511551
// When the suggested binding change would be from `x` to `_x`, suggest changing the

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ pub fn parse_externs(
24772477
let mut error = handler.early_struct_error(format!(
24782478
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
24792479
));
2480-
let adjusted_name = name.replace("-", "_");
2480+
let adjusted_name = name.replace('-', "_");
24812481
if crate::utils::is_ascii_ident(&adjusted_name) {
24822482
error.help(format!(
24832483
"consider replacing the dashes with underscores: `{adjusted_name}`"

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ fn build_module_items(
599599
let prim_ty = clean::PrimitiveType::from(p);
600600
items.push(clean::Item {
601601
name: None,
602-
attrs: Box::new(clean::Attributes::default()),
602+
attrs: Box::default(),
603603
// We can use the item's `DefId` directly since the only information ever used
604604
// from it is `DefId.krate`.
605605
item_id: ItemId::DefId(did),

src/librustdoc/clean/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,7 @@ impl WherePredicate {
13271327
pub(crate) enum GenericParamDefKind {
13281328
Lifetime { outlives: ThinVec<Lifetime> },
13291329
Type { did: DefId, bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
1330+
// Option<Box<String>> makes this type smaller than `Option<String>` would.
13301331
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
13311332
}
13321333

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
588588
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
589589
pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
590590
pub(crate) static DOC_CHANNEL: Lazy<&'static str> =
591-
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit("/").filter(|c| !c.is_empty()).next().unwrap());
591+
Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').filter(|c| !c.is_empty()).next().unwrap());
592592

593593
/// Render a sequence of macro arms in a format suitable for displaying to the user
594594
/// as part of an item declaration.

src/librustdoc/html/render/write_shared.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,12 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
356356

357357
let content = format!(
358358
"<h1>List of all crates</h1><ul class=\"all-items\">{}</ul>",
359-
krates
360-
.iter()
361-
.map(|s| {
362-
format!(
363-
"<li><a href=\"{trailing_slash}index.html\">{s}</a></li>",
364-
trailing_slash = ensure_trailing_slash(s),
365-
)
366-
})
367-
.collect::<String>()
359+
krates.iter().format_with("", |k, f| {
360+
f(&format_args!(
361+
"<li><a href=\"{trailing_slash}index.html\">{k}</a></li>",
362+
trailing_slash = ensure_trailing_slash(k),
363+
))
364+
})
368365
);
369366
let v = layout::render(&shared.layout, &page, "", content, &shared.style_files);
370367
shared.fs.write(dst, v)?;

src/librustdoc/passes/lint/redundant_explicit_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn check_redundant_explicit_link<'md>(
8787
let link_data = collect_link_data(&mut offset_iter);
8888

8989
if let Some(resolvable_link) = link_data.resolvable_link.as_ref() {
90-
if &link_data.display_link.replace("`", "") != resolvable_link {
90+
if &link_data.display_link.replace('`', "") != resolvable_link {
9191
// Skips if display link does not match to actual
9292
// resolvable link, usually happens if display link
9393
// has several segments, e.g.

0 commit comments

Comments
 (0)