couple of clippy::perf fixes

This commit is contained in:
Matthias Krüger 2022-11-18 10:30:47 +01:00
parent 83356b78c4
commit e3036df003
11 changed files with 14 additions and 16 deletions

View File

@ -1436,7 +1436,7 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &ParseSess) -> bool {
let crate_matches = if c.starts_with("allsorts-rental") { let crate_matches = if c.starts_with("allsorts-rental") {
true true
} else { } else {
let mut version = c.trim_start_matches("rental-").split("."); let mut version = c.trim_start_matches("rental-").split('.');
version.next() == Some("0") version.next() == Some("0")
&& version.next() == Some("5") && version.next() == Some("5")
&& version && version

View File

@ -584,7 +584,7 @@ trait UnusedDelimLint {
let sm = cx.sess().source_map(); let sm = cx.sess().source_map();
let lo_replace = let lo_replace =
if keep_space.0 && if keep_space.0 &&
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(" ") { let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(' ') {
" ".to_string() " ".to_string()
} else { } else {
"".to_string() "".to_string()
@ -592,7 +592,7 @@ trait UnusedDelimLint {
let hi_replace = let hi_replace =
if keep_space.1 && if keep_space.1 &&
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(" ") { let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(' ') {
" ".to_string() " ".to_string()
} else { } else {
"".to_string() "".to_string()

View File

@ -830,5 +830,5 @@ pub(super) fn should_generate_set_arg(field: &Field) -> bool {
} }
pub(super) fn is_doc_comment(attr: &Attribute) -> bool { pub(super) fn is_doc_comment(attr: &Attribute) -> bool {
attr.path.segments.last().unwrap().ident.to_string() == "doc" attr.path.segments.last().unwrap().ident == "doc"
} }

View File

@ -2194,11 +2194,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
define_scoped_cx!(self); define_scoped_cx!(self);
let possible_names = let possible_names = ('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}")));
('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}"))).collect::<Vec<_>>();
let mut available_names = possible_names let mut available_names = possible_names
.into_iter()
.filter(|name| !self.used_region_names.contains(&name)) .filter(|name| !self.used_region_names.contains(&name))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
debug!(?available_names); debug!(?available_names);

View File

@ -899,7 +899,7 @@ fn debug_with_context_rec<V: Debug + Eq>(
let info_elem = map.places[child].proj_elem.unwrap(); let info_elem = map.places[child].proj_elem.unwrap();
let child_place_str = match info_elem { let child_place_str = match info_elem {
TrackElem::Field(field) => { TrackElem::Field(field) => {
if place_str.starts_with("*") { if place_str.starts_with('*') {
format!("({}).{}", place_str, field.index()) format!("({}).{}", place_str, field.index())
} else { } else {
format!("{}.{}", place_str, field.index()) format!("{}.{}", place_str, field.index())

View File

@ -1657,14 +1657,14 @@ impl<'a> Parser<'a> {
let left = begin_par_sp; let left = begin_par_sp;
let right = self.prev_token.span; let right = self.prev_token.span;
let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) && let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) &&
!snip.ends_with(" ") { !snip.ends_with(' ') {
" ".to_string() " ".to_string()
} else { } else {
"".to_string() "".to_string()
}; };
let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) && let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) &&
!snip.starts_with(" ") { !snip.starts_with(' ') {
" ".to_string() " ".to_string()
} else { } else {
"".to_string() "".to_string()

View File

@ -353,7 +353,7 @@ impl CheckAttrVisitor<'_> {
attr.span, attr.span,
OnlyHasEffectOn { OnlyHasEffectOn {
attr_name: attr.name_or_empty(), attr_name: attr.name_or_empty(),
target_name: allowed_target.name().replace(" ", "_"), target_name: allowed_target.name().replace(' ', "_"),
}, },
); );
} }

View File

@ -772,7 +772,7 @@ impl<'tcx> DeadVisitor<'tcx> {
self.tcx.emit_spanned_lint( self.tcx.emit_spanned_lint(
lint, lint,
tcx.hir().local_def_id_to_hir_id(first_id), tcx.hir().local_def_id_to_hir_id(first_id),
MultiSpan::from_spans(spans.clone()), MultiSpan::from_spans(spans),
diag, diag,
); );
} }

View File

@ -418,7 +418,7 @@ impl Options {
) { ) {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
diag.struct_err(&e.to_string()).emit(); diag.struct_err(e).emit();
return Err(1); return Err(1);
} }
}; };
@ -561,7 +561,7 @@ impl Options {
) { ) {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
diag.struct_err(&e.to_string()).emit(); diag.struct_err(e).emit();
return Err(1); return Err(1);
} }
}; };

View File

@ -58,7 +58,7 @@ pub(crate) fn suffix_path(filename: &str, suffix: &str) -> PathBuf {
} }
pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf { pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf {
let filename = filename.rsplit("/").next().unwrap(); let filename = filename.rsplit('/').next().unwrap();
suffix_path(filename, &static_suffix(contents)) suffix_path(filename, &static_suffix(contents))
} }

View File

@ -11,7 +11,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
let test_file_contents = fs::read_to_string(&testfile).unwrap(); let test_file_contents = fs::read_to_string(&testfile).unwrap();
let test_dir = testfile.parent().unwrap(); let test_dir = testfile.parent().unwrap();
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace("-", "_"); let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
let bit_width = if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") { let bit_width = if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") {
format!(".{}bit", bit_width) format!(".{}bit", bit_width)