]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0423] expected function, tuple struct or tuple variant, found struct
authorMuhammad Mahad <mahadtxt@gmail.com>
Mon, 17 Jul 2023 07:32:17 +0000 (12:32 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:55 +0000 (18:55 +0100)
Give error when an identifier was used like a function
name or a value was expected and the identifier exists
but it belongs to a different namespace.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
called error function.

gcc/testsuite/ChangeLog:

* rust/compile/found_struct.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-tyty-call.cc
gcc/testsuite/rust/compile/found_struct.rs [new file with mode: 0644]

index 8469cf825b651eb8bef3e3600254389dfdf6d650..733ba616a868f9cb03357643a49b5e95e8aa2f1a 100644 (file)
@@ -59,7 +59,7 @@ TypeCheckCallExpr::visit (ADTType &type)
   if (variant.get_variant_type () != TyTy::VariantDef::VariantType::TUPLE)
     {
       rust_error_at (
-       call.get_locus (),
+       call.get_locus (), ErrorCode ("E0423"),
        "expected function, tuple struct or tuple variant, found struct %<%s%>",
        type.get_name ().c_str ());
       return;
diff --git a/gcc/testsuite/rust/compile/found_struct.rs b/gcc/testsuite/rust/compile/found_struct.rs
new file mode 100644 (file)
index 0000000..66462e6
--- /dev/null
@@ -0,0 +1,11 @@
+// https://doc.rust-lang.org/error_codes/E0423.html
+#![allow(unused)]
+fn main() {
+    struct Foo {
+        a: bool,
+    };
+
+    let f = Foo(); // { dg-error "expected function, tuple struct or tuple variant, found struct .Foo." }
+                   // error: expected function, tuple struct or tuple variant, found `Foo`
+                   // `Foo` is a struct name, but this expression uses it like a function name
+}