Skip to content

Commit 1077d57

Browse files
committed
remove redundant clones
1 parent 2816486 commit 1077d57

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,13 @@ impl<'a> Parser<'a> {
570570
let expect = tokens_to_string(&expected);
571571
let actual = super::token_descr(&self.token);
572572
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {
573+
let fmt = format!("expected one of {expect}, found {actual}");
573574
let short_expect = if expected.len() > 6 {
574575
format!("{} possible tokens", expected.len())
575576
} else {
576-
expect.clone()
577+
expect
577578
};
578-
(
579-
format!("expected one of {expect}, found {actual}"),
580-
(self.prev_token.span.shrink_to_hi(), format!("expected one of {short_expect}")),
581-
)
579+
(fmt, (self.prev_token.span.shrink_to_hi(), format!("expected one of {short_expect}")))
582580
} else if expected.is_empty() {
583581
(
584582
format!("unexpected token: {actual}"),

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -2944,22 +2944,25 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29442944
rustc_transmute::Answer::No(reason) => {
29452945
let dst = trait_ref.skip_binder().substs.type_at(0);
29462946
let src = trait_ref.skip_binder().substs.type_at(1);
2947-
let custom_err_msg = format!("`{src}` cannot be safely transmuted into `{dst}` in the defining scope of `{scope}`").to_string();
2947+
let custom_err_msg = format!(
2948+
"`{src}` cannot be safely transmuted into `{dst}` in the defining scope of `{scope}`"
2949+
);
29482950
let reason_msg = match reason {
29492951
rustc_transmute::Reason::SrcIsUnspecified => {
2950-
format!("`{src}` does not have a well-specified layout").to_string()
2952+
format!("`{src}` does not have a well-specified layout")
29512953
}
2954+
29522955
rustc_transmute::Reason::DstIsUnspecified => {
2953-
format!("`{dst}` does not have a well-specified layout").to_string()
2956+
format!("`{dst}` does not have a well-specified layout")
29542957
}
2958+
29552959
rustc_transmute::Reason::DstIsBitIncompatible => {
29562960
format!("At least one value of `{src}` isn't a bit-valid value of `{dst}`")
2957-
.to_string()
29582961
}
2962+
29592963
rustc_transmute::Reason::DstIsPrivate => format!(
29602964
"`{dst}` is or contains a type or field that is not visible in that scope"
2961-
)
2962-
.to_string(),
2965+
),
29632966
// FIXME(bryangarza): Include the number of bytes of src and dst
29642967
rustc_transmute::Reason::DstIsTooBig => {
29652968
format!("The size of `{src}` is smaller than the size of `{dst}`")

0 commit comments

Comments
 (0)