Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccrs: fix a compiler crash when path expression contains nothing #3286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 8 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,9 @@ 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 ();
// we can not throw an error here because if entered from macro expansion
// the macro expander can throw another error which might confuse the user
return AST::PathInExpression::create_error (locus);
}
segments.push_back (std::move (initial_segment));

Expand Down Expand Up @@ -11637,6 +11637,11 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
AST::PathInExpression path = parse_path_in_expression ();
std::unique_ptr<AST::Expr> null_denotation;

if (path.is_error ())
{
rust_error_at (path.get_locus (), "expected identifier");
}
Comment on lines +11641 to +11643
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
rust_error_at (path.get_locus (), "expected identifier");
}
rust_error_at (path.get_locus (), "expected identifier");

small formatting nit :)


if (lexer.peek_token ()->get_id () == EXCLAM)
{
std::unique_ptr<AST::MacroInvocation> invoc
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 }
}
Loading