clippy::perf fixes

This commit is contained in:
Matthias Krüger 2022-07-20 11:48:11 +02:00
parent 03d488b48a
commit 611bbcb044
10 changed files with 17 additions and 21 deletions

View File

@ -299,7 +299,7 @@ impl DiagnosticMessage {
/// - If `self` is non-translatable then return `self`'s message.
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
let attr = match sub {
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s.clone()),
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s),
SubdiagnosticMessage::FluentIdentifier(id) => {
return DiagnosticMessage::FluentIdentifier(id, None);
}

View File

@ -212,7 +212,7 @@ impl DiagnosticDeriveBuilder {
}
NestedMeta::Meta(meta @ Meta::NameValue(_))
if !is_help_note_or_warn
&& meta.path().segments.last().unwrap().ident.to_string() == "code" =>
&& meta.path().segments.last().unwrap().ident == "code" =>
{
// don't error for valid follow-up attributes
}

View File

@ -194,8 +194,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
let snake_name = Ident::new(
// FIXME: should probably trim prefix, not replace all occurrences
&name
.replace(&format!("{}-", res.ident).replace("_", "-"), "")
.replace("-", "_"),
.replace(&format!("{}-", res.ident).replace('_', "-"), "")
.replace('-', "_"),
span,
);
constants.extend(quote! {
@ -207,7 +207,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
});
for Attribute { id: Identifier { name: attr_name }, .. } in attributes {
let snake_name = Ident::new(&attr_name.replace("-", "_"), span);
let snake_name = Ident::new(&attr_name.replace('-', "_"), span);
if !previous_attrs.insert(snake_name.clone()) {
continue;
}

View File

@ -88,19 +88,17 @@ impl<'tcx> ValTree<'tcx> {
let leafs = self
.unwrap_branch()
.into_iter()
.map(|v| v.unwrap_leaf().try_to_u8().unwrap())
.collect::<Vec<_>>();
.map(|v| v.unwrap_leaf().try_to_u8().unwrap());
return Some(tcx.arena.alloc_from_iter(leafs.into_iter()));
return Some(tcx.arena.alloc_from_iter(leafs));
}
ty::Slice(slice_ty) if *slice_ty == tcx.types.u8 => {
let leafs = self
.unwrap_branch()
.into_iter()
.map(|v| v.unwrap_leaf().try_to_u8().unwrap())
.collect::<Vec<_>>();
.map(|v| v.unwrap_leaf().try_to_u8().unwrap());
return Some(tcx.arena.alloc_from_iter(leafs.into_iter()));
return Some(tcx.arena.alloc_from_iter(leafs));
}
_ => {}
},

View File

@ -1754,7 +1754,6 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|| self.in_assoc_ty
|| self.tcx.resolutions(()).has_pub_restricted
{
let descr = descr.to_string();
let vis_span =
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
if kind == "trait" {

View File

@ -2608,7 +2608,7 @@ fn show_candidates(
"item".to_string()
};
let plural_descr =
if descr.ends_with("s") { format!("{}es", descr) } else { format!("{}s", descr) };
if descr.ends_with('s') { format!("{}es", descr) } else { format!("{}s", descr) };
let mut msg = format!("{}these {} exist but are inaccessible", prefix, plural_descr);
let mut has_colon = false;

View File

@ -535,7 +535,7 @@ mod parse {
) -> bool {
match v {
Some(s) => {
for s in s.split(",") {
for s in s.split(',') {
let Some(pass_name) = s.strip_prefix(&['+', '-'][..]) else { return false };
slot.push((pass_name.to_string(), &s[..1] == "+"));
}

View File

@ -607,10 +607,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
"{}, {}={}>",
&constraint[..constraint.len() - 1],
item.name,
term.to_string()
term
);
} else {
constraint.push_str(&format!("<{}={}>", item.name, term.to_string()));
constraint.push_str(&format!("<{}={}>", item.name, term));
}
}

View File

@ -1803,7 +1803,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.source_map()
.span_to_snippet(range_end.expr.span)
.map(|s| format!(" from `{s}`"))
.unwrap_or(String::new());
.unwrap_or_default();
err.span_suggestion(
range_start.span.shrink_to_hi(),
&format!("to set the remaining fields{instead}, separate the last named field with a comma"),
@ -2362,7 +2362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
};
let expr_snippet =
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or_default();
let is_wrapped = expr_snippet.starts_with('(') && expr_snippet.ends_with(')');
let after_open = expr.span.lo() + rustc_span::BytePos(1);
let before_close = expr.span.hi() - rustc_span::BytePos(1);

View File

@ -72,9 +72,8 @@ impl<'tcx> ExprUseDelegate<'tcx> {
}
fn mark_consumed(&mut self, consumer: HirId, target: TrackedValue) {
if !self.places.consumed.contains_key(&consumer) {
self.places.consumed.insert(consumer, <_>::default());
}
self.places.consumed.entry(consumer).or_insert_with(|| <_>::default());
debug!(?consumer, ?target, "mark_consumed");
self.places.consumed.get_mut(&consumer).map(|places| places.insert(target));
}