]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE with empty generic arguments
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 17 Apr 2025 14:53:58 +0000 (15:53 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Fri, 18 Apr 2025 16:06:33 +0000 (16:06 +0000)
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.philip@googlemail.com>
gcc/rust/ast/rust-ast-visitor.cc
gcc/rust/expand/rust-expand-visitor.cc
gcc/testsuite/rust/compile/issue-3649.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/nr2/exclude

index 57741021540536e78a90ba9e8ba0359446a685ee..4d4e89c782583d95d1bbbee99a1116f35cc0fcd9 100644 (file)
@@ -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
index b5e65b5f64141e6b7dc3ec20c7ed029d388c28f8..c6c1ba4e7b03605189e9faca536652d161a554a3 100644 (file)
@@ -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 (file)
index 0000000..b85b193
--- /dev/null
@@ -0,0 +1,2 @@
+struct T(Box<>);
+// { dg-error "could not resolve type path .Box. .E0412." "" { target *-*-* } .-1 }
index e5911b2a6ac01e4a91886f6fa43a1e1c51cd81b2..12e63d884a388c3f93fda3d86b2035e6f5a78671 100644 (file)
@@ -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