Skip to content

Commit 6f47265

Browse files
committed
more clippy::perf fixes
1 parent dec6894 commit 6f47265

File tree

6 files changed

+11
-19
lines changed

6 files changed

+11
-19
lines changed

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ pub trait LintContext: Sized {
842842
if let Some(positional_arg_to_replace) = position_sp_to_replace {
843843
let name = if is_formatting_arg { named_arg_name + "$" } else { named_arg_name };
844844
let span_to_replace = if let Ok(positional_arg_content) =
845-
self.sess().source_map().span_to_snippet(positional_arg_to_replace) && positional_arg_content.starts_with(":") {
845+
self.sess().source_map().span_to_snippet(positional_arg_to_replace) && positional_arg_content.starts_with(':') {
846846
positional_arg_to_replace.shrink_to_lo()
847847
} else {
848848
positional_arg_to_replace

compiler/rustc_metadata/src/rmeta/encoder.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -1378,19 +1378,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13781378

13791379
let tcx = self.tcx;
13801380

1381-
let keys_and_jobs = tcx
1382-
.mir_keys(())
1383-
.iter()
1384-
.filter_map(|&def_id| {
1385-
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
1386-
if encode_const || encode_opt {
1387-
Some((def_id, encode_const, encode_opt))
1388-
} else {
1389-
None
1390-
}
1391-
})
1392-
.collect::<Vec<_>>();
1393-
for (def_id, encode_const, encode_opt) in keys_and_jobs.into_iter() {
1381+
let keys_and_jobs = tcx.mir_keys(()).iter().filter_map(|&def_id| {
1382+
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
1383+
if encode_const || encode_opt { Some((def_id, encode_const, encode_opt)) } else { None }
1384+
});
1385+
for (def_id, encode_const, encode_opt) in keys_and_jobs {
13941386
debug_assert!(encode_const || encode_opt);
13951387

13961388
debug!("EntryBuilder::encode_mir({:?})", def_id);

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ impl<'a> Resolver<'a> {
13931393

13941394
// If only some candidates are accessible, take just them
13951395
if !candidates.iter().all(|v: &ImportSuggestion| !v.accessible) {
1396-
candidates = candidates.into_iter().filter(|x| x.accessible).collect();
1396+
candidates.retain(|x| x.accessible)
13971397
}
13981398

13991399
candidates

library/std/src/sys/unix/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ mod cgroups {
429429
Some(b"") => Cgroup::V2,
430430
Some(controllers)
431431
if from_utf8(controllers)
432-
.is_ok_and(|c| c.split(",").any(|c| c == "cpu")) =>
432+
.is_ok_and(|c| c.split(',').any(|c| c == "cpu")) =>
433433
{
434434
Cgroup::V1
435435
}

src/librustdoc/html/render/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2367,9 +2367,9 @@ pub(crate) fn get_filtered_impls_for_reference<'a>(
23672367
let Some(v) = shared.cache.impls.get(&def_id) else { return (Vec::new(), Vec::new(), Vec::new()) };
23682368
// Since there is no "direct implementation" on the reference primitive type, we filter out
23692369
// every implementation which isn't a trait implementation.
2370-
let traits: Vec<_> = v.iter().filter(|i| i.inner_impl().trait_.is_some()).collect();
2370+
let traits = v.iter().filter(|i| i.inner_impl().trait_.is_some());
23712371
let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) =
2372-
traits.into_iter().partition(|t| t.inner_impl().kind.is_auto());
2372+
traits.partition(|t| t.inner_impl().kind.is_auto());
23732373

23742374
let (blanket_impl, concrete): (Vec<&Impl>, _) =
23752375
concrete.into_iter().partition(|t| t.inner_impl().kind.is_blanket());

src/librustdoc/html/render/write_shared.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub(super) fn write_shared(
312312
if line.starts_with(&prefix) {
313313
continue;
314314
}
315-
if line.ends_with(",") {
315+
if line.ends_with(',') {
316316
ret.push(line[..line.len() - 1].to_string());
317317
} else {
318318
// No comma (it's the case for the last added crate line)

0 commit comments

Comments
 (0)