use &str / String literals instead of format!()
This commit is contained in:
parent
35a99eef32
commit
3af7df91fc
19 changed files with 37 additions and 55 deletions
|
@ -649,7 +649,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
if !assign_value.is_empty() {
|
if !assign_value.is_empty() {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
sugg_span.shrink_to_hi(),
|
sugg_span.shrink_to_hi(),
|
||||||
format!("consider assigning a value"),
|
"consider assigning a value",
|
||||||
format!(" = {}", assign_value),
|
format!(" = {}", assign_value),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
|
|
@ -270,7 +270,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
for extra in extra_info {
|
for extra in extra_info {
|
||||||
match extra {
|
match extra {
|
||||||
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
|
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 {
|
for extra in extra_info {
|
||||||
match extra {
|
match extra {
|
||||||
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
|
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
|
// We prefer the latter because it matches the behavior of
|
||||||
// Clang.
|
// Clang.
|
||||||
if late && matches!(reg, InlineAsmRegOrRegClass::Reg(_)) {
|
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 {
|
} else {
|
||||||
constraints.push(format!("{}", op_idx[&idx]));
|
constraints.push(format!("{}", op_idx[&idx]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2240,7 +2240,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
),
|
),
|
||||||
"s",
|
"s",
|
||||||
),
|
),
|
||||||
[only] => (format!("{only}"), ""),
|
[only] => (only.to_string(), ""),
|
||||||
[] => unreachable!(),
|
[] => unreachable!(),
|
||||||
};
|
};
|
||||||
let last_span = *arg_spans.last().unwrap();
|
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)
|
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);
|
let sole_field_ty = sole_field.ty(self.tcx, substs);
|
||||||
if self.can_coerce(expr_ty, sole_field_ty) {
|
if self.can_coerce(expr_ty, sole_field_ty) {
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
args_span
|
args_span
|
||||||
};
|
};
|
||||||
labels.push((span, format!("multiple arguments are missing")));
|
labels.push((span, "multiple arguments are missing".to_string()));
|
||||||
suggestion_text = match suggestion_text {
|
suggestion_text = match suggestion_text {
|
||||||
SuggestionText::None | SuggestionText::Provide(_) => {
|
SuggestionText::None | SuggestionText::Provide(_) => {
|
||||||
SuggestionText::Provide(true)
|
SuggestionText::Provide(true)
|
||||||
|
|
|
@ -319,11 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err.multipart_suggestion_verbose(
|
err.multipart_suggestion_verbose("use parentheses to call these", sugg, applicability);
|
||||||
format!("use parentheses to call these"),
|
|
||||||
sugg,
|
|
||||||
applicability,
|
|
||||||
);
|
|
||||||
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1007,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter {
|
if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!("there is a method with a similar name",),
|
"there is a method with a similar name",
|
||||||
lev_candidate.name,
|
lev_candidate.name,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
|
|
@ -184,7 +184,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
|
||||||
let text = if br.has_name() {
|
let text = if br.has_name() {
|
||||||
format!("the lifetime `{}` as defined here", br.name)
|
format!("the lifetime `{}` as defined here", br.name)
|
||||||
} else {
|
} else {
|
||||||
format!("the anonymous lifetime as defined here")
|
"the anonymous lifetime as defined here".to_string()
|
||||||
};
|
};
|
||||||
(text, sp)
|
(text, sp)
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
|
||||||
sp = param.span;
|
sp = param.span;
|
||||||
}
|
}
|
||||||
let text = if name == kw::UnderscoreLifetime {
|
let text = if name == kw::UnderscoreLifetime {
|
||||||
format!("the anonymous lifetime as defined here")
|
"the anonymous lifetime as defined here".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("the lifetime `{}` as defined here", name)
|
format!("the lifetime `{}` as defined here", name)
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => {
|
(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(
|
err.span_note(
|
||||||
sup_span,
|
sup_span,
|
||||||
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
|
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
|
||||||
|
@ -55,17 +55,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
sub_span,
|
sub_span,
|
||||||
format!("the lifetime `{sub_symbol}` defined here..."),
|
format!("the lifetime `{sub_symbol}` defined here..."),
|
||||||
);
|
);
|
||||||
err.span_note(
|
err.span_note(sup_span, "...must outlive the lifetime defined here");
|
||||||
sup_span,
|
|
||||||
format!("...must outlive the lifetime defined here"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
(Some(sub_span), Some(sup_span), _, _) => {
|
(Some(sub_span), Some(sup_span), _, _) => {
|
||||||
err.span_note(sub_span, format!("the lifetime defined here..."));
|
err.span_note(sub_span, "the lifetime defined here...");
|
||||||
err.span_note(
|
err.span_note(sup_span, "...must outlive the lifetime defined here");
|
||||||
sup_span,
|
|
||||||
format!("...must outlive the lifetime defined here"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,11 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
lint.multipart_suggestion_verbose(
|
lint.multipart_suggestion_verbose(
|
||||||
format!("to check pattern in a loop use `while let`"),
|
"to check pattern in a loop use `while let`",
|
||||||
vec![
|
vec![
|
||||||
// NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts
|
// 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}(")),
|
(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
|
Applicability::MaybeIncorrect
|
||||||
);
|
);
|
||||||
|
@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
|
||||||
vec![
|
vec![
|
||||||
// NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts
|
// 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}(")),
|
(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,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
|
|
|
@ -39,10 +39,8 @@ impl<'a> DiagnosticDerive<'a> {
|
||||||
let init = match builder.slug.value_ref() {
|
let init = match builder.slug.value_ref() {
|
||||||
None => {
|
None => {
|
||||||
span_err(builder.span, "diagnostic slug not specified")
|
span_err(builder.span, "diagnostic slug not specified")
|
||||||
.help(format!(
|
.help("specify the slug as the first argument to the `#[diag(...)]` \
|
||||||
"specify the slug as the first argument to the `#[diag(...)]` \
|
attribute, such as `#[diag(hir_analysis_example_error)]`")
|
||||||
attribute, such as `#[diag(hir_analysis_example_error)]`",
|
|
||||||
))
|
|
||||||
.emit();
|
.emit();
|
||||||
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
|
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
|
||||||
}
|
}
|
||||||
|
@ -133,10 +131,8 @@ impl<'a> LintDiagnosticDerive<'a> {
|
||||||
match builder.slug.value_ref() {
|
match builder.slug.value_ref() {
|
||||||
None => {
|
None => {
|
||||||
span_err(builder.span, "diagnostic slug not specified")
|
span_err(builder.span, "diagnostic slug not specified")
|
||||||
.help(format!(
|
.help("specify the slug as the first argument to the attribute, such as \
|
||||||
"specify the slug as the first argument to the attribute, such as \
|
`#[diag(compiletest_example)]`")
|
||||||
`#[diag(compiletest_example)]`",
|
|
||||||
))
|
|
||||||
.emit();
|
.emit();
|
||||||
DiagnosticDeriveError::ErrorHandled.to_compile_error()
|
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`.
|
// FIXME: this is a poor version of `pretty_print_const_value`.
|
||||||
let fmt_val = |val: &ConstValue<'tcx>| match val {
|
let fmt_val = |val: &ConstValue<'tcx>| match val {
|
||||||
ConstValue::ZeroSized => format!("<ZST>"),
|
ConstValue::ZeroSized => "<ZST>".to_string(),
|
||||||
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
|
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
|
||||||
ConstValue::Slice { .. } => format!("Slice(..)"),
|
ConstValue::Slice { .. } => "Slice(..)".to_string(),
|
||||||
ConstValue::ByRef { .. } => format!("ByRef(..)"),
|
ConstValue::ByRef { .. } => "ByRef(..)".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree {
|
let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree {
|
||||||
ty::ValTree::Leaf(leaf) => format!("ValTree::Leaf({:?})", leaf),
|
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 {
|
let val = match literal {
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
||||||
let Some((otherwise, rest)) = arms.split_last() else {
|
let Some((otherwise, rest)) = arms.split_last() else {
|
||||||
return Err(ParseError {
|
return Err(ParseError {
|
||||||
span,
|
span,
|
||||||
item_description: format!("no arms"),
|
item_description: "no arms".to_string(),
|
||||||
expected: "at least one arm".to_string(),
|
expected: "at least one arm".to_string(),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
|
@ -277,11 +277,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
let override_suggestion =
|
let override_suggestion =
|
||||||
if ["true", "false"].contains(&item_str.to_string().to_lowercase().as_str()) {
|
if ["true", "false"].contains(&item_str.to_string().to_lowercase().as_str()) {
|
||||||
let item_typo = item_str.to_string().to_lowercase();
|
let item_typo = item_str.to_string().to_lowercase();
|
||||||
Some((
|
Some((item_span, "you may want to use a bool value instead", item_typo))
|
||||||
item_span,
|
|
||||||
"you may want to use a bool value instead",
|
|
||||||
format!("{}", item_typo),
|
|
||||||
))
|
|
||||||
// FIXME(vincenzopalazzo): make the check smarter,
|
// FIXME(vincenzopalazzo): make the check smarter,
|
||||||
// and maybe expand with levenshtein distance checks
|
// and maybe expand with levenshtein distance checks
|
||||||
} else if item_str.as_str() == "printf" {
|
} 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);
|
let message = format!("consider introducing lifetime `{}` here", name);
|
||||||
should_continue = suggest(err, false, span, &message, sugg);
|
should_continue = suggest(err, false, span, &message, sugg);
|
||||||
} else {
|
} 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);
|
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() {
|
} else if uv.has_non_region_param() {
|
||||||
NotConstEvaluatable::MentionsParam
|
NotConstEvaluatable::MentionsParam
|
||||||
} else {
|
} else {
|
||||||
let guar = infcx.tcx.sess.delay_span_bug(
|
let guar = infcx
|
||||||
span,
|
.tcx
|
||||||
format!("Missing value for constant, but no error reported?"),
|
.sess
|
||||||
);
|
.delay_span_bug(span, "Missing value for constant, but no error reported?");
|
||||||
NotConstEvaluatable::Error(guar)
|
NotConstEvaluatable::Error(guar)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2332,9 +2332,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
// get rid of :: between Trait and <type>
|
// get rid of :: between Trait and <type>
|
||||||
// must be '::' between them, otherwise the parser won't accept the code
|
// must be '::' between them, otherwise the parser won't accept the code
|
||||||
suggestions.push((between_span, "".to_string(),));
|
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 {
|
} 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(
|
err.multipart_suggestion(
|
||||||
message,
|
message,
|
||||||
|
|
|
@ -2740,7 +2740,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
ty::Closure(def_id, _) => err.span_note(
|
ty::Closure(def_id, _) => err.span_note(
|
||||||
self.tcx.def_span(def_id),
|
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),
|
_ => err.note(&msg),
|
||||||
};
|
};
|
||||||
|
@ -3386,7 +3386,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
err.span_note(
|
err.span_note(
|
||||||
multi_span,
|
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…
Add table
Add a link
Reference in a new issue