Skip to content

Commit cb9f666

Browse files
committed
Migrate 'invalid callee' diagnostic
1 parent b40f11c commit cb9f666

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

compiler/rustc_hir_typeck/messages.ftl

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ hir_typeck_functional_record_update_on_non_struct =
5656
5757
hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
5858
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
59-
hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
6059
60+
hir_typeck_invalid_callee = expected function, found {$ty}
61+
62+
hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
6163
hir_typeck_lang_start_incorrect_number_params = incorrect number of parameters for the `start` lang item
6264
hir_typeck_lang_start_incorrect_number_params_note_expected_count = the `start` lang item should have four parameters, but found {$found_param_count}
6365

compiler/rustc_hir_typeck/src/callee.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::method::MethodCallee;
33
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
44

55
use crate::errors;
6-
use crate::type_error_struct;
76
use rustc_ast::util::parser::PREC_POSTFIX;
87
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, StashKey};
98
use rustc_hir as hir;
@@ -603,17 +602,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
603602
}
604603

605604
let callee_ty = self.resolve_vars_if_possible(callee_ty);
606-
let mut err = type_error_struct!(
607-
self.tcx.sess,
608-
callee_expr.span,
609-
callee_ty,
610-
E0618,
611-
"expected function, found {}",
612-
match &unit_variant {
605+
let mut err = self.tcx.sess.create_err(errors::InvalidCallee {
606+
span: callee_expr.span,
607+
ty: match &unit_variant {
613608
Some((_, kind, path)) => format!("{kind} `{path}`"),
614609
None => format!("`{callee_ty}`"),
615610
}
616-
);
611+
});
612+
if callee_ty.references_error() {
613+
err.downgrade_to_delayed_bug();
614+
}
617615

618616
self.identify_bad_closure_def_and_call(
619617
&mut err,

compiler/rustc_hir_typeck/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ impl HelpUseLatestEdition {
282282
}
283283
}
284284

285+
#[derive(Diagnostic)]
286+
#[diag(hir_typeck_invalid_callee, code = "E0618")]
287+
pub struct InvalidCallee {
288+
#[primary_span]
289+
pub span: Span,
290+
pub ty: String,
291+
}
292+
285293
#[derive(Subdiagnostic)]
286294
pub enum OptionResultRefMismatch {
287295
#[suggestion(

0 commit comments

Comments
 (0)