Skip to content

Commit e3036df

Browse files
committed
couple of clippy::perf fixes
1 parent 83356b7 commit e3036df

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
@@ -584,15 +584,15 @@ trait UnusedDelimLint {
584584
let sm = cx.sess().source_map();
585585
let lo_replace =
586586
if keep_space.0 &&
587-
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(" ") {
587+
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(' ') {
588588
" ".to_string()
589589
} else {
590590
"".to_string()
591591
};
592592

593593
let hi_replace =
594594
if keep_space.1 &&
595-
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(" ") {
595+
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(' ') {
596596
" ".to_string()
597597
} else {
598598
"".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
@@ -1657,14 +1657,14 @@ impl<'a> Parser<'a> {
16571657
let left = begin_par_sp;
16581658
let right = self.prev_token.span;
16591659
let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) &&
1660-
!snip.ends_with(" ") {
1660+
!snip.ends_with(' ') {
16611661
" ".to_string()
16621662
} else {
16631663
"".to_string()
16641664
};
16651665

16661666
let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) &&
1667-
!snip.starts_with(" ") {
1667+
!snip.starts_with(' ') {
16681668
" ".to_string()
16691669
} else {
16701670
"".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)