From: Yap Zhi Heng <[email protected]>

gcc/rust/ChangeLog:

        * parse/rust-parse-impl.hxx(parse_expr_stmt): Return error early when
        parse_path_in_expression() returns an error node.

Signed-off-by: Yap Zhi Heng <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/dcf65692c273b5cf84b72064f1d5371e68b91782

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4558

 gcc/rust/parse/rust-parse-impl.hxx       | 9 +++++++++
 gcc/testsuite/rust/compile/empty_path.rs | 7 +++++++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/empty_path.rs

diff --git a/gcc/rust/parse/rust-parse-impl.hxx 
b/gcc/rust/parse/rust-parse-impl.hxx
index 97bd5b15e..9d7d529d4 100644
--- a/gcc/rust/parse/rust-parse-impl.hxx
+++ b/gcc/rust/parse/rust-parse-impl.hxx
@@ -7284,6 +7284,15 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
     case DOLLAR_SIGN:
       {
        AST::PathInExpression path = parse_path_in_expression ();
+       if (path.is_error ())
+         {
+           Error error (t->get_locus (), "expected identifier");
+           add_error (std::move (error));
+           skip_after_semicolon ();
+           return tl::unexpected<Parse::Error::Node> (
+             Parse::Error::Node::CHILD_ERROR);
+         }
+
        tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
          null_denotation;
 
diff --git a/gcc/testsuite/rust/compile/empty_path.rs 
b/gcc/testsuite/rust/compile/empty_path.rs
new file mode 100644
index 000000000..7d8c296bb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/empty_path.rs
@@ -0,0 +1,7 @@
+#![feature(no_core)]
+#![no_core]
+
+fn main() {
+    ::;
+    // { dg-error "expected identifier" "" { target *-*-* } .-1 }
+}

base-commit: 954e0795be0d8c172b7de6d606ea4ed48ab557d2
-- 
2.54.0

Reply via email to