aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-07-31 21:18:56 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-08-05 16:37:01 +0200
commit13d6c61231e82c6fdaf666924199fd519877f4f0 (patch)
tree65ba9b4f04d92064e5f1daf93434cd826251e340
parent3e141c0cd3e0a926734bfb4f1c7f6f7558c47fa9 (diff)
downloadgcc-13d6c61231e82c6fdaf666924199fd519877f4f0.zip
gcc-13d6c61231e82c6fdaf666924199fd519877f4f0.tar.gz
gcc-13d6c61231e82c6fdaf666924199fd519877f4f0.tar.bz2
gccrs: Support const generic inference variables
We already support const infer so this just creates a fresh tyty::infer_var for the const element type and then a ConstKind::Infer type for the const type wrapper and the existing plumbing handles this. Fixes Rust-GCC#3885 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): create infer variable gcc/testsuite/ChangeLog: * rust/compile/issue-3885.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc18
-rw-r--r--gcc/testsuite/rust/compile/issue-3885.rs7
2 files changed, 22 insertions, 3 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 5bf8cc3..2dc0e29 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -33,6 +33,7 @@
#include "rust-type-util.h"
#include "rust-immutable-name-resolution-context.h"
#include "rust-compile-base.h"
+#include "rust-tyty-util.h"
#include "tree.h"
namespace Rust {
@@ -662,11 +663,22 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
void
TypeCheckExpr::visit (HIR::AnonConst &expr)
{
- // FIXME: How do we typecheck a deferred inference const?
+ if (!expr.is_deferred ())
+ {
+ infered = TypeCheckExpr::Resolve (expr.get_inner_expr ());
+ return;
+ }
+
+ auto locus = expr.get_locus ();
+ auto infer_ty_var = TyTy::TyVar::get_implicit_infer_var (locus);
- rust_assert (!expr.is_deferred ());
+ HirId next = mappings.get_next_hir_id ();
+ infered = new TyTy::ConstType (TyTy::ConstType::ConstKind::Infer, "",
+ infer_ty_var.get_tyty (), error_mark_node, {},
+ locus, next, next, {});
- infered = TypeCheckExpr::Resolve (expr.get_inner_expr ());
+ context->insert_implicit_type (infered->get_ref (), infered);
+ mappings.insert_location (infered->get_ref (), locus);
}
void
diff --git a/gcc/testsuite/rust/compile/issue-3885.rs b/gcc/testsuite/rust/compile/issue-3885.rs
new file mode 100644
index 0000000..050a59c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3885.rs
@@ -0,0 +1,7 @@
+pub fn test() {
+ let _u: [_; _] = [15u32];
+ let _v: [u8; _] = [1, 2, 3];
+ let _w: [_; 2] = [1.0, 2.0];
+ let _x = [42; 5];
+ let _y: [_; _] = _x;
+}