Skip to content

Commit 3c6fc06

Browse files
authored
Rollup merge of #104566 - matthiaskrgr:clippy_perf_nov18, r=oli-obk
couple of clippy::perf fixes
2 parents 7f35493 + e3036df commit 3c6fc06

File tree

11 files changed

+14
-16
lines changed

11 files changed

+14
-16
lines changed

compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &ParseSess) -> bool {
14361436
let crate_matches = if c.starts_with("allsorts-rental") {
14371437
true
14381438
} else {
1439-
let mut version = c.trim_start_matches("rental-").split(".");
1439+
let mut version = c.trim_start_matches("rental-").split('.');
14401440
version.next() == Some("0")
14411441
&& version.next() == Some("5")
14421442
&& version

compiler/rustc_lint/src/unused.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,15 +582,15 @@ trait UnusedDelimLint {
582582
let sm = cx.sess().source_map();
583583
let lo_replace =
584584
if keep_space.0 &&
585-
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(" ") {
585+
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(' ') {
586586
" ".to_string()
587587
} else {
588588
"".to_string()
589589
};
590590

591591
let hi_replace =
592592
if keep_space.1 &&
593-
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(" ") {
593+
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(' ') {
594594
" ".to_string()
595595
} else {
596596
"".to_string()

compiler/rustc_macros/src/diagnostics/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,5 +830,5 @@ pub(super) fn should_generate_set_arg(field: &Field) -> bool {
830830
}
831831

832832
pub(super) fn is_doc_comment(attr: &Attribute) -> bool {
833-
attr.path.segments.last().unwrap().ident.to_string() == "doc"
833+
attr.path.segments.last().unwrap().ident == "doc"
834834
}

compiler/rustc_middle/src/ty/print/pretty.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2194,11 +2194,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21942194

21952195
define_scoped_cx!(self);
21962196

2197-
let possible_names =
2198-
('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}"))).collect::<Vec<_>>();
2197+
let possible_names = ('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}")));
21992198

22002199
let mut available_names = possible_names
2201-
.into_iter()
22022200
.filter(|name| !self.used_region_names.contains(&name))
22032201
.collect::<Vec<_>>();
22042202
debug!(?available_names);

compiler/rustc_mir_dataflow/src/value_analysis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ fn debug_with_context_rec<V: Debug + Eq>(
899899
let info_elem = map.places[child].proj_elem.unwrap();
900900
let child_place_str = match info_elem {
901901
TrackElem::Field(field) => {
902-
if place_str.starts_with("*") {
902+
if place_str.starts_with('*') {
903903
format!("({}).{}", place_str, field.index())
904904
} else {
905905
format!("{}.{}", place_str, field.index())

compiler/rustc_parse/src/parser/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1660,14 +1660,14 @@ impl<'a> Parser<'a> {
16601660
let left = begin_par_sp;
16611661
let right = self.prev_token.span;
16621662
let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) &&
1663-
!snip.ends_with(" ") {
1663+
!snip.ends_with(' ') {
16641664
" ".to_string()
16651665
} else {
16661666
"".to_string()
16671667
};
16681668

16691669
let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) &&
1670-
!snip.starts_with(" ") {
1670+
!snip.starts_with(' ') {
16711671
" ".to_string()
16721672
} else {
16731673
"".to_string()

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl CheckAttrVisitor<'_> {
353353
attr.span,
354354
OnlyHasEffectOn {
355355
attr_name: attr.name_or_empty(),
356-
target_name: allowed_target.name().replace(" ", "_"),
356+
target_name: allowed_target.name().replace(' ', "_"),
357357
},
358358
);
359359
}

compiler/rustc_passes/src/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'tcx> DeadVisitor<'tcx> {
772772
self.tcx.emit_spanned_lint(
773773
lint,
774774
tcx.hir().local_def_id_to_hir_id(first_id),
775-
MultiSpan::from_spans(spans.clone()),
775+
MultiSpan::from_spans(spans),
776776
diag,
777777
);
778778
}

src/librustdoc/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl Options {
418418
) {
419419
Ok(p) => p,
420420
Err(e) => {
421-
diag.struct_err(&e.to_string()).emit();
421+
diag.struct_err(e).emit();
422422
return Err(1);
423423
}
424424
};
@@ -561,7 +561,7 @@ impl Options {
561561
) {
562562
Ok(p) => p,
563563
Err(e) => {
564-
diag.struct_err(&e.to_string()).emit();
564+
diag.struct_err(e).emit();
565565
return Err(1);
566566
}
567567
};

src/librustdoc/html/static_files.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn suffix_path(filename: &str, suffix: &str) -> PathBuf {
5858
}
5959

6060
pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf {
61-
let filename = filename.rsplit("/").next().unwrap();
61+
let filename = filename.rsplit('/').next().unwrap();
6262
suffix_path(filename, &static_suffix(contents))
6363
}
6464

src/tools/miropt-test-tools/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
1111
let test_file_contents = fs::read_to_string(&testfile).unwrap();
1212

1313
let test_dir = testfile.parent().unwrap();
14-
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace("-", "_");
14+
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
1515

1616
let bit_width = if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") {
1717
format!(".{}bit", bit_width)

0 commit comments

Comments
 (0)