Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors

Cleanup error handlers: round 5

More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171.

r? ````@compiler-errors````
This commit is contained in:
Michael Goulet 2024-01-05 10:57:21 -05:00 committed by GitHub
commit f361b591ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 369 additions and 464 deletions

View file

@ -66,12 +66,9 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for NegativePositiveConflict<'_
) -> rustc_errors::DiagnosticBuilder<'_, G> {
let mut diag =
DiagnosticBuilder::new(dcx, level, fluent::trait_selection_negative_positive_conflict);
diag.set_arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
diag.set_arg(
"self_desc",
self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()),
);
diag.set_span(self.impl_span);
diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
diag.span(self.impl_span);
diag.code(rustc_errors::error_code!(E0751));
match self.negative_impl_span {
Ok(span) => {
@ -79,7 +76,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for NegativePositiveConflict<'_
}
Err(cname) => {
diag.note(fluent::trait_selection_negative_implementation_in_crate);
diag.set_arg("negative_impl_cname", cname.to_string());
diag.arg("negative_impl_cname", cname.to_string());
}
}
match self.positive_impl_span {
@ -88,7 +85,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for NegativePositiveConflict<'_
}
Err(cname) => {
diag.note(fluent::trait_selection_positive_implementation_in_crate);
diag.set_arg("positive_impl_cname", cname.to_string());
diag.arg("positive_impl_cname", cname.to_string());
}
}
diag
@ -115,7 +112,7 @@ impl AddToDiagnostic for AdjustSignatureBorrow {
{
match self {
AdjustSignatureBorrow::Borrow { to_borrow } => {
diag.set_arg("len", to_borrow.len());
diag.arg("len", to_borrow.len());
diag.multipart_suggestion_verbose(
fluent::trait_selection_adjust_signature_borrow,
to_borrow,
@ -123,7 +120,7 @@ impl AddToDiagnostic for AdjustSignatureBorrow {
);
}
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
diag.set_arg("len", remove_borrow.len());
diag.arg("len", remove_borrow.len());
diag.multipart_suggestion_verbose(
fluent::trait_selection_adjust_signature_remove_borrow,
remove_borrow,

View file

@ -2007,7 +2007,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
};
err.code(error_code!(E0746));
err.set_primary_message("return type cannot have an unboxed trait object");
err.primary_message("return type cannot have an unboxed trait object");
err.children.clear();
let span = obligation.cause.span;
@ -2712,7 +2712,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if name == sym::Send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
err.clear_code();
err.set_primary_message(format!(
err.primary_message(format!(
"{future_or_coroutine} cannot be {trait_verb} between threads safely"
));
@ -2800,7 +2800,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.unwrap_or_else(|| format!("{future_or_coroutine} is not {trait_name}"));
span.push_span_label(original_span, message);
err.set_span(span);
err.span(span);
format!("is not {trait_name}")
} else {

View file

@ -3163,14 +3163,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
) {
match obligation_cause_code {
ObligationCauseCode::RustCall => {
err.set_primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument");
err.primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument");
}
ObligationCauseCode::BindingObligation(def_id, _)
| ObligationCauseCode::ItemObligation(def_id)
if self.tcx.is_fn_trait(*def_id) =>
{
err.code(rustc_errors::error_code!(E0059));
err.set_primary_message(format!(
err.primary_message(format!(
"type parameter to bare `{}` trait must be a tuple",
self.tcx.def_path_str(*def_id)
));