[gccrs COMMIT 3/3] gccrs: Remove unnessecary diagnostics on array capacity values

gerris.rs@gmail.com gerris.rs@gmail.com
Tue Sep 15 09:16:04 GMT 2026


From: Philip Herron <herron.philip@googlemail.com>

Fixes Rust-GCC/gccrs#4153

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): always update const type
	* typecheck/rust-unify.cc (UnifyRules::expect_array): emit_error=false

gcc/testsuite/ChangeLog:

	* rust/compile/issues/4168.rs: remove dup/bad diagnostic
	* rust/compile/issues/issue-4153.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/883e65a539a9c84c6cb29f19ddca1bca47daf163

The commit has been mentioned in the following issue(s):
 - Rust-GCC/gccrs#4153: https://github.com/Rust-GCC/gccrs/issues/4153

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4896

 gcc/rust/typecheck/rust-hir-type-check-type.cc  |  5 +++--
 gcc/rust/typecheck/rust-unify.cc                |  5 ++++-
 gcc/testsuite/rust/compile/issues/4168.rs       |  1 -
 gcc/testsuite/rust/compile/issues/issue-4153.rs | 15 +++++++++++++++
 4 files changed, 22 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issues/issue-4153.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 5fe75cf48..c60d419e5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -734,9 +734,10 @@ TypeCheckType::visit (HIR::ArrayType &type)
 
 	  const_type = new TyTy::ConstValueType (capacity_expr, expected_ty,
 						 size_id, size_id);
-	  context->insert_type (type.get_size_expr ().get_mappings (),
-				const_type->as_base_type ());
 	}
+
+      context->insert_type (type.get_size_expr ().get_mappings (),
+			    const_type->as_base_type ());
     }
 
   translated
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index c8dee6214..3d5454741 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -987,7 +987,10 @@ UnifyRules::expect_array (TyTy::ArrayType *ltype, TyTy::BaseType *rtype)
 	auto capacity_type_unify = capacity_unify->as_const_type ();
 	if (capacity_type_unify->const_kind ()
 	    == TyTy::BaseConstType::ConstKind::Error)
-	  return unify_error_type_node ();
+	  {
+	    emit_error = false;
+	    return unify_error_type_node ();
+	  }
 
 	return new TyTy::ArrayType (
 	  type.get_ref (), type.get_ty_ref (), type.get_ident ().locus,
diff --git a/gcc/testsuite/rust/compile/issues/4168.rs b/gcc/testsuite/rust/compile/issues/4168.rs
index ad0d0420f..7d01ec9f2 100644
--- a/gcc/testsuite/rust/compile/issues/4168.rs
+++ b/gcc/testsuite/rust/compile/issues/4168.rs
@@ -7,4 +7,3 @@ const fn add(x: usize, y: usize) -> i32 {
 }
 const ARR: [i32; add(1, 2)] = [5, 6, 1];
 // { dg-error "mismatched types, expected .usize. but got .i32. .E0308." "" { target *-*-* } .-1 }
-// { dg-error "mismatched types" "" { target *-*-* } .-2 }
diff --git a/gcc/testsuite/rust/compile/issues/issue-4153.rs b/gcc/testsuite/rust/compile/issues/issue-4153.rs
new file mode 100644
index 000000000..e79e6c328
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issues/issue-4153.rs
@@ -0,0 +1,15 @@
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+fn is_123(x: [u32; N]) -> bool { // { dg-error "mismatched types, expected .usize. but got .fn \\(\\) -> \\(\\)." }
+    // { dg-error "capacity of array .* is not known at compile time" "" { target *-*-* } .-1 }
+    match x {
+        [1, 2] => true,
+        _ => false,
+    }
+}
+
+fn N() {}
-- 
2.55.0



More information about the Gcc-rust mailing list