Skip to content

Commit ebe3563

Browse files
authored
Rollup merge of rust-lang#105873 - matthiaskrgr:clippy_fmt, r=Nilstrieb
use &str / String literals instead of format!()
2 parents 221e71e + 3af7df9 commit ebe3563

File tree

19 files changed

+37
-55
lines changed

19 files changed

+37
-55
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
649649
if !assign_value.is_empty() {
650650
err.span_suggestion_verbose(
651651
sugg_span.shrink_to_hi(),
652-
format!("consider assigning a value"),
652+
"consider assigning a value",
653653
format!(" = {}", assign_value),
654654
Applicability::MaybeIncorrect,
655655
);

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
270270
for extra in extra_info {
271271
match extra {
272272
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
273-
err.span_note(*span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
273+
err.span_note(*span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
274274
}
275275
}
276276
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
472472
for extra in extra_info {
473473
match extra {
474474
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
475-
diag.span_note(span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
475+
diag.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
476476
}
477477
}
478478
}

compiler/rustc_codegen_llvm/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
144144
// We prefer the latter because it matches the behavior of
145145
// Clang.
146146
if late && matches!(reg, InlineAsmRegOrRegClass::Reg(_)) {
147-
constraints.push(format!("{}", reg_to_llvm(reg, Some(&in_value.layout))));
147+
constraints.push(reg_to_llvm(reg, Some(&in_value.layout)).to_string());
148148
} else {
149149
constraints.push(format!("{}", op_idx[&idx]));
150150
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22402240
),
22412241
"s",
22422242
),
2243-
[only] => (format!("{only}"), ""),
2243+
[only] => (only.to_string(), ""),
22442244
[] => unreachable!(),
22452245
};
22462246
let last_span = *arg_spans.last().unwrap();

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
406406
}
407407

408408
let note_about_variant_field_privacy = (field_is_local && !field_is_accessible)
409-
.then(|| format!(" (its field is private, but it's local to this crate and its privacy can be changed)"));
409+
.then(|| " (its field is private, but it's local to this crate and its privacy can be changed)".to_string());
410410

411411
let sole_field_ty = sole_field.ty(self.tcx, substs);
412412
if self.can_coerce(expr_ty, sole_field_ty) {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10131013
} else {
10141014
args_span
10151015
};
1016-
labels.push((span, format!("multiple arguments are missing")));
1016+
labels.push((span, "multiple arguments are missing".to_string()));
10171017
suggestion_text = match suggestion_text {
10181018
SuggestionText::None | SuggestionText::Provide(_) => {
10191019
SuggestionText::Provide(true)

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
319319
}
320320
}
321321

322-
err.multipart_suggestion_verbose(
323-
format!("use parentheses to call these"),
324-
sugg,
325-
applicability,
326-
);
322+
err.multipart_suggestion_verbose("use parentheses to call these", sugg, applicability);
327323

328324
true
329325
} else {

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10071007
if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter {
10081008
err.span_suggestion(
10091009
span,
1010-
&format!("there is a method with a similar name",),
1010+
"there is a method with a similar name",
10111011
lev_candidate.name,
10121012
Applicability::MaybeIncorrect,
10131013
);

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
184184
let text = if br.has_name() {
185185
format!("the lifetime `{}` as defined here", br.name)
186186
} else {
187-
format!("the anonymous lifetime as defined here")
187+
"the anonymous lifetime as defined here".to_string()
188188
};
189189
(text, sp)
190190
}
@@ -203,7 +203,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
203203
sp = param.span;
204204
}
205205
let text = if name == kw::UnderscoreLifetime {
206-
format!("the anonymous lifetime as defined here")
206+
"the anonymous lifetime as defined here".to_string()
207207
} else {
208208
format!("the lifetime `{}` as defined here", name)
209209
};

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
4444
);
4545
}
4646
(Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => {
47-
err.span_note(sub_span, format!("the lifetime defined here..."));
47+
err.span_note(sub_span, "the lifetime defined here...");
4848
err.span_note(
4949
sup_span,
5050
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
@@ -55,17 +55,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
5555
sub_span,
5656
format!("the lifetime `{sub_symbol}` defined here..."),
5757
);
58-
err.span_note(
59-
sup_span,
60-
format!("...must outlive the lifetime defined here"),
61-
);
58+
err.span_note(sup_span, "...must outlive the lifetime defined here");
6259
}
6360
(Some(sub_span), Some(sup_span), _, _) => {
64-
err.span_note(sub_span, format!("the lifetime defined here..."));
65-
err.span_note(
66-
sup_span,
67-
format!("...must outlive the lifetime defined here"),
68-
);
61+
err.span_note(sub_span, "the lifetime defined here...");
62+
err.span_note(sup_span, "...must outlive the lifetime defined here");
6963
}
7064
_ => {}
7165
}

compiler/rustc_lint/src/for_loops_over_fallibles.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
7171
);
7272
} else {
7373
lint.multipart_suggestion_verbose(
74-
format!("to check pattern in a loop use `while let`"),
74+
"to check pattern in a loop use `while let`",
7575
vec![
7676
// NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts
7777
(expr.span.with_hi(pat.span.lo()), format!("while let {var}(")),
78-
(pat.span.between(arg.span), format!(") = ")),
78+
(pat.span.between(arg.span), ") = ".to_string()),
7979
],
8080
Applicability::MaybeIncorrect
8181
);
@@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
9595
vec![
9696
// NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts
9797
(expr.span.with_hi(pat.span.lo()), format!("if let {var}(")),
98-
(pat.span.between(arg.span), format!(") = ")),
98+
(pat.span.between(arg.span), ") = ".to_string()),
9999
],
100100
Applicability::MaybeIncorrect,
101101
)

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ impl<'a> DiagnosticDerive<'a> {
3939
let init = match builder.slug.value_ref() {
4040
None => {
4141
span_err(builder.span, "diagnostic slug not specified")
42-
.help(format!(
43-
"specify the slug as the first argument to the `#[diag(...)]` \
44-
attribute, such as `#[diag(hir_analysis_example_error)]`",
45-
))
42+
.help("specify the slug as the first argument to the `#[diag(...)]` \
43+
attribute, such as `#[diag(hir_analysis_example_error)]`")
4644
.emit();
4745
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
4846
}
@@ -133,10 +131,8 @@ impl<'a> LintDiagnosticDerive<'a> {
133131
match builder.slug.value_ref() {
134132
None => {
135133
span_err(builder.span, "diagnostic slug not specified")
136-
.help(format!(
137-
"specify the slug as the first argument to the attribute, such as \
138-
`#[diag(compiletest_example)]`",
139-
))
134+
.help("specify the slug as the first argument to the attribute, such as \
135+
`#[diag(compiletest_example)]`")
140136
.emit();
141137
DiagnosticDeriveError::ErrorHandled.to_compile_error()
142138
}

compiler/rustc_middle/src/mir/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
448448

449449
// FIXME: this is a poor version of `pretty_print_const_value`.
450450
let fmt_val = |val: &ConstValue<'tcx>| match val {
451-
ConstValue::ZeroSized => format!("<ZST>"),
451+
ConstValue::ZeroSized => "<ZST>".to_string(),
452452
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
453-
ConstValue::Slice { .. } => format!("Slice(..)"),
454-
ConstValue::ByRef { .. } => format!("ByRef(..)"),
453+
ConstValue::Slice { .. } => "Slice(..)".to_string(),
454+
ConstValue::ByRef { .. } => "ByRef(..)".to_string(),
455455
};
456456

457457
let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree {
458458
ty::ValTree::Leaf(leaf) => format!("ValTree::Leaf({:?})", leaf),
459-
ty::ValTree::Branch(_) => format!("ValTree::Branch(..)"),
459+
ty::ValTree::Branch(_) => "ValTree::Branch(..)".to_string(),
460460
};
461461

462462
let val = match literal {

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
7676
let Some((otherwise, rest)) = arms.split_last() else {
7777
return Err(ParseError {
7878
span,
79-
item_description: format!("no arms"),
79+
item_description: "no arms".to_string(),
8080
expected: "at least one arm".to_string(),
8181
})
8282
};

compiler/rustc_resolve/src/late/diagnostics.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
277277
let override_suggestion =
278278
if ["true", "false"].contains(&item_str.to_string().to_lowercase().as_str()) {
279279
let item_typo = item_str.to_string().to_lowercase();
280-
Some((
281-
item_span,
282-
"you may want to use a bool value instead",
283-
format!("{}", item_typo),
284-
))
280+
Some((item_span, "you may want to use a bool value instead", item_typo))
285281
// FIXME(vincenzopalazzo): make the check smarter,
286282
// and maybe expand with levenshtein distance checks
287283
} else if item_str.as_str() == "printf" {
@@ -2324,7 +2320,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
23242320
let message = format!("consider introducing lifetime `{}` here", name);
23252321
should_continue = suggest(err, false, span, &message, sugg);
23262322
} else {
2327-
let message = format!("consider introducing a named lifetime parameter");
2323+
let message = "consider introducing a named lifetime parameter";
23282324
should_continue = suggest(err, false, span, &message, sugg);
23292325
}
23302326
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ pub fn is_const_evaluatable<'tcx>(
138138
} else if uv.has_non_region_param() {
139139
NotConstEvaluatable::MentionsParam
140140
} else {
141-
let guar = infcx.tcx.sess.delay_span_bug(
142-
span,
143-
format!("Missing value for constant, but no error reported?"),
144-
);
141+
let guar = infcx
142+
.tcx
143+
.sess
144+
.delay_span_bug(span, "Missing value for constant, but no error reported?");
145145
NotConstEvaluatable::Error(guar)
146146
};
147147

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2332,9 +2332,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23322332
// get rid of :: between Trait and <type>
23332333
// must be '::' between them, otherwise the parser won't accept the code
23342334
suggestions.push((between_span, "".to_string(),));
2335-
suggestions.push((generic_arg.span_ext.shrink_to_hi(), format!(">")));
2335+
suggestions.push((generic_arg.span_ext.shrink_to_hi(), ">".to_string()));
23362336
} else {
2337-
suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), format!(">")));
2337+
suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), ">".to_string()));
23382338
}
23392339
err.multipart_suggestion(
23402340
message,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
27402740
}
27412741
ty::Closure(def_id, _) => err.span_note(
27422742
self.tcx.def_span(def_id),
2743-
&format!("required because it's used within this closure"),
2743+
"required because it's used within this closure",
27442744
),
27452745
_ => err.note(&msg),
27462746
};
@@ -3386,7 +3386,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
33863386
}
33873387
err.span_note(
33883388
multi_span,
3389-
format!("the method call chain might not have had the expected associated types"),
3389+
"the method call chain might not have had the expected associated types",
33903390
);
33913391
}
33923392
}

0 commit comments

Comments
 (0)