Skip to content

Commit 230b775

Browse files
authored
Rollup merge of #99528 - matthiaskrgr:2022_07_perf, r=estebank
couple of clippy::perf fixes
2 parents da18bd1 + 611bbcb commit 230b775

File tree

10 files changed

+17
-21
lines changed

10 files changed

+17
-21
lines changed

compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl DiagnosticMessage {
299299
/// - If `self` is non-translatable then return `self`'s message.
300300
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
301301
let attr = match sub {
302-
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s.clone()),
302+
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s),
303303
SubdiagnosticMessage::FluentIdentifier(id) => {
304304
return DiagnosticMessage::FluentIdentifier(id, None);
305305
}

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl DiagnosticDeriveBuilder {
212212
}
213213
NestedMeta::Meta(meta @ Meta::NameValue(_))
214214
if !is_help_note_or_warn
215-
&& meta.path().segments.last().unwrap().ident.to_string() == "code" =>
215+
&& meta.path().segments.last().unwrap().ident == "code" =>
216216
{
217217
// don't error for valid follow-up attributes
218218
}

compiler/rustc_macros/src/diagnostics/fluent.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
194194
let snake_name = Ident::new(
195195
// FIXME: should probably trim prefix, not replace all occurrences
196196
&name
197-
.replace(&format!("{}-", res.ident).replace("_", "-"), "")
198-
.replace("-", "_"),
197+
.replace(&format!("{}-", res.ident).replace('_', "-"), "")
198+
.replace('-', "_"),
199199
span,
200200
);
201201
constants.extend(quote! {
@@ -207,7 +207,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
207207
});
208208

209209
for Attribute { id: Identifier { name: attr_name }, .. } in attributes {
210-
let snake_name = Ident::new(&attr_name.replace("-", "_"), span);
210+
let snake_name = Ident::new(&attr_name.replace('-', "_"), span);
211211
if !previous_attrs.insert(snake_name.clone()) {
212212
continue;
213213
}

compiler/rustc_middle/src/ty/consts/valtree.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,17 @@ impl<'tcx> ValTree<'tcx> {
8888
let leafs = self
8989
.unwrap_branch()
9090
.into_iter()
91-
.map(|v| v.unwrap_leaf().try_to_u8().unwrap())
92-
.collect::<Vec<_>>();
91+
.map(|v| v.unwrap_leaf().try_to_u8().unwrap());
9392

94-
return Some(tcx.arena.alloc_from_iter(leafs.into_iter()));
93+
return Some(tcx.arena.alloc_from_iter(leafs));
9594
}
9695
ty::Slice(slice_ty) if *slice_ty == tcx.types.u8 => {
9796
let leafs = self
9897
.unwrap_branch()
9998
.into_iter()
100-
.map(|v| v.unwrap_leaf().try_to_u8().unwrap())
101-
.collect::<Vec<_>>();
99+
.map(|v| v.unwrap_leaf().try_to_u8().unwrap());
102100

103-
return Some(tcx.arena.alloc_from_iter(leafs.into_iter()));
101+
return Some(tcx.arena.alloc_from_iter(leafs));
104102
}
105103
_ => {}
106104
},

compiler/rustc_privacy/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,6 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17541754
|| self.in_assoc_ty
17551755
|| self.tcx.resolutions(()).has_pub_restricted
17561756
{
1757-
let descr = descr.to_string();
17581757
let vis_span =
17591758
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
17601759
if kind == "trait" {

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ fn show_candidates(
26082608
"item"
26092609
};
26102610
let plural_descr =
2611-
if descr.ends_with("s") { format!("{}es", descr) } else { format!("{}s", descr) };
2611+
if descr.ends_with('s') { format!("{}es", descr) } else { format!("{}s", descr) };
26122612

26132613
let mut msg = format!("{}these {} exist but are inaccessible", prefix, plural_descr);
26142614
let mut has_colon = false;

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ mod parse {
535535
) -> bool {
536536
match v {
537537
Some(s) => {
538-
for s in s.split(",") {
538+
for s in s.split(',') {
539539
let Some(pass_name) = s.strip_prefix(&['+', '-'][..]) else { return false };
540540
slot.push((pass_name.to_string(), &s[..1] == "+"));
541541
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
607607
"{}, {}={}>",
608608
&constraint[..constraint.len() - 1],
609609
item.name,
610-
term.to_string()
610+
term
611611
);
612612
} else {
613-
constraint.push_str(&format!("<{}={}>", item.name, term.to_string()));
613+
constraint.push_str(&format!("<{}={}>", item.name, term));
614614
}
615615
}
616616

compiler/rustc_typeck/src/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18031803
.source_map()
18041804
.span_to_snippet(range_end.expr.span)
18051805
.map(|s| format!(" from `{s}`"))
1806-
.unwrap_or(String::new());
1806+
.unwrap_or_default();
18071807
err.span_suggestion(
18081808
range_start.span.shrink_to_hi(),
18091809
&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> {
23622362
false
23632363
};
23642364
let expr_snippet =
2365-
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
2365+
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or_default();
23662366
let is_wrapped = expr_snippet.starts_with('(') && expr_snippet.ends_with(')');
23672367
let after_open = expr.span.lo() + rustc_span::BytePos(1);
23682368
let before_close = expr.span.hi() - rustc_span::BytePos(1);

compiler/rustc_typeck/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ impl<'tcx> ExprUseDelegate<'tcx> {
7272
}
7373

7474
fn mark_consumed(&mut self, consumer: HirId, target: TrackedValue) {
75-
if !self.places.consumed.contains_key(&consumer) {
76-
self.places.consumed.insert(consumer, <_>::default());
77-
}
75+
self.places.consumed.entry(consumer).or_insert_with(|| <_>::default());
76+
7877
debug!(?consumer, ?target, "mark_consumed");
7978
self.places.consumed.get_mut(&consumer).map(|places| places.insert(target));
8079
}

0 commit comments

Comments
 (0)