https://gcc.gnu.org/g:e0df215ca50c2bd2a0ccc103484b629d2fbd43ec

commit r15-9106-ge0df215ca50c2bd2a0ccc103484b629d2fbd43ec
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Fri Mar 28 18:24:57 2025 +0000

    gccrs: fix ice when setting up regions
    
    num regions is based on the used arguments of regions which can be
    less than the substutions requirements. So lets check for that and allow
    anon regions to be created for them.
    
    Fixes Rust-GCC#3605
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-tyty-subst.h: check for min range
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-3605.rs: New test.
    
    Signed-off-by: Philip Herron <herron.phi...@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-tyty-subst.h     | 2 +-
 gcc/testsuite/rust/compile/issue-3605.rs | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-tyty-subst.h 
b/gcc/rust/typecheck/rust-tyty-subst.h
index b8e928d60f03..3f0b912fa7b0 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.h
+++ b/gcc/rust/typecheck/rust-tyty-subst.h
@@ -125,7 +125,7 @@ public:
                                     std::vector<Region> subst)
   {
     RegionParamList list (num_regions);
-    for (size_t i = 0; i < subst.size (); i++)
+    for (size_t i = 0; i < MIN (num_regions, subst.size ()); i++)
       list.regions.at (i) = subst.at (i);
     for (size_t i = subst.size (); i < num_regions; i++)
       {
diff --git a/gcc/testsuite/rust/compile/issue-3605.rs 
b/gcc/testsuite/rust/compile/issue-3605.rs
new file mode 100644
index 000000000000..05e6e48e66e3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3605.rs
@@ -0,0 +1,5 @@
+enum Foo<'a> {}
+
+enum Bar<'a> {
+    in_band_def_explicit_impl(Foo<'a>),
+}

Reply via email to