Skip to content

Commit 86af713

Browse files
authored
Rollup merge of rust-lang#99103 - TaKO8Ki:avoid-&str-to-string-conversions, r=oli-obk
Avoid some `&str` to `String` conversions This patch removes some `&str` to `String` conversions.
2 parents 76f968d + bda83e6 commit 86af713

File tree

13 files changed

+23
-34
lines changed

13 files changed

+23
-34
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -597,16 +597,16 @@ impl UseSpans<'_> {
597597
}
598598

599599
/// Describe the span associated with a use of a place.
600-
pub(super) fn describe(&self) -> String {
600+
pub(super) fn describe(&self) -> &str {
601601
match *self {
602602
UseSpans::ClosureUse { generator_kind, .. } => {
603603
if generator_kind.is_some() {
604-
" in generator".to_string()
604+
" in generator"
605605
} else {
606-
" in closure".to_string()
606+
" in closure"
607607
}
608608
}
609-
_ => String::new(),
609+
_ => "",
610610
}
611611
}
612612

compiler/rustc_middle/src/mir/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1824,12 +1824,10 @@ impl BorrowKind {
18241824
}
18251825
}
18261826

1827-
pub fn describe_mutability(&self) -> String {
1827+
pub fn describe_mutability(&self) -> &str {
18281828
match *self {
1829-
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => {
1830-
"immutable".to_string()
1831-
}
1832-
BorrowKind::Mut { .. } => "mutable".to_string(),
1829+
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => "immutable",
1830+
BorrowKind::Mut { .. } => "mutable",
18331831
}
18341832
}
18351833
}

compiler/rustc_mir_transform/src/check_packed_ref.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
3939
let message = if tcx.generics_of(def_id).own_requires_monomorphization() {
4040
"`#[derive]` can't be used on a `#[repr(packed)]` struct with \
4141
type or const parameters (error E0133)"
42-
.to_string()
4342
} else {
4443
"`#[derive]` can't be used on a `#[repr(packed)]` struct that \
4544
does not derive Copy (error E0133)"
46-
.to_string()
4745
};
48-
lint.build(&message).emit();
46+
lint.build(message).emit();
4947
});
5048
}
5149

compiler/rustc_resolve/src/diagnostics.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,7 @@ impl<'a> Resolver<'a> {
943943
"generic parameters with a default cannot use \
944944
forward declared identifiers"
945945
);
946-
err.span_label(
947-
span,
948-
"defaulted generic parameters cannot be forward declared".to_string(),
949-
);
946+
err.span_label(span, "defaulted generic parameters cannot be forward declared");
950947
err
951948
}
952949
ResolutionError::ParamInTyOfConstParam(name) => {

compiler/rustc_resolve/src/late/diagnostics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
349349

350350
err.code(rustc_errors::error_code!(E0424));
351351
err.span_label(span, match source {
352-
PathSource::Pat => "`self` value is a keyword and may not be bound to variables or shadowed"
353-
.to_string(),
354-
_ => "`self` value is a keyword only available in methods with a `self` parameter"
355-
.to_string(),
352+
PathSource::Pat => "`self` value is a keyword and may not be bound to variables or shadowed",
353+
_ => "`self` value is a keyword only available in methods with a `self` parameter",
356354
});
357355
if let Some((fn_kind, span)) = &self.diagnostic_metadata.current_function {
358356
// The current function has a `self' parameter, but we were unable to resolve

compiler/rustc_span/src/hygiene.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ pub fn debug_hygiene_data(verbose: bool) -> String {
629629
if verbose {
630630
format!("{:#?}", data)
631631
} else {
632-
let mut s = String::from("");
633-
s.push_str("Expansions:");
632+
let mut s = String::from("Expansions:");
634633
let mut debug_expn_data = |(id, expn_data): (&ExpnId, &ExpnData)| {
635634
s.push_str(&format!(
636635
"\n{:?}: parent: {:?}, call_site_ctxt: {:?}, def_site_ctxt: {:?}, kind: {:?}",

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn report_conflicting_impls(
406406
let mut err = err.build(&msg);
407407
match tcx.span_of_impl(overlap.with_impl) {
408408
Ok(span) => {
409-
err.span_label(span, "first implementation here".to_string());
409+
err.span_label(span, "first implementation here");
410410

411411
err.span_label(
412412
impl_span,

compiler/rustc_typeck/src/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
263263
} else if let ExprKind::Block(block, _) = &then_expr.kind
264264
&& let Some(expr) = &block.expr
265265
{
266-
err.span_label(expr.span, "found here".to_string());
266+
err.span_label(expr.span, "found here");
267267
}
268268
err.note("`if` expressions without `else` evaluate to `()`");
269269
err.help("consider adding an `else` block that evaluates to the expected type");

compiler/rustc_typeck/src/check/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
317317
.tcx
318318
.is_diagnostic_item(sym::Result, expected_adt.did())
319319
{
320-
vec!["Ok(())".to_string()]
320+
vec!["Ok(())"]
321321
} else if self.tcx.is_diagnostic_item(sym::Option, expected_adt.did()) {
322-
vec!["None".to_string(), "Some(())".to_string()]
322+
vec!["None", "Some(())"]
323323
} else {
324324
return;
325325
};

compiler/rustc_typeck/src/check/op.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
565565
.is_ok()
566566
{
567567
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
568-
("( /* arguments */ )".to_string(), Applicability::HasPlaceholders)
568+
("( /* arguments */ )", Applicability::HasPlaceholders)
569569
} else {
570-
("()".to_string(), Applicability::MaybeIncorrect)
570+
("()", Applicability::MaybeIncorrect)
571571
};
572572

573573
err.span_suggestion_verbose(

compiler/rustc_typeck/src/hir_wf_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn diagnostic_hir_wf_check<'tcx>(
8686

8787
let errors = fulfill.select_all_or_error(&infcx);
8888
if !errors.is_empty() {
89-
tracing::debug!("Wf-check got errors for {:?}: {:?}", ty, errors);
89+
debug!("Wf-check got errors for {:?}: {:?}", ty, errors);
9090
for error in errors {
9191
if error.obligation.predicate == self.predicate {
9292
// Save the cause from the greatest depth - this corresponds

compiler/rustc_typeck/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
252252
let mut diag =
253253
struct_span_err!(tcx.sess, generics_param_span.unwrap_or(main_span), E0131, "{}", msg);
254254
if let Some(generics_param_span) = generics_param_span {
255-
let label = "`main` cannot have generic parameters".to_string();
255+
let label = "`main` cannot have generic parameters";
256256
diag.span_label(generics_param_span, label);
257257
}
258258
diag.emit();
@@ -307,8 +307,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
307307
let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span);
308308
if !return_ty.bound_vars().is_empty() {
309309
let msg = "`main` function return type is not allowed to have generic \
310-
parameters"
311-
.to_owned();
310+
parameters";
312311
struct_span_err!(tcx.sess, return_ty_span, E0131, "{}", msg).emit();
313312
error = true;
314313
}

compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
126126
}
127127
}
128128

129-
fn kind(&self) -> String {
130-
if self.missing_lifetimes() { "lifetime".to_string() } else { "generic".to_string() }
129+
fn kind(&self) -> &str {
130+
if self.missing_lifetimes() { "lifetime" } else { "generic" }
131131
}
132132

133133
fn num_provided_args(&self) -> usize {

0 commit comments

Comments
 (0)