[gcc/devel/rust/master] gccrs: Fix ICE when using super mid way though path
Thomas Schwinge
tschwinge@gcc.gnu.org
Thu Mar 27 16:21:52 GMT 2025
https://gcc.gnu.org/g:34b0a681598d52de442a0a21c3a7df20bf1485bc
commit 34b0a681598d52de442a0a21c3a7df20bf1485bc
Author: Philip Herron <herron.philip@googlemail.com>
Date: Wed Mar 26 17:26:12 2025 +0000
gccrs: Fix ICE when using super mid way though path
Fixes Rust-GCC#3568
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): check for super mid path
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 puts out a different error multiple times
* rust/compile/issue-3568.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/resolve/rust-ast-resolve-path.cc | 6 ++++++
gcc/testsuite/rust/compile/issue-3568.rs | 7 +++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
3 files changed, 14 insertions(+)
diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc
index b2b10719e190..530926d5d97a 100644
--- a/gcc/rust/resolve/rust-ast-resolve-path.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-path.cc
@@ -370,6 +370,12 @@ ResolvePath::resolve_path (AST::SimplePath &expr)
}
else if (segment.is_super_path_seg ())
{
+ if (!is_first_segment)
+ {
+ rust_error_at (segment.get_locus (),
+ "%<super%> can only be used in start position");
+ return UNKNOWN_NODEID;
+ }
if (module_scope_id == crate_scope_id)
{
rust_error_at (segment.get_locus (),
diff --git a/gcc/testsuite/rust/compile/issue-3568.rs b/gcc/testsuite/rust/compile/issue-3568.rs
new file mode 100644
index 000000000000..222a174ef381
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3568.rs
@@ -0,0 +1,7 @@
+pub type T = ();
+mod foo {
+ pub use super::T;
+}
+
+pub use foo::super::foo::S as T;
+// { dg-error ".super. can only be used in start position" "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 71c2b682bf02..9273bd1489e1 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -36,4 +36,5 @@ torture/alt_patterns1.rs
torture/loop4.rs
torture/loop8.rs
torture/name_resolve1.rs
+issue-3568.rs
# please don't delete the trailing newline
More information about the Gcc-cvs
mailing list