aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-06-23 11:21:02 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-08-05 16:36:51 +0200
commitdd4eabb87bff25a1a1ad5fc7b8f2da7cce8e0e47 (patch)
tree37583e0a7b3177d9d2ed061b4899bf095c7eb46e /gcc/testsuite/rust
parent866510c83a4e35473b1f4caf3b1258aa23fc742f (diff)
downloadgcc-dd4eabb87bff25a1a1ad5fc7b8f2da7cce8e0e47.zip
gcc-dd4eabb87bff25a1a1ad5fc7b8f2da7cce8e0e47.tar.gz
gcc-dd4eabb87bff25a1a1ad5fc7b8f2da7cce8e0e47.tar.bz2
gccrs: check for invalid const calls during code-gen
Closure calls are not const so this is invalid. This patch fixes two bugs 1. Make the look at the parent context optional for generics 2. Ensure we look for non const calls during call expr code-gen Fixes Rust-GCC#3551 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): add const call check * backend/rust-compile-item.cc (CompileItem::visit): ensure we upfront compile types where possible * backend/rust-compile-item.h: update header * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): make parent ctx optional gcc/testsuite/ChangeLog: * rust/compile/issue-3551.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/testsuite/rust')
-rw-r--r--gcc/testsuite/rust/compile/issue-3551.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/issue-3551.rs b/gcc/testsuite/rust/compile/issue-3551.rs
new file mode 100644
index 0000000..6d6a812
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3551.rs
@@ -0,0 +1,15 @@
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ #[lang = "fn_once_output"]
+ type Output;
+
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+struct Bug {
+ a: [(); (|| 0)()],
+ // { dg-error "calls in constants are limited to constant functions, tuple structs and tuple variants" "" { target *-*-* } .-1 }
+}