[gccrs COMMIT] gccrs: Add missing unconstrained type parameters walker for const generics

gerris.rs@gmail.com gerris.rs@gmail.com
Sun Aug 23 15:05:04 GMT 2026


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

Fixes Rust-GCC/gccrs#4805

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-base.cc (walk_type_to_constrain): walk const generics

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4805.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/7a008ab0e6c3e33bd7ce1f6e3240e829de3010c8

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

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

 gcc/rust/typecheck/rust-hir-type-check-base.cc | 8 ++++++++
 gcc/testsuite/rust/compile/issue-4805.rs       | 7 +++++++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-4805.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 399b95946..97ff55400 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -101,6 +101,7 @@ walk_type_to_constrain (std::set<HirId> &constrained_symbols, TyTy::BaseType &r)
       {
 	auto &arr = static_cast<TyTy::ArrayType &> (r);
 	walk_type_to_constrain (constrained_symbols, *arr.get_element_type ());
+	walk_type_to_constrain (constrained_symbols, *arr.get_capacity ());
       }
       break;
     case TyTy::TypeKind::FNDEF:
@@ -117,6 +118,13 @@ walk_type_to_constrain (std::set<HirId> &constrained_symbols, TyTy::BaseType &r)
 	constrained_symbols.insert (param.get_ty_ref ());
       }
       break;
+    case TyTy::TypeKind::CONST:
+      {
+	auto *constant = r.as_const_type ();
+	if (constant->const_kind () == TyTy::BaseConstType::ConstKind::Decl)
+	  constrained_symbols.insert (r.get_ty_ref ());
+      }
+      break;
     case TyTy::SLICE:
       {
 	auto &slice = static_cast<TyTy::SliceType &> (r);
diff --git a/gcc/testsuite/rust/compile/issue-4805.rs b/gcc/testsuite/rust/compile/issue-4805.rs
new file mode 100644
index 000000000..300e3d5aa
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4805.rs
@@ -0,0 +1,7 @@
+#![no_core]
+#![feature(no_core)]
+#![feature(min_const_generics)]
+
+trait A {}
+
+impl<const N: usize> A for [u8; N] {}

base-commit: 7e1296cfa4d3d71183ade4f2c3d48125013d16c4
-- 
2.55.0



More information about the Gcc-rust mailing list