aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-12-02 16:17:54 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:33:08 +0100
commit9a53a1d1abe2e97207a7bf9ed4db735c4bafb771 (patch)
treeacc9f32451d83025a6d04998d96636195705a88c /gcc/testsuite/rust/compile
parent02bdd68e7daf59a0081ad9b05b5a17624d620dc3 (diff)
downloadgcc-9a53a1d1abe2e97207a7bf9ed4db735c4bafb771.zip
gcc-9a53a1d1abe2e97207a7bf9ed4db735c4bafb771.tar.gz
gcc-9a53a1d1abe2e97207a7bf9ed4db735c4bafb771.tar.bz2
gccrs: constant evaluation like these are coercion sites
The code here was wrongly assuming the decl type from the folding of the expression would be the type of the constant decl. This is not the case for unsized coercions for slices, where the expression here is a reference to an array then we require the coercion to fix the result up to the expected type. Fixes Rust-GCC#1525 gcc/rust/ChangeLog: * backend/rust-compile-base.cc: apply coercion site to result * backend/rust-compile-base.h: update prototype * backend/rust-compile-implitem.cc (CompileTraitItem::visit): send in coercion info * backend/rust-compile-item.cc (CompileItem::visit): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-1525.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r--gcc/testsuite/rust/compile/issue-1525.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/issue-1525.rs b/gcc/testsuite/rust/compile/issue-1525.rs
new file mode 100644
index 0000000..b2247cd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1525.rs
@@ -0,0 +1,4 @@
+fn main() {
+ const slice: &[i32] = &[1, 2, 3];
+ let _slice2: &[i32] = slice;
+}