mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
use &str / String literals instead of format!()
This commit is contained in:
parent
35a99eef32
commit
3af7df91fc
@ -649,7 +649,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
if !assign_value.is_empty() {
|
||||
err.span_suggestion_verbose(
|
||||
sugg_span.shrink_to_hi(),
|
||||
format!("consider assigning a value"),
|
||||
"consider assigning a value",
|
||||
format!(" = {}", assign_value),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -270,7 +270,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
for extra in extra_info {
|
||||
match extra {
|
||||
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
|
||||
err.span_note(*span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
|
||||
err.span_note(*span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
for extra in extra_info {
|
||||
match extra {
|
||||
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
|
||||
diag.span_note(span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
|
||||
diag.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||
// We prefer the latter because it matches the behavior of
|
||||
// Clang.
|
||||
if late && matches!(reg, InlineAsmRegOrRegClass::Reg(_)) {
|
||||
constraints.push(format!("{}", reg_to_llvm(reg, Some(&in_value.layout))));
|
||||
constraints.push(reg_to_llvm(reg, Some(&in_value.layout)).to_string());
|
||||
} else {
|
||||
constraints.push(format!("{}", op_idx[&idx]));
|
||||
}
|
||||
|
@ -2240,7 +2240,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
),
|
||||
"s",
|
||||
),
|
||||
[only] => (format!("{only}"), ""),
|
||||
[only] => (only.to_string(), ""),
|
||||
[] => unreachable!(),
|
||||
};
|
||||
let last_span = *arg_spans.last().unwrap();
|
||||
|
@ -406,7 +406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
let note_about_variant_field_privacy = (field_is_local && !field_is_accessible)
|
||||
.then(|| format!(" (its field is private, but it's local to this crate and its privacy can be changed)"));
|
||||
.then(|| " (its field is private, but it's local to this crate and its privacy can be changed)".to_string());
|
||||
|
||||
let sole_field_ty = sole_field.ty(self.tcx, substs);
|
||||
if self.can_coerce(expr_ty, sole_field_ty) {
|
||||
|
@ -1013,7 +1013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
} else {
|
||||
args_span
|
||||
};
|
||||
labels.push((span, format!("multiple arguments are missing")));
|
||||
labels.push((span, "multiple arguments are missing".to_string()));
|
||||
suggestion_text = match suggestion_text {
|
||||
SuggestionText::None | SuggestionText::Provide(_) => {
|
||||
SuggestionText::Provide(true)
|
||||
|
@ -319,11 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
err.multipart_suggestion_verbose(
|
||||
format!("use parentheses to call these"),
|
||||
sugg,
|
||||
applicability,
|
||||
);
|
||||
err.multipart_suggestion_verbose("use parentheses to call these", sugg, applicability);
|
||||
|
||||
true
|
||||
} else {
|
||||
|
@ -1007,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&format!("there is a method with a similar name",),
|
||||
"there is a method with a similar name",
|
||||
lev_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -184,7 +184,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
|
||||
let text = if br.has_name() {
|
||||
format!("the lifetime `{}` as defined here", br.name)
|
||||
} else {
|
||||
format!("the anonymous lifetime as defined here")
|
||||
"the anonymous lifetime as defined here".to_string()
|
||||
};
|
||||
(text, sp)
|
||||
}
|
||||
@ -203,7 +203,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
|
||||
sp = param.span;
|
||||
}
|
||||
let text = if name == kw::UnderscoreLifetime {
|
||||
format!("the anonymous lifetime as defined here")
|
||||
"the anonymous lifetime as defined here".to_string()
|
||||
} else {
|
||||
format!("the lifetime `{}` as defined here", name)
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
);
|
||||
}
|
||||
(Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => {
|
||||
err.span_note(sub_span, format!("the lifetime defined here..."));
|
||||
err.span_note(sub_span, "the lifetime defined here...");
|
||||
err.span_note(
|
||||
sup_span,
|
||||
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
|
||||
@ -55,17 +55,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
sub_span,
|
||||
format!("the lifetime `{sub_symbol}` defined here..."),
|
||||
);
|
||||
err.span_note(
|
||||
sup_span,
|
||||
format!("...must outlive the lifetime defined here"),
|
||||
);
|
||||
err.span_note(sup_span, "...must outlive the lifetime defined here");
|
||||
}
|
||||
(Some(sub_span), Some(sup_span), _, _) => {
|
||||
err.span_note(sub_span, format!("the lifetime defined here..."));
|
||||
err.span_note(
|
||||
sup_span,
|
||||
format!("...must outlive the lifetime defined here"),
|
||||
);
|
||||
err.span_note(sub_span, "the lifetime defined here...");
|
||||
err.span_note(sup_span, "...must outlive the lifetime defined here");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
|
||||
);
|
||||
} else {
|
||||
lint.multipart_suggestion_verbose(
|
||||
format!("to check pattern in a loop use `while let`"),
|
||||
"to check pattern in a loop use `while let`",
|
||||
vec![
|
||||
// NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts
|
||||
(expr.span.with_hi(pat.span.lo()), format!("while let {var}(")),
|
||||
(pat.span.between(arg.span), format!(") = ")),
|
||||
(pat.span.between(arg.span), ") = ".to_string()),
|
||||
],
|
||||
Applicability::MaybeIncorrect
|
||||
);
|
||||
@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
|
||||
vec![
|
||||
// NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts
|
||||
(expr.span.with_hi(pat.span.lo()), format!("if let {var}(")),
|
||||
(pat.span.between(arg.span), format!(") = ")),
|
||||
(pat.span.between(arg.span), ") = ".to_string()),
|
||||
],
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
|
@ -39,10 +39,8 @@ impl<'a> DiagnosticDerive<'a> {
|
||||
let init = match builder.slug.value_ref() {
|
||||
None => {
|
||||
span_err(builder.span, "diagnostic slug not specified")
|
||||
.help(format!(
|
||||
"specify the slug as the first argument to the `#[diag(...)]` \
|
||||
attribute, such as `#[diag(hir_analysis_example_error)]`",
|
||||
))
|
||||
.help("specify the slug as the first argument to the `#[diag(...)]` \
|
||||
attribute, such as `#[diag(hir_analysis_example_error)]`")
|
||||
.emit();
|
||||
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
|
||||
}
|
||||
@ -133,10 +131,8 @@ impl<'a> LintDiagnosticDerive<'a> {
|
||||
match builder.slug.value_ref() {
|
||||
None => {
|
||||
span_err(builder.span, "diagnostic slug not specified")
|
||||
.help(format!(
|
||||
"specify the slug as the first argument to the attribute, such as \
|
||||
`#[diag(compiletest_example)]`",
|
||||
))
|
||||
.help("specify the slug as the first argument to the attribute, such as \
|
||||
`#[diag(compiletest_example)]`")
|
||||
.emit();
|
||||
DiagnosticDeriveError::ErrorHandled.to_compile_error()
|
||||
}
|
||||
|
@ -448,15 +448,15 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
|
||||
|
||||
// FIXME: this is a poor version of `pretty_print_const_value`.
|
||||
let fmt_val = |val: &ConstValue<'tcx>| match val {
|
||||
ConstValue::ZeroSized => format!("<ZST>"),
|
||||
ConstValue::ZeroSized => "<ZST>".to_string(),
|
||||
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
|
||||
ConstValue::Slice { .. } => format!("Slice(..)"),
|
||||
ConstValue::ByRef { .. } => format!("ByRef(..)"),
|
||||
ConstValue::Slice { .. } => "Slice(..)".to_string(),
|
||||
ConstValue::ByRef { .. } => "ByRef(..)".to_string(),
|
||||
};
|
||||
|
||||
let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree {
|
||||
ty::ValTree::Leaf(leaf) => format!("ValTree::Leaf({:?})", leaf),
|
||||
ty::ValTree::Branch(_) => format!("ValTree::Branch(..)"),
|
||||
ty::ValTree::Branch(_) => "ValTree::Branch(..)".to_string(),
|
||||
};
|
||||
|
||||
let val = match literal {
|
||||
|
@ -76,7 +76,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
||||
let Some((otherwise, rest)) = arms.split_last() else {
|
||||
return Err(ParseError {
|
||||
span,
|
||||
item_description: format!("no arms"),
|
||||
item_description: "no arms".to_string(),
|
||||
expected: "at least one arm".to_string(),
|
||||
})
|
||||
};
|
||||
|
@ -277,11 +277,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
let override_suggestion =
|
||||
if ["true", "false"].contains(&item_str.to_string().to_lowercase().as_str()) {
|
||||
let item_typo = item_str.to_string().to_lowercase();
|
||||
Some((
|
||||
item_span,
|
||||
"you may want to use a bool value instead",
|
||||
format!("{}", item_typo),
|
||||
))
|
||||
Some((item_span, "you may want to use a bool value instead", item_typo))
|
||||
// FIXME(vincenzopalazzo): make the check smarter,
|
||||
// and maybe expand with levenshtein distance checks
|
||||
} else if item_str.as_str() == "printf" {
|
||||
@ -2324,7 +2320,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
let message = format!("consider introducing lifetime `{}` here", name);
|
||||
should_continue = suggest(err, false, span, &message, sugg);
|
||||
} else {
|
||||
let message = format!("consider introducing a named lifetime parameter");
|
||||
let message = "consider introducing a named lifetime parameter";
|
||||
should_continue = suggest(err, false, span, &message, sugg);
|
||||
}
|
||||
}
|
||||
|
@ -138,10 +138,10 @@ pub fn is_const_evaluatable<'tcx>(
|
||||
} else if uv.has_non_region_param() {
|
||||
NotConstEvaluatable::MentionsParam
|
||||
} else {
|
||||
let guar = infcx.tcx.sess.delay_span_bug(
|
||||
span,
|
||||
format!("Missing value for constant, but no error reported?"),
|
||||
);
|
||||
let guar = infcx
|
||||
.tcx
|
||||
.sess
|
||||
.delay_span_bug(span, "Missing value for constant, but no error reported?");
|
||||
NotConstEvaluatable::Error(guar)
|
||||
};
|
||||
|
||||
|
@ -2332,9 +2332,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
// get rid of :: between Trait and <type>
|
||||
// must be '::' between them, otherwise the parser won't accept the code
|
||||
suggestions.push((between_span, "".to_string(),));
|
||||
suggestions.push((generic_arg.span_ext.shrink_to_hi(), format!(">")));
|
||||
suggestions.push((generic_arg.span_ext.shrink_to_hi(), ">".to_string()));
|
||||
} else {
|
||||
suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), format!(">")));
|
||||
suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), ">".to_string()));
|
||||
}
|
||||
err.multipart_suggestion(
|
||||
message,
|
||||
|
@ -2740,7 +2740,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
ty::Closure(def_id, _) => err.span_note(
|
||||
self.tcx.def_span(def_id),
|
||||
&format!("required because it's used within this closure"),
|
||||
"required because it's used within this closure",
|
||||
),
|
||||
_ => err.note(&msg),
|
||||
};
|
||||
@ -3386,7 +3386,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
err.span_note(
|
||||
multi_span,
|
||||
format!("the method call chain might not have had the expected associated types"),
|
||||
"the method call chain might not have had the expected associated types",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user