aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-02-14 17:32:20 +0000
committerPhilip Herron <philip.herron@embecosm.com>2025-02-14 18:03:54 +0000
commitf21bf4bd6c415884c3b24c96a381d9cbc6c1cde2 (patch)
treef80deb20c2d1f9d17d451b1d95dce168c44526bb /gcc/rust
parent1eb46203ced28c5a3e44f6b63a23d4e91bd4f344 (diff)
downloadgcc-f21bf4bd6c415884c3b24c96a381d9cbc6c1cde2.zip
gcc-f21bf4bd6c415884c3b24c96a381d9cbc6c1cde2.tar.gz
gcc-f21bf4bd6c415884c3b24c96a381d9cbc6c1cde2.tar.bz2
gccrs: improve error diagnostic for bad type-resolution in CallExpr
We have the type information for the resolved call lets tell the user about it in the diagnostic and apply the correct error code. Fixes Rust-GCC#2035 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): improve error diag gcc/testsuite/ChangeLog: * rust/compile/generics4.rs: cleanup * rust/compile/generics6.rs: likewise * rust/compile/type-bindings1.rs: likewise * rust/compile/unconstrained_type_param.rs: likewise * rust/compile/issue-2035.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 30fca00..99edcc3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -225,12 +225,17 @@ TypeCheckExpr::visit (HIR::CallExpr &expr)
if (resolved_fn_trait_call)
return;
- bool valid_tyty = function_tyty->get_kind () == TyTy::TypeKind::FNDEF
- || function_tyty->get_kind () == TyTy::TypeKind::FNPTR;
+ bool valid_tyty
+ = function_tyty->is<TyTy::FnType> () || function_tyty->is<TyTy::FnPtr> ();
if (!valid_tyty)
{
- rust_error_at (expr.get_locus (),
- "Failed to resolve expression of function call");
+ bool emit_error = !function_tyty->is<TyTy::ErrorType> ();
+ if (emit_error)
+ {
+ rich_location r (line_table, expr.get_locus ());
+ rust_error_at (r, ErrorCode::E0618, "expected function, found %<%s%>",
+ function_tyty->get_name ().c_str ());
+ }
return;
}