Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couple of clippy::perf fixes #99528

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_macros/src/diagnostics/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand All @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_middle/src/ty/consts/valtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
_ => {}
},
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] == "+"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down