]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: improve error diagnostic for bad type-resolution in CallExpr
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 14 Feb 2025 17:32:20 +0000 (17:32 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:07:06 +0000 (13:07 +0100)
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>
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/generics4.rs
gcc/testsuite/rust/compile/generics6.rs
gcc/testsuite/rust/compile/issue-2035.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/type-bindings1.rs
gcc/testsuite/rust/compile/unconstrained_type_param.rs

index 5c38cb42b39b085fc9b4dce8931fa00fff9fb61d..85d717535ed7c25b9e41b4775cf3bd8b7ce263a3 100644 (file)
@@ -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;
     }
 
index 31b681abb10efff1583ed025a6de317379c48e8c..c4dbc432c07cd829efcb5450d50a5d78e2ec1590 100644 (file)
@@ -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 }
index 33093cf706b93cf464fd005f406fcff1f439a14d..d77c559db213681c7402ae2e3939a2ba5ca48072 100644 (file)
@@ -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 (file)
index 0000000..c0817d5
--- /dev/null
@@ -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 }
+}
index 358035bbc17189a3513b6c917384771667200cf0..ef0b47128dfaf6327e41cd1b7295a9f633284e36 100644 (file)
@@ -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 }
 }
index 1cef0b983b0a0b930796ab91e5232d5615fcc3dc..60554dac0e0173495cb120721881f52a25829c6c 100644 (file)
@@ -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 }
 }