https://gcc.gnu.org/g:13d6c61231e82c6fdaf666924199fd519877f4f0

commit r16-2990-g13d6c61231e82c6fdaf666924199fd519877f4f0
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Thu Jul 31 21:18:56 2025 +0100

    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.phi...@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 18 +++++++++++++++---
 gcc/testsuite/rust/compile/issue-3885.rs       |  7 +++++++
 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 5bf8cc3bc1f8..2dc0e296e79b 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 000000000000..050a59cfd50c
--- /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;
+}

Reply via email to