]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Use tl::expected in the parser to avoid error state
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 17 Nov 2025 14:01:14 +0000 (15:01 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 17 Dec 2025 06:20:10 +0000 (07:20 +0100)
commitce810af4667fbfdbd18d452bf8769d421dfa39bf
tree6ac66dad3d9acd0fff442a78b0814bcef9c754a8
parentb40f769c2f6c8544453fc412ac0101191c33a365
gccrs: Use tl::expected in the parser to avoid error state

We made heavy use of error state within some AST node and it was the
source of multiple errors, and caused confusion with (null) pointers.
This commit removes some error state use within our parser in an attempt
to remove those error states later.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_inner_attributes): Change
return type to avoid empty/error values that may break invariants in
the AST.
(Parser::parse_inner_attribute): Likewise.
(Parser::parse_outer_attribute): Likewise.
(Parser::parse_outer_attributes): Likewise.
(Parser::parse_attribute_body): Likewise.
(Parser::parse_simple_path): Likewise.
(Parser::parse_macro_invocation): Likewise.
(Parser::parse_visibility): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_delim_token_tree): Likewise.
(Parser::parse_identifier_or_keyword_token): Likewise.
(Parser::parse_token_tree): Likewise.
(Parser::parse_macro_rules_def): Likewise.
(Parser::parse_decl_macro_def): Likewise.
(Parser::parse_macro_invocation): Likewise.
(Parser::parse_macro_rule): Likewise.
(Parser::parse_macro_matcher): Likewise.
(Parser::parse_type_path_segment): Likewise.
(Parser::parse_path_expr_segment): Likewise.
(Parser::parse_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
(Parser::parse_items): Circumvent GCC 5 to 7 bug.
(is_simple_path_segment): Move to utility file.
(token_id_matches_delims): Likewise.
(is_likely_path_next): Remove unused function.
(Parser::parse_attr_input): Return a structure instead of a tuple.
* expand/rust-macro-builtins-offset-of.cc: Adapt call to expected.
* ast/rust-ast.cc (AttributeParser::parse_path_meta_item): Use empty
vector when an error is encountered.
* expand/rust-macro-builtins-include.cc: Likewise.
* parse/rust-parse.h: Update prototypes.
* parse/rust-parse-impl-proc-macro.cc: Likewise.
* ast/rust-ast.h: Remove error state from Visibility.
* ast/rust-item.h: Use private visibility instead of error.
* ast/rust-macro.h: Likewise.
* expand/rust-macro-expand.cc: Likewise.
* hir/rust-ast-lower.cc: Remove error case.
* rust-session-manager.cc: Use private visibility
* parse/rust-parse-utils.h: New file.
* parse/rust-parse-error.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue3608.rs: Update error messages.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 files changed:
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-item.h
gcc/rust/ast/rust-macro.h
gcc/rust/expand/rust-macro-builtins-include.cc
gcc/rust/expand/rust-macro-builtins-offset-of.cc
gcc/rust/expand/rust-macro-expand.cc
gcc/rust/hir/rust-ast-lower.cc
gcc/rust/parse/rust-parse-error.h [new file with mode: 0644]
gcc/rust/parse/rust-parse-impl-proc-macro.cc
gcc/rust/parse/rust-parse-impl.h
gcc/rust/parse/rust-parse-utils.h [new file with mode: 0644]
gcc/rust/parse/rust-parse.h
gcc/rust/rust-session-manager.cc
gcc/testsuite/rust/compile/macros/mbe/macro-issue3608.rs