Restrict From<S>
for {D,Subd}iagnosticMessage
.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
This commit is contained in:
parent
a368898de7
commit
6b62f37402
177 changed files with 791 additions and 787 deletions
|
@ -243,13 +243,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let note = format!("{title} is defined in an impl for the type `{impl_ty}`");
|
||||
|
||||
if let Some(span) = note_span {
|
||||
err.span_note(span, ¬e);
|
||||
err.span_note(span, note);
|
||||
} else {
|
||||
err.note(¬e);
|
||||
err.note(note);
|
||||
}
|
||||
}
|
||||
if candidates.len() > limit {
|
||||
err.note(&format!("and {} others", candidates.len() - limit));
|
||||
err.note(format!("and {} others", candidates.len() - limit));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
"associated type `{name}` not found for `{self_ty}` in the current scope"
|
||||
);
|
||||
err.span_label(name.span, format!("associated item not found in `{self_ty}`"));
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"the associated type was found for\n{type_candidates}{additional_types}",
|
||||
));
|
||||
add_def_label(&mut err);
|
||||
|
@ -390,10 +390,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
let mut err = tcx.sess.struct_span_err(
|
||||
name.span,
|
||||
&format!("the associated type `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied")
|
||||
format!("the associated type `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied")
|
||||
);
|
||||
if !bounds.is_empty() {
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"the following trait bounds were not satisfied:\n{}",
|
||||
bounds.join("\n")
|
||||
));
|
||||
|
@ -409,7 +409,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
if !tcx.sess.source_map().is_span_accessible(span) {
|
||||
continue;
|
||||
}
|
||||
err.span_label(span, &msg);
|
||||
err.span_label(span, msg);
|
||||
}
|
||||
add_def_label(&mut err);
|
||||
err.emit()
|
||||
|
@ -589,7 +589,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}
|
||||
if !suggestions.is_empty() {
|
||||
err.multipart_suggestion(
|
||||
&format!("specify the associated type{}", pluralize!(types_count)),
|
||||
format!("specify the associated type{}", pluralize!(types_count)),
|
||||
suggestions,
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
|
|
|
@ -112,7 +112,7 @@ fn generic_arg_mismatch_err(
|
|||
if let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = body.value.kind
|
||||
{
|
||||
if let Res::Def(DefKind::Fn { .. }, id) = path.res {
|
||||
err.help(&format!("`{}` is a function item, not a type", tcx.item_name(id)));
|
||||
err.help(format!("`{}` is a function item, not a type", tcx.item_name(id)));
|
||||
err.help("function item types cannot be named directly");
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ fn generic_arg_mismatch_err(
|
|||
} else {
|
||||
(arg.descr(), param.kind.descr())
|
||||
};
|
||||
err.note(&format!("{} arguments must be provided before {} arguments", first, last));
|
||||
err.note(format!("{} arguments must be provided before {} arguments", first, last));
|
||||
if let Some(help) = help {
|
||||
err.help(help);
|
||||
}
|
||||
|
|
|
@ -1168,9 +1168,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
tcx.sess
|
||||
.struct_span_err(
|
||||
binding.span,
|
||||
&format!("{} `{}` is private", assoc_item.kind, binding.item_name),
|
||||
format!("{} `{}` is private", assoc_item.kind, binding.item_name),
|
||||
)
|
||||
.span_label(binding.span, &format!("private {}", assoc_item.kind))
|
||||
.span_label(binding.span, format!("private {}", assoc_item.kind))
|
||||
.emit();
|
||||
}
|
||||
tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None);
|
||||
|
@ -1342,11 +1342,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let expected = tcx.def_descr(assoc_item_def_id);
|
||||
let mut err = tcx.sess.struct_span_err(
|
||||
binding.span,
|
||||
&format!("expected {expected} bound, found {got}"),
|
||||
format!("expected {expected} bound, found {got}"),
|
||||
);
|
||||
err.span_note(
|
||||
tcx.def_span(assoc_item_def_id),
|
||||
&format!("{expected} defined here"),
|
||||
format!("{expected} defined here"),
|
||||
);
|
||||
|
||||
if let hir::def::DefKind::AssocConst = def_kind
|
||||
|
@ -1508,7 +1508,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
"additional use",
|
||||
);
|
||||
first_trait.label_with_exp_info(&mut err, "first non-auto trait", "first use");
|
||||
err.help(&format!(
|
||||
err.help(format!(
|
||||
"consider creating a new trait with all of these as supertraits and using that \
|
||||
trait here instead: `trait NewTrait: {} {{}}`",
|
||||
regular_traits
|
||||
|
@ -1818,7 +1818,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
([], []) => {
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"if there were a type named `Type` that implements a trait named \
|
||||
`Trait` with associated type `{name}`, you could use the \
|
||||
fully-qualified path",
|
||||
|
@ -1830,7 +1830,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
([], [trait_str]) => {
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"if there were a type named `Example` that implemented `{trait_str}`, \
|
||||
you could use the fully-qualified path",
|
||||
),
|
||||
|
@ -1841,7 +1841,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
([], traits) => {
|
||||
err.span_suggestions(
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"if there were a type named `Example` that implemented one of the \
|
||||
traits with associated type `{name}`, you could use the \
|
||||
fully-qualified path",
|
||||
|
@ -1856,7 +1856,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
([type_str], []) => {
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"if there were a trait named `Example` with associated type `{name}` \
|
||||
implemented for `{type_str}`, you could use the fully-qualified path",
|
||||
),
|
||||
|
@ -1867,7 +1867,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
(types, []) => {
|
||||
err.span_suggestions(
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"if there were a trait named `Example` with associated type `{name}` \
|
||||
implemented for one of the types, you could use the fully-qualified \
|
||||
path",
|
||||
|
@ -2033,7 +2033,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"associated type `{}` could derive from `{}`",
|
||||
ty_param_name,
|
||||
bound.print_only_trait_path(),
|
||||
|
@ -2041,7 +2041,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}
|
||||
}
|
||||
if !where_bounds.is_empty() {
|
||||
err.help(&format!(
|
||||
err.help(format!(
|
||||
"consider introducing a new type parameter `T` and adding `where` constraints:\
|
||||
\n where\n T: {},\n{}",
|
||||
ty_param_name,
|
||||
|
@ -2109,14 +2109,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// work for the `enum`, instead of just looking if it takes *any*.
|
||||
err.span_suggestion_verbose(
|
||||
args_span,
|
||||
&format!("{type_name} doesn't have generic parameters"),
|
||||
format!("{type_name} doesn't have generic parameters"),
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
return;
|
||||
}
|
||||
let Ok(snippet) = tcx.sess.source_map().span_to_snippet(args_span) else {
|
||||
err.note(&msg);
|
||||
err.note(msg);
|
||||
return;
|
||||
};
|
||||
let (qself_sugg_span, is_self) = if let hir::TyKind::Path(
|
||||
|
@ -2150,12 +2150,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
kw::SelfUpper == segment.ident.name,
|
||||
),
|
||||
_ => {
|
||||
err.note(&msg);
|
||||
err.note(msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err.note(&msg);
|
||||
err.note(msg);
|
||||
return;
|
||||
};
|
||||
let suggestion = vec![
|
||||
|
@ -2170,7 +2170,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
(args_span, String::new()),
|
||||
];
|
||||
err.multipart_suggestion_verbose(
|
||||
&msg,
|
||||
msg,
|
||||
suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -2222,7 +2222,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let reported = if variant_resolution.is_some() {
|
||||
// Variant in type position
|
||||
let msg = format!("expected type, found variant `{}`", assoc_ident);
|
||||
tcx.sess.span_err(span, &msg)
|
||||
tcx.sess.span_err(span, msg)
|
||||
} else if qself_ty.is_enum() {
|
||||
let mut err = struct_span_err!(
|
||||
tcx.sess,
|
||||
|
@ -2293,7 +2293,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// Assume that if it's not matched, there must be a const defined with the same name
|
||||
// but it was used in a type position.
|
||||
let msg = format!("found associated const `{assoc_ident}` when type was expected");
|
||||
let guar = tcx.sess.struct_span_err(span, &msg).emit();
|
||||
let guar = tcx.sess.struct_span_err(span, msg).emit();
|
||||
return Err(guar);
|
||||
};
|
||||
|
||||
|
@ -2313,7 +2313,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
also,
|
||||
tcx.def_kind_descr(kind, def_id)
|
||||
);
|
||||
lint.span_note(tcx.def_span(def_id), ¬e_msg);
|
||||
lint.span_note(tcx.def_span(def_id), note_msg);
|
||||
};
|
||||
|
||||
could_refer_to(DefKind::Variant, variant_def_id, "");
|
||||
|
@ -2510,9 +2510,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let msg = format!("{kind} `{name}` is private");
|
||||
let def_span = tcx.def_span(item);
|
||||
tcx.sess
|
||||
.struct_span_err_with_code(span, &msg, rustc_errors::error_code!(E0624))
|
||||
.span_label(span, &format!("private {kind}"))
|
||||
.span_label(def_span, &format!("{kind} defined here"))
|
||||
.struct_span_err_with_code(span, msg, rustc_errors::error_code!(E0624))
|
||||
.span_label(span, format!("private {kind}"))
|
||||
.span_label(def_span, format!("{kind} defined here"))
|
||||
.emit();
|
||||
}
|
||||
tcx.check_stability(item, Some(block), span, None);
|
||||
|
@ -2960,7 +2960,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
self.prohibit_generics(path.segments.iter(), |err| {
|
||||
if let Some(span) = tcx.def_ident_span(def_id) {
|
||||
let name = tcx.item_name(def_id);
|
||||
err.span_note(span, &format!("type parameter `{name}` defined here"));
|
||||
err.span_note(span, format!("type parameter `{name}` defined here"));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3021,7 +3021,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let mut span: MultiSpan = vec![t_sp].into();
|
||||
span.push_span_label(
|
||||
i_sp,
|
||||
&format!("`Self` is on type `{type_name}` in this `impl`"),
|
||||
format!("`Self` is on type `{type_name}` in this `impl`"),
|
||||
);
|
||||
let mut postfix = "";
|
||||
if generics == 0 {
|
||||
|
@ -3029,11 +3029,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}
|
||||
span.push_span_label(
|
||||
t_sp,
|
||||
&format!("`Self` corresponds to this type{postfix}"),
|
||||
format!("`Self` corresponds to this type{postfix}"),
|
||||
);
|
||||
err.span_note(span, &msg);
|
||||
err.span_note(span, msg);
|
||||
} else {
|
||||
err.note(&msg);
|
||||
err.note(msg);
|
||||
}
|
||||
for segment in path.segments {
|
||||
if let Some(args) = segment.args && segment.ident.name == kw::SelfUpper {
|
||||
|
@ -3124,7 +3124,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
if let Some(args) = segment.args {
|
||||
err.span_suggestion_verbose(
|
||||
segment.ident.span.shrink_to_hi().to(args.span_ext),
|
||||
&format!("primitive type `{name}` doesn't have generic parameters"),
|
||||
format!("primitive type `{name}` doesn't have generic parameters"),
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -3415,7 +3415,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
if !infer_replacements.is_empty() {
|
||||
diag.multipart_suggestion(
|
||||
&format!(
|
||||
format!(
|
||||
"try replacing `_` with the type{} in the corresponding trait method signature",
|
||||
rustc_errors::pluralize!(infer_replacements.len()),
|
||||
),
|
||||
|
|
|
@ -175,7 +175,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
}
|
||||
// Generic statics are rejected, but we still reach this case.
|
||||
Err(e) => {
|
||||
tcx.sess.delay_span_bug(span, &e.to_string());
|
||||
tcx.sess.delay_span_bug(span, e.to_string());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -334,7 +334,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
|
|||
&tcx.sess.parse_sess,
|
||||
sym::impl_trait_projections,
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"`{}` return type cannot contain a projection or `Self` that references \
|
||||
lifetimes from a parent scope",
|
||||
if is_async { "async fn" } else { "impl Trait" },
|
||||
|
@ -428,7 +428,7 @@ fn check_opaque_meets_bounds<'tcx>(
|
|||
let ty_err = ty_err.to_string(tcx);
|
||||
tcx.sess.delay_span_bug(
|
||||
span,
|
||||
&format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
|
||||
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -618,11 +618,11 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
E0044,
|
||||
"foreign items may not have {kinds} parameters",
|
||||
)
|
||||
.span_label(item.span, &format!("can't have {kinds} parameters"))
|
||||
.span_label(item.span, format!("can't have {kinds} parameters"))
|
||||
.help(
|
||||
// FIXME: once we start storing spans for type arguments, turn this
|
||||
// into a suggestion.
|
||||
&format!(
|
||||
format!(
|
||||
"replace the {} parameters with concrete {}{}",
|
||||
kinds,
|
||||
kinds_pl,
|
||||
|
@ -985,10 +985,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
|
|||
|
||||
err.span_note(
|
||||
tcx.def_span(def_spans[0].0),
|
||||
&format!(
|
||||
"`{}` has a `#[repr(align)]` attribute",
|
||||
tcx.item_name(def_spans[0].0)
|
||||
),
|
||||
format!("`{}` has a `#[repr(align)]` attribute", tcx.item_name(def_spans[0].0)),
|
||||
);
|
||||
|
||||
if def_spans.len() > 2 {
|
||||
|
@ -997,7 +994,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
|
|||
let ident = tcx.item_name(*adt_def);
|
||||
err.span_note(
|
||||
*span,
|
||||
&if first {
|
||||
if first {
|
||||
format!(
|
||||
"`{}` contains a field of type `{}`",
|
||||
tcx.type_of(def.did()).subst_identity(),
|
||||
|
@ -1466,10 +1463,10 @@ fn opaque_type_cycle_error(
|
|||
let ty_span = tcx.def_span(def_id);
|
||||
if !seen.contains(&ty_span) {
|
||||
let descr = if ty.is_impl_trait() { "opaque " } else { "" };
|
||||
err.span_label(ty_span, &format!("returning this {descr}type `{ty}`"));
|
||||
err.span_label(ty_span, format!("returning this {descr}type `{ty}`"));
|
||||
seen.insert(ty_span);
|
||||
}
|
||||
err.span_label(sp, &format!("returning here with type `{ty}`"));
|
||||
err.span_label(sp, format!("returning here with type `{ty}`"));
|
||||
}
|
||||
|
||||
for closure_def_id in visitor.closures {
|
||||
|
|
|
@ -1273,7 +1273,7 @@ fn compare_number_of_generics<'tcx>(
|
|||
|
||||
let mut err = tcx.sess.struct_span_err_with_code(
|
||||
spans,
|
||||
&format!(
|
||||
format!(
|
||||
"{} `{}` has {} {kind} parameter{} but its trait \
|
||||
declaration has {} {kind} parameter{}",
|
||||
item_kind,
|
||||
|
|
|
@ -52,7 +52,7 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro
|
|||
let span = tcx.def_span(drop_impl_did);
|
||||
let reported = tcx.sess.delay_span_bug(
|
||||
span,
|
||||
&format!("should have been rejected by coherence check: {dtor_self_type}"),
|
||||
format!("should have been rejected by coherence check: {dtor_self_type}"),
|
||||
);
|
||||
Err(reported)
|
||||
}
|
||||
|
@ -76,15 +76,15 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
|
|||
struct_span_err!(tcx.sess, drop_impl_span, E0366, "`Drop` impls cannot be specialized");
|
||||
match arg {
|
||||
ty::util::NotUniqueParam::DuplicateParam(arg) => {
|
||||
err.note(&format!("`{arg}` is mentioned multiple times"))
|
||||
err.note(format!("`{arg}` is mentioned multiple times"))
|
||||
}
|
||||
ty::util::NotUniqueParam::NotParam(arg) => {
|
||||
err.note(&format!("`{arg}` is not a generic parameter"))
|
||||
err.note(format!("`{arg}` is not a generic parameter"))
|
||||
}
|
||||
};
|
||||
err.span_note(
|
||||
item_span,
|
||||
&format!(
|
||||
format!(
|
||||
"use the same sequence of generic lifetime, type and const parameters \
|
||||
as the {self_descr} definition",
|
||||
),
|
||||
|
|
|
@ -547,14 +547,14 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
|
|||
Err(_) => {
|
||||
let msg =
|
||||
format!("unrecognized platform-specific intrinsic function: `{name}`");
|
||||
tcx.sess.struct_span_err(it.span, &msg).emit();
|
||||
tcx.sess.struct_span_err(it.span, msg).emit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let msg = format!("unrecognized platform-specific intrinsic function: `{name}`");
|
||||
tcx.sess.struct_span_err(it.span, &msg).emit();
|
||||
tcx.sess.struct_span_err(it.span, msg).emit();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -130,7 +130,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
_ => None,
|
||||
};
|
||||
let Some(asm_ty) = asm_ty else {
|
||||
let msg = &format!("cannot use value of type `{ty}` for inline assembly");
|
||||
let msg = format!("cannot use value of type `{ty}` for inline assembly");
|
||||
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
|
||||
err.note(
|
||||
"only integers, floats, SIMD vectors, pointers and function pointers \
|
||||
|
@ -145,7 +145,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
if !ty.is_copy_modulo_regions(self.tcx, self.param_env) {
|
||||
let msg = "arguments for inline assembly must be copyable";
|
||||
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
|
||||
err.note(&format!("`{ty}` does not implement the Copy trait"));
|
||||
err.note(format!("`{ty}` does not implement the Copy trait"));
|
||||
err.emit();
|
||||
}
|
||||
|
||||
|
@ -164,8 +164,8 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
let mut err = self.tcx.sess.struct_span_err(vec![in_expr.span, expr.span], msg);
|
||||
|
||||
let in_expr_ty = (self.get_operand_ty)(in_expr);
|
||||
err.span_label(in_expr.span, &format!("type `{in_expr_ty}`"));
|
||||
err.span_label(expr.span, &format!("type `{ty}`"));
|
||||
err.span_label(in_expr.span, format!("type `{in_expr_ty}`"));
|
||||
err.span_label(expr.span, format!("type `{ty}`"));
|
||||
err.note(
|
||||
"asm inout arguments must have the same type, \
|
||||
unless they are both pointers or integers of the same size",
|
||||
|
@ -184,17 +184,17 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
let reg_class = reg.reg_class();
|
||||
let supported_tys = reg_class.supported_types(asm_arch);
|
||||
let Some((_, feature)) = supported_tys.iter().find(|&&(t, _)| t == asm_ty) else {
|
||||
let msg = &format!("type `{ty}` cannot be used with this register class");
|
||||
let msg = format!("type `{ty}` cannot be used with this register class");
|
||||
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
|
||||
let supported_tys: Vec<_> =
|
||||
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"register class `{}` supports these types: {}",
|
||||
reg_class.name(),
|
||||
supported_tys.join(", "),
|
||||
));
|
||||
if let Some(suggest) = reg_class.suggest_class(asm_arch, asm_ty) {
|
||||
err.help(&format!(
|
||||
err.help(format!(
|
||||
"consider using the `{}` register class instead",
|
||||
suggest.name()
|
||||
));
|
||||
|
@ -215,9 +215,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
// register class is usable at all.
|
||||
if let Some(feature) = feature {
|
||||
if !target_features.contains(feature) {
|
||||
let msg = &format!("`{}` target feature is not enabled", feature);
|
||||
let msg = format!("`{}` target feature is not enabled", feature);
|
||||
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"this is required to use type `{}` with register class `{}`",
|
||||
ty,
|
||||
reg_class.name(),
|
||||
|
@ -252,10 +252,10 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
"formatting may not be suitable for sub-register argument",
|
||||
|lint| {
|
||||
lint.span_label(expr.span, "for this argument");
|
||||
lint.help(&format!(
|
||||
lint.help(format!(
|
||||
"use `{{{idx}:{suggested_modifier}}}` to have the register formatted as `{suggested_result}`",
|
||||
));
|
||||
lint.help(&format!(
|
||||
lint.help(format!(
|
||||
"or use `{{{idx}:{default_modifier}}}` to keep the default formatting of `{default_result}`",
|
||||
));
|
||||
lint
|
||||
|
@ -301,7 +301,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
op.is_clobber(),
|
||||
) {
|
||||
let msg = format!("cannot use register `{}`: {}", reg.name(), msg);
|
||||
self.tcx.sess.struct_span_err(*op_sp, &msg).emit();
|
||||
self.tcx.sess.struct_span_err(*op_sp, msg).emit();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
reg_class.name(),
|
||||
feature
|
||||
);
|
||||
self.tcx.sess.struct_span_err(*op_sp, &msg).emit();
|
||||
self.tcx.sess.struct_span_err(*op_sp, msg).emit();
|
||||
// register isn't enabled, don't do more checks
|
||||
continue;
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
.intersperse(", ")
|
||||
.collect::<String>(),
|
||||
);
|
||||
self.tcx.sess.struct_span_err(*op_sp, &msg).emit();
|
||||
self.tcx.sess.struct_span_err(*op_sp, msg).emit();
|
||||
// register isn't enabled, don't do more checks
|
||||
continue;
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
self.tcx.sess.struct_span_err(*op_sp, "invalid `sym` operand");
|
||||
err.span_label(
|
||||
self.tcx.def_span(anon_const.def_id),
|
||||
&format!("is {} `{}`", ty.kind().article(), ty),
|
||||
format!("is {} `{}`", ty.kind().article(), ty),
|
||||
);
|
||||
err.help("`sym` operands must refer to either a function or a static");
|
||||
err.emit();
|
||||
|
|
|
@ -445,7 +445,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
let plural = pluralize!(unsatisfied_bounds.len());
|
||||
let mut err = tcx.sess.struct_span_err(
|
||||
gat_item_hir.span,
|
||||
&format!("missing required bound{} on `{}`", plural, gat_item_hir.ident),
|
||||
format!("missing required bound{} on `{}`", plural, gat_item_hir.ident),
|
||||
);
|
||||
|
||||
let suggestion = format!(
|
||||
|
@ -455,14 +455,14 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
);
|
||||
err.span_suggestion(
|
||||
gat_item_hir.generics.tail_span_for_predicate_suggestion(),
|
||||
&format!("add the required where clause{plural}"),
|
||||
format!("add the required where clause{plural}"),
|
||||
suggestion,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
||||
let bound =
|
||||
if unsatisfied_bounds.len() > 1 { "these bounds are" } else { "this bound is" };
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"{} currently required to ensure that impls have maximum flexibility",
|
||||
bound
|
||||
));
|
||||
|
@ -916,14 +916,14 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
|||
if is_ptr {
|
||||
tcx.sess.span_err(
|
||||
hir_ty.span,
|
||||
&format!(
|
||||
format!(
|
||||
"using {unsupported_type} as const generic parameters is forbidden",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
let mut err = tcx.sess.struct_span_err(
|
||||
hir_ty.span,
|
||||
&format!(
|
||||
format!(
|
||||
"{unsupported_type} is forbidden as the type of a const generic parameter",
|
||||
),
|
||||
);
|
||||
|
@ -1029,7 +1029,7 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
|
|||
let ty = tcx.erase_regions(ty);
|
||||
if ty.has_infer() {
|
||||
tcx.sess
|
||||
.delay_span_bug(item.span, &format!("inference variables in {:?}", ty));
|
||||
.delay_span_bug(item.span, format!("inference variables in {:?}", ty));
|
||||
// Just treat unresolved type expression as if it needs drop.
|
||||
true
|
||||
} else {
|
||||
|
@ -1651,7 +1651,7 @@ fn check_method_receiver<'tcx>(
|
|||
&tcx.sess.parse_sess,
|
||||
sym::arbitrary_self_types,
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"`{receiver_ty}` cannot be used as the type of `self` without \
|
||||
the `arbitrary_self_types` feature",
|
||||
),
|
||||
|
@ -1874,10 +1874,10 @@ fn report_bivariance(
|
|||
} else {
|
||||
format!("consider removing `{param_name}` or referring to it in a field")
|
||||
};
|
||||
err.help(&msg);
|
||||
err.help(msg);
|
||||
|
||||
if matches!(param.kind, hir::GenericParamKind::Type { .. }) && !has_explicit_bounds {
|
||||
err.help(&format!(
|
||||
err.help(format!(
|
||||
"if you intended `{0}` to be a const parameter, use `const {0}: usize` instead",
|
||||
param_name
|
||||
));
|
||||
|
|
|
@ -213,7 +213,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
|||
for structs containing the field being coerced, \
|
||||
ZST fields with 1 byte alignment, and nothing else",
|
||||
)
|
||||
.note(&format!(
|
||||
.note(format!(
|
||||
"extra field `{}` of type `{}` is not allowed",
|
||||
field.name, ty_a,
|
||||
))
|
||||
|
@ -241,7 +241,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
|||
for a coercion between structures with a single field \
|
||||
being coerced",
|
||||
)
|
||||
.note(&format!(
|
||||
.note(format!(
|
||||
"currently, {} fields need coercions: {}",
|
||||
coerced_fields.len(),
|
||||
coerced_fields
|
||||
|
@ -298,7 +298,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
|
|||
let coerce_unsized_trait = tcx.require_lang_item(LangItem::CoerceUnsized, Some(span));
|
||||
|
||||
let unsize_trait = tcx.lang_items().require(LangItem::Unsize).unwrap_or_else(|err| {
|
||||
tcx.sess.fatal(&format!("`CoerceUnsized` implementation {}", err.to_string()));
|
||||
tcx.sess.fatal(format!("`CoerceUnsized` implementation {}", err.to_string()));
|
||||
});
|
||||
|
||||
let source = tcx.type_of(impl_did).subst_identity();
|
||||
|
@ -469,7 +469,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
|
|||
"`CoerceUnsized` may only be implemented for \
|
||||
a coercion between structures with one field being coerced",
|
||||
)
|
||||
.note(&format!(
|
||||
.note(format!(
|
||||
"currently, {} fields need coercions: {}",
|
||||
diff_fields.len(),
|
||||
diff_fields
|
||||
|
|
|
@ -146,7 +146,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
);
|
||||
err.help("consider using an extension trait instead");
|
||||
if let ty::Ref(_, subty, _) = ty.kind() {
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"you could also try moving the reference to \
|
||||
uses of `{}` (such as `self`) within the implementation",
|
||||
subty
|
||||
|
|
|
@ -372,10 +372,10 @@ fn emit_orphan_check_error<'tcx>(
|
|||
|
||||
if is_target_ty {
|
||||
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
|
||||
err.span_label(self_ty_span, &msg);
|
||||
err.span_label(self_ty_span, msg);
|
||||
} else {
|
||||
// Point at `C<B>` in `impl<A, B> for C<B> in D<A>`
|
||||
err.span_label(trait_span, &msg);
|
||||
err.span_label(trait_span, msg);
|
||||
}
|
||||
}
|
||||
err.note("define and implement a trait or new type instead");
|
||||
|
@ -531,15 +531,15 @@ fn lint_auto_trait_impl<'tcx>(
|
|||
let self_descr = tcx.def_descr(self_type_did);
|
||||
match arg {
|
||||
ty::util::NotUniqueParam::DuplicateParam(arg) => {
|
||||
lint.note(&format!("`{}` is mentioned multiple times", arg));
|
||||
lint.note(format!("`{}` is mentioned multiple times", arg));
|
||||
}
|
||||
ty::util::NotUniqueParam::NotParam(arg) => {
|
||||
lint.note(&format!("`{}` is not a generic parameter", arg));
|
||||
lint.note(format!("`{}` is not a generic parameter", arg));
|
||||
}
|
||||
}
|
||||
lint.span_note(
|
||||
item_span,
|
||||
&format!(
|
||||
format!(
|
||||
"try using the same sequence of generic parameters as the {} definition",
|
||||
self_descr,
|
||||
),
|
||||
|
|
|
@ -987,7 +987,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
lifetime.ident
|
||||
),
|
||||
|lint| {
|
||||
let help = &format!(
|
||||
let help = format!(
|
||||
"you can use the `'static` lifetime directly, in place of `{}`",
|
||||
lifetime.ident,
|
||||
);
|
||||
|
@ -1365,7 +1365,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
|
||||
self.tcx.sess.delay_span_bug(
|
||||
lifetime_ref.ident.span,
|
||||
&format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
|
||||
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -828,14 +828,14 @@ fn infer_placeholder_type<'a>(
|
|||
if let Some(ty) = ty.make_suggestable(tcx, false) {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&format!("provide a type for the {item}", item = kind),
|
||||
format!("provide a type for the {item}", item = kind),
|
||||
format!("{colon} {ty}"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else {
|
||||
with_forced_trimmed_paths!(err.span_note(
|
||||
tcx.hir().body(body_id).value.span,
|
||||
&format!("however, the inferred type `{ty}` cannot be named"),
|
||||
format!("however, the inferred type `{ty}` cannot be named"),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -856,7 +856,7 @@ fn infer_placeholder_type<'a>(
|
|||
} else {
|
||||
with_forced_trimmed_paths!(diag.span_note(
|
||||
tcx.hir().body(body_id).value.span,
|
||||
&format!("however, the inferred type `{ty}` cannot be named"),
|
||||
format!("however, the inferred type `{ty}` cannot be named"),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
|||
// (#36836)
|
||||
tcx.sess.delay_span_bug(
|
||||
tcx.def_span(impl_def_id),
|
||||
&format!(
|
||||
format!(
|
||||
"potentially unconstrained type parameters weren't evaluated: {:?}",
|
||||
impl_self_ty,
|
||||
),
|
||||
|
|
|
@ -272,7 +272,7 @@ fn check_duplicate_params<'tcx>(
|
|||
if let (_, [duplicate, ..]) = base_params.partition_dedup() {
|
||||
let param = impl1_substs[duplicate.0 as usize];
|
||||
tcx.sess
|
||||
.struct_span_err(span, &format!("specializing impl repeats parameter `{}`", param))
|
||||
.struct_span_err(span, format!("specializing impl repeats parameter `{}`", param))
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
@ -464,7 +464,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
|||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
&format!(
|
||||
format!(
|
||||
"cannot specialize on trait `{}`",
|
||||
tcx.def_path_str(trait_ref.def_id),
|
||||
),
|
||||
|
@ -479,7 +479,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
|||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
&format!("cannot specialize on associated type `{projection_ty} == {term}`",),
|
||||
format!("cannot specialize on associated type `{projection_ty} == {term}`",),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
|||
}
|
||||
_ => {
|
||||
tcx.sess
|
||||
.struct_span_err(span, &format!("cannot specialize on predicate `{}`", predicate))
|
||||
.struct_span_err(span, format!("cannot specialize on predicate `{}`", predicate))
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau
|
|||
|
||||
let span = tcx.def_span(item_def_id);
|
||||
let mut err = tcx.sess.struct_span_err(span, "rustc_outlives");
|
||||
for p in &pred {
|
||||
for p in pred {
|
||||
err.note(p);
|
||||
}
|
||||
err.emit();
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
|
|||
&self,
|
||||
mut err: DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
err.note(&format!(
|
||||
err.note(format!(
|
||||
"certain types, like `{}`, must be casted before passing them to a \
|
||||
variadic function, because of arcane ABI rules dictated by the C \
|
||||
standard",
|
||||
|
|
|
@ -480,7 +480,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
let span = self.path_segment.ident.span;
|
||||
let msg = self.create_error_message();
|
||||
|
||||
self.tcx.sess.struct_span_err_with_code(span, &msg, self.code())
|
||||
self.tcx.sess.struct_span_err_with_code(span, msg, self.code())
|
||||
}
|
||||
|
||||
/// Builds the `expected 1 type argument / supplied 2 type arguments` message.
|
||||
|
@ -602,7 +602,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
err.span_suggestion_verbose(
|
||||
span.shrink_to_hi(),
|
||||
&msg,
|
||||
msg,
|
||||
sugg,
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
|
@ -625,7 +625,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix);
|
||||
debug!("sugg: {:?}", sugg);
|
||||
|
||||
err.span_suggestion_verbose(sugg_span, &msg, sugg, Applicability::HasPlaceholders);
|
||||
err.span_suggestion_verbose(sugg_span, msg, sugg, Applicability::HasPlaceholders);
|
||||
}
|
||||
AngleBrackets::Implied => {
|
||||
// We never encounter missing lifetimes in situations in which lifetimes are elided
|
||||
|
@ -652,7 +652,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
err.span_suggestion_verbose(
|
||||
span.shrink_to_hi(),
|
||||
&msg,
|
||||
msg,
|
||||
sugg,
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
|
@ -683,7 +683,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix);
|
||||
debug!("sugg: {:?}", sugg);
|
||||
|
||||
err.span_suggestion_verbose(sugg_span, &msg, sugg, Applicability::HasPlaceholders);
|
||||
err.span_suggestion_verbose(sugg_span, msg, sugg, Applicability::HasPlaceholders);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -885,7 +885,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
err.span_suggestion(
|
||||
span_redundant_lt_args,
|
||||
&msg_lifetimes,
|
||||
msg_lifetimes,
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -927,7 +927,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
err.span_suggestion(
|
||||
span_redundant_type_or_const_args,
|
||||
&msg_types_or_consts,
|
||||
msg_types_or_consts,
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -943,7 +943,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
if !suggestions.is_empty() {
|
||||
err.multipart_suggestion_verbose(
|
||||
&format!(
|
||||
format!(
|
||||
"replace the generic bound{s} with the associated type{s}",
|
||||
s = pluralize!(unbound_types.len())
|
||||
),
|
||||
|
@ -969,7 +969,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
},
|
||||
);
|
||||
|
||||
err.span_suggestion(span, &msg, "", Applicability::MaybeIncorrect);
|
||||
err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
|
||||
} else if redundant_lifetime_args && redundant_type_or_const_args {
|
||||
remove_lifetime_args(err);
|
||||
remove_type_or_const_args(err);
|
||||
|
@ -1029,7 +1029,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
)
|
||||
};
|
||||
|
||||
err.span_note(spans, &msg);
|
||||
err.span_note(spans, msg);
|
||||
}
|
||||
|
||||
/// Add note if `impl Trait` is explicitly specified.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue