https://gcc.gnu.org/g:4d70c16011e809a6732a0c34f1fc23ca75851476

commit 4d70c16011e809a6732a0c34f1fc23ca75851476
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Thu Apr 17 15:53:58 2025 +0100

    gccrs: Fix ICE with empty generic arguments
    
    We have an assertion when accessing generic args if there are any which
    is really useful so this adds the missing guards for the case where
    they are specified but empty.
    
    Fixes Rust-GCC#3649
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): add guard
            * expand/rust-expand-visitor.cc (ExpandVisitor::visit): add guard
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/nr2/exclude: nr2 is missing error for this
            * rust/compile/issue-3649.rs: New test.
    
    Signed-off-by: Philip Herron <herron.phi...@googlemail.com>

Diff:
---
 gcc/rust/ast/rust-ast-visitor.cc         | 3 ++-
 gcc/rust/expand/rust-expand-visitor.cc   | 3 ++-
 gcc/testsuite/rust/compile/issue-3649.rs | 2 ++
 gcc/testsuite/rust/compile/nr2/exclude   | 1 +
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 577410215405..4d4e89c78258 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -108,7 +108,8 @@ DefaultASTVisitor::visit (GenericArgsBinding &binding)
 void
 DefaultASTVisitor::visit (AST::TypePathSegmentGeneric &segment)
 {
-  visit (segment.get_generic_args ());
+  if (segment.has_generic_args ())
+    visit (segment.get_generic_args ());
 }
 
 void
diff --git a/gcc/rust/expand/rust-expand-visitor.cc 
b/gcc/rust/expand/rust-expand-visitor.cc
index b5e65b5f6414..c6c1ba4e7b03 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -489,7 +489,8 @@ ExpandVisitor::visit (AST::PathInExpression &path)
 void
 ExpandVisitor::visit (AST::TypePathSegmentGeneric &segment)
 {
-  expand_generic_args (segment.get_generic_args ());
+  if (segment.has_generic_args ())
+    expand_generic_args (segment.get_generic_args ());
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/issue-3649.rs 
b/gcc/testsuite/rust/compile/issue-3649.rs
new file mode 100644
index 000000000000..b85b193312ef
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3649.rs
@@ -0,0 +1,2 @@
+struct T(Box<>);
+// { dg-error "could not resolve type path .Box. .E0412." "" { target *-*-* } 
.-1 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index e5911b2a6ac0..12e63d884a38 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -22,4 +22,5 @@ issue-3568.rs
 issue-3663.rs
 issue-3671.rs
 issue-3652.rs
+issue-3649.rs
 # please don't delete the trailing newline

Reply via email to