]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE when using super mid way though path
authorPhilip Herron <herron.philip@googlemail.com>
Wed, 26 Mar 2025 17:26:12 +0000 (17:26 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 31 Mar 2025 19:07:16 +0000 (21:07 +0200)
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>
gcc/rust/resolve/rust-ast-resolve-path.cc
gcc/testsuite/rust/compile/issue-3568.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/nr2/exclude

index b2b10719e19086978bcb224bf11178fb82751774..530926d5d97a5bd6f47a436db33dd5d4522da066 100644 (file)
@@ -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 (file)
index 0000000..222a174
--- /dev/null
@@ -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 }
index 71c2b682bf02da40ce23458c00190cb1c663e11d..9273bd1489e123a455da91ece9f4f0e2bc1d8eb0 100644 (file)
@@ -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