https://gcc.gnu.org/g:943f6542f449d7226bbe49e9d8b4a3d559007197
commit r17-1090-g943f6542f449d7226bbe49e9d8b4a3d559007197 Author: Yap Zhi Heng <[email protected]> Date: Tue May 26 22:39:34 2026 +0800 gccrs: Fix ICE when parsing empty path expression 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]> Diff: --- gcc/rust/parse/rust-parse-impl.hxx | 9 +++++++++ gcc/testsuite/rust/compile/empty_path.rs | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/gcc/rust/parse/rust-parse-impl.hxx b/gcc/rust/parse/rust-parse-impl.hxx index 97bd5b15e1f5..9d7d529d4ee2 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 000000000000..7d8c296bb556 --- /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 } +}
