Skip to content

Commit

Permalink
gccrs: fix a compiler crash when path expression contains nothing
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-path.h: allows error nodes to specify the source
	location, so that it could be used in diagnostics later.
	* parse/rust-parse-impl.h: creates the PathInExpression error node
	with source location and prints proper diagnostics if the path
	is empty.

gcc/testsuite/ChangeLog:

	* rust/compile/paamayim-nekudotayim.rs: add a test for testing
	proper error recovery logic when there is no path names.
  • Loading branch information
liushuyu committed Dec 4, 2024
1 parent 9e07940 commit 658ca0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,9 @@ class PathInExpression : public Pattern, public ExprWithoutBlock
}

// Creates an error state path in expression.
static PathInExpression create_error ()
static PathInExpression create_error (location_t locus = UNDEF_LOCATION)
{
return PathInExpression ({}, {}, UNDEF_LOCATION);
return PathInExpression ({}, {}, locus);
}

// Returns whether path in expression is in an error state.
Expand Down
5 changes: 2 additions & 3 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6713,9 +6713,8 @@ Parser<ManagedTokenSource>::parse_path_in_expression ()
AST::PathExprSegment initial_segment = parse_path_expr_segment ();
if (initial_segment.is_error ())
{
// skip after somewhere?
// don't necessarily throw error but yeah
return AST::PathInExpression::create_error ();
rust_error_at (locus, "expected identifier");
return AST::PathInExpression::create_error (locus);
}
segments.push_back (std::move (initial_segment));

Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/rust/compile/paamayim-nekudotayim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// http://phpsadness.com/sad/1
fn main() {
::;
// { dg-error "expected identifier" "" { target *-*-* } .-1 }
}

0 comments on commit 658ca0f

Please sign in to comment.