Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate compiler/rustc_hir_typeck/src/callee.rs to translatable diagnostics #115862

Merged
merged 5 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate 'invalid callee' diagnostic
  • Loading branch information
clubby789 committed Sep 15, 2023
commit cb9f666fdf50bf80b71a54ccfcb7dfe4ad4c84d4
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ hir_typeck_functional_record_update_on_non_struct =

hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`

hir_typeck_invalid_callee = expected function, found {$ty}

hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
hir_typeck_lang_start_incorrect_number_params = incorrect number of parameters for the `start` lang item
hir_typeck_lang_start_incorrect_number_params_note_expected_count = the `start` lang item should have four parameters, but found {$found_param_count}

Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::method::MethodCallee;
use super::{Expectation, FnCtxt, TupleArgumentsFlag};

use crate::errors;
use crate::type_error_struct;
use rustc_ast::util::parser::PREC_POSTFIX;
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, StashKey};
use rustc_hir as hir;
Expand Down Expand Up @@ -603,17 +602,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

let callee_ty = self.resolve_vars_if_possible(callee_ty);
let mut err = type_error_struct!(
self.tcx.sess,
callee_expr.span,
callee_ty,
E0618,
"expected function, found {}",
match &unit_variant {
let mut err = self.tcx.sess.create_err(errors::InvalidCallee {
span: callee_expr.span,
ty: match &unit_variant {
Some((_, kind, path)) => format!("{kind} `{path}`"),
None => format!("`{callee_ty}`"),
}
);
});
if callee_ty.references_error() {
err.downgrade_to_delayed_bug();
}

self.identify_bad_closure_def_and_call(
&mut err,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ impl HelpUseLatestEdition {
}
}

#[derive(Diagnostic)]
#[diag(hir_typeck_invalid_callee, code = "E0618")]
pub struct InvalidCallee {
#[primary_span]
pub span: Span,
pub ty: String,
}

#[derive(Subdiagnostic)]
pub enum OptionResultRefMismatch {
#[suggestion(
Expand Down