aboutsummaryrefslogtreecommitdiff
path: root/gcc
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
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')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc13
-rw-r--r--gcc/testsuite/rust/compile/generics4.rs1
-rw-r--r--gcc/testsuite/rust/compile/generics6.rs1
-rw-r--r--gcc/testsuite/rust/compile/issue-2035.rs10
-rw-r--r--gcc/testsuite/rust/compile/type-bindings1.rs1
-rw-r--r--gcc/testsuite/rust/compile/unconstrained_type_param.rs1
6 files changed, 19 insertions, 8 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;
}
diff --git a/gcc/testsuite/rust/compile/generics4.rs b/gcc/testsuite/rust/compile/generics4.rs
index 31b681a..c4dbc43 100644
--- a/gcc/testsuite/rust/compile/generics4.rs
+++ b/gcc/testsuite/rust/compile/generics4.rs
@@ -6,7 +6,6 @@ struct GenericStruct<T>(T, usize);
fn main() {
let a2;
a2 = GenericStruct::<i8, i32>(1, 456); // { dg-error "generic item takes at most 1 type arguments but 2 were supplied" }
- // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-1 }
let b2: i32 = a2.0;
// { dg-error {Expected Tuple or ADT got: T\?} "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/rust/compile/generics6.rs b/gcc/testsuite/rust/compile/generics6.rs
index 33093cf..d77c559 100644
--- a/gcc/testsuite/rust/compile/generics6.rs
+++ b/gcc/testsuite/rust/compile/generics6.rs
@@ -27,6 +27,5 @@ impl Foo<f32> {
fn main() {
let a: i32 = Foo::test(); // { dg-error "multiple applicable items in scope for: .test." }
- // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-1 }
}
diff --git a/gcc/testsuite/rust/compile/issue-2035.rs b/gcc/testsuite/rust/compile/issue-2035.rs
new file mode 100644
index 0000000..c0817d5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2035.rs
@@ -0,0 +1,10 @@
+fn func(i: i32) {
+ i();
+ // { dg-error "expected function, found .i32. .E0618." "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let i = 0i32;
+ i();
+ // { dg-error "expected function, found .i32. .E0618." "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/type-bindings1.rs b/gcc/testsuite/rust/compile/type-bindings1.rs
index 358035b..ef0b471 100644
--- a/gcc/testsuite/rust/compile/type-bindings1.rs
+++ b/gcc/testsuite/rust/compile/type-bindings1.rs
@@ -7,5 +7,4 @@ fn main() {
let a;
a = Foo::<A = i32, B = f32>(123f32);
// { dg-error "associated type bindings are not allowed here" "" { target *-*-* } .-1 }
- // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-2 }
}
diff --git a/gcc/testsuite/rust/compile/unconstrained_type_param.rs b/gcc/testsuite/rust/compile/unconstrained_type_param.rs
index 1cef0b9..60554da 100644
--- a/gcc/testsuite/rust/compile/unconstrained_type_param.rs
+++ b/gcc/testsuite/rust/compile/unconstrained_type_param.rs
@@ -13,5 +13,4 @@ impl<X, Y> Foo<X> {
fn main() {
let a = Foo::test();
// { dg-error "expected" "" { target *-*-* } .-1 }
- // { dg-error "Failed to resolve expression of function call" "" { target *-*-* } .-2 }
}