Skip to content

Conversation

@P-E-P
Copy link
Member

@P-E-P P-E-P commented Nov 17, 2025

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.

@P-E-P P-E-P marked this pull request as draft November 18, 2025 14:18
@P-E-P P-E-P force-pushed the parser_error_values branch 3 times, most recently from fd83799 to 8b3ff51 Compare November 20, 2025 15:53
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.
	(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.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P force-pushed the parser_error_values branch from 8b3ff51 to 719a040 Compare November 20, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant