Skip to content

Commit 658ca0f

Browse files
committed
gccrs: fix a compiler crash when path expression contains nothing
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.
1 parent 9e07940 commit 658ca0f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

gcc/rust/ast/rust-path.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,9 @@ class PathInExpression : public Pattern, public ExprWithoutBlock
727727
}
728728

729729
// Creates an error state path in expression.
730-
static PathInExpression create_error ()
730+
static PathInExpression create_error (location_t locus = UNDEF_LOCATION)
731731
{
732-
return PathInExpression ({}, {}, UNDEF_LOCATION);
732+
return PathInExpression ({}, {}, locus);
733733
}
734734

735735
// Returns whether path in expression is in an error state.

gcc/rust/parse/rust-parse-impl.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -6713,9 +6713,8 @@ Parser<ManagedTokenSource>::parse_path_in_expression ()
67136713
AST::PathExprSegment initial_segment = parse_path_expr_segment ();
67146714
if (initial_segment.is_error ())
67156715
{
6716-
// skip after somewhere?
6717-
// don't necessarily throw error but yeah
6718-
return AST::PathInExpression::create_error ();
6716+
rust_error_at (locus, "expected identifier");
6717+
return AST::PathInExpression::create_error (locus);
67196718
}
67206719
segments.push_back (std::move (initial_segment));
67216720

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// http://phpsadness.com/sad/1
2+
fn main() {
3+
::;
4+
// { dg-error "expected identifier" "" { target *-*-* } .-1 }
5+
}

0 commit comments

Comments
 (0)