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]>
---
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 97bd5b15e1f..9d7d529d4ee 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 00000000000..7d8c296bb55
--- /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 }
+}
--
2.50.1