gccrs: bugfix: initialize slice from array in const context
authorFaisal Abbas <90.abbasfaisal@gmail.com>
Sun, 4 Sep 2022 15:07:43 +0000 (16:07 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 31 Jan 2023 13:16:51 +0000 (14:16 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Turn
constant item typechecking into a coercion site instead of a unify
site.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-stmt.cc
gcc/testsuite/rust/compile/const6.rs [new file with mode: 0644]

index e82dd8e..a55cf22 100644 (file)
@@ -68,7 +68,7 @@ TypeCheckStmt::visit (HIR::ConstantItem &constant)
   TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ());
   TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ());
 
-  infered = unify_site (
+  infered = coercion_site (
     constant.get_mappings ().get_hirid (),
     TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()),
     TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()),
diff --git a/gcc/testsuite/rust/compile/const6.rs b/gcc/testsuite/rust/compile/const6.rs
new file mode 100644 (file)
index 0000000..8f0dc32
--- /dev/null
@@ -0,0 +1,4 @@
+fn main() {
+    const array:[i32; 1] = [1];
+    const slice:&[i32] = &array;
+}