Skip to content

Conversation

@P-E-P
Copy link
Member

@P-E-P P-E-P commented Dec 10, 2025

No description provided.

@P-E-P P-E-P force-pushed the improved_parser_errors branch from 6af4be8 to adf8940 Compare December 12, 2025 13:16
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@P-E-P P-E-P marked this pull request as draft December 17, 2025 10:25
P-E-P added 3 commits January 5, 2026 14:38
A parser error header with Parse::Error namespace has recently been
introduced. Move some old parser error classes to this namespace.

gcc/rust/ChangeLog:

	* parse/rust-parse.h (class ParseLifetimeParamError): Move error from
	here ...
	(class ParseLifetimeError): Likewise.
	(enum class): Likewise.
	* parse/rust-parse-error.h (class LifetimeParam): ... to here.
	here.
	(class Lifetime): Likewise.
	(enum class): Likewise.
	(struct LoopLabel): Likewise and make it a full struct with ctors.
	(struct Self): Likewise.
	* parse/rust-parse-impl-expr.hxx: Make error point to new namespace.
	* parse/rust-parse-impl.hxx: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Errors in the parser needs to be collected instead of emitted directly.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.hxx: Collect errors instead of emitting them.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog:

	* parse/rust-parse-error.h (struct BlockExpr): Add BlockExpr error type
	* parse/rust-parse-impl-expr.hxx: Update return types.
	* parse/rust-parse-impl.hxx: Likewise.
	* parse/rust-parse.h: Update function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P force-pushed the improved_parser_errors branch 4 times, most recently from 88b3510 to 7d5edde Compare January 5, 2026 21:53
P-E-P added 3 commits January 5, 2026 23:14
Some error types in the parser had the exact same meaning and could be
grouped under one same type.

gcc/rust/ChangeLog:

	* ast/rust-ast.cc (AttributeParser::parse_meta_item_lit): Use
	tl::expected
	* expand/rust-macro-builtins-helpers.cc (parse_single_string_literal):
	Likewise.
	* expand/rust-macro-expand.cc (MacroExpander::match_fragment):
	Likewise.
	* parse/rust-cfg-parser.cc (parse_cfg_option): Likewise.
	* parse/rust-parse-error.h (struct SimplePath): Remove error type.
	(struct DelimTokenTree): Likewise.
	(struct Token): Likewise.
	(struct TokenTree): Likewise.
	(class LifetimeParam): Move from here ...
	(struct LifetimeParam): ... to here. Add ctor.
	(class Lifetime): Add error type.
	(enum class): Remove AnonConst.
	(struct BlockExpr): Change BlockExpr to generic node error.
	* parse/rust-parse-impl-expr.hxx: Use tl::expected for errors.
	* parse/rust-parse-impl-path.hxx: Likewise.
	* parse/rust-parse-impl-ttree.hxx: Likewise.
	* parse/rust-parse-impl.hxx: Likewise.
	* parse/rust-parse.h: Update function return types with tl::expected
	to propagate errors.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Update function
	name.
	* ast/rust-ast-pointer-visitor.cc (PointerVisitor::visit): Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast.cc (BreakExpr::as_string): Use getter function.
	(AttributeParser::parse_path_meta_item): Convert to expected type.
	(ReturnExpr::as_string): Change access to returned expr.
	* ast/rust-desugar-for-loops.cc (DesugarForLoops::DesugarCtx::make_break_arm):
	Likewise.
	* ast/rust-expr.h (class BreakExpr): Make expr in break optional.
	(class ReturnExpr): Make returned expr explicitely optional. Change the
	getters and introduce a  const getter.
	* expand/rust-cfg-strip.cc (CfgStrip::visit): Convert to expected type.
	* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Update
	constructor call to new expected types.
	(parse_reg_operand_out): Likewise.
	(parse_reg_operand_inout): Likewise.
	(parse_llvm_operands): Likewise.
	* expand/rust-macro-builtins-format-args.cc (format_args_parse_expr):
	Likewise.
	(format_args_parse_arguments): Likewise.
	* expand/rust-macro-builtins-helpers.cc (try_expand_many_expr): Update
	value for tl::expected.
	* expand/rust-macro-builtins-include.cc (MacroBuiltin::include_handler):
	Likewise.
	* expand/rust-macro-expand.cc (transcribe_expression): Update
	constructor call with expected value.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	* parse/rust-parse-error.h (enum class): Add new error types for Expr
	and StructExprField.
	* parse/rust-parse-impl-expr.hxx: Explicitely handle return expr
	parsing failure. Update to fit new expected types.
	* parse/rust-parse-impl.hxx: Likewise.
	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Adapt to
	tl::expected.
	* ast/rust-desugar-while-let.cc (DesugarWhileLet::DesugarCtx::make_break_arm):
	Use optional for break expressions when missing instead of nullptr.
	* parse/rust-parse.h: Change function return type with expected. Remove
	error state from ExprOrStmt.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
GCC5 does not infer correctly the type to use within the template.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl-expr.hxx: Use explicit template.
	* parse/rust-parse-impl-path.hxx: Likewise.
	* parse/rust-parse-impl-ttree.hxx: Likewise.
	* parse/rust-parse-impl.hxx: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P force-pushed the improved_parser_errors branch from 7d5edde to dfc822a Compare January 6, 2026 00:30
@P-E-P P-E-P marked this pull request as ready for review January 6, 2026 10:05
@P-E-P P-E-P added this pull request to the merge queue Jan 6, 2026
@P-E-P P-E-P changed the title Improved parser errors Improved Expr parser errors Jan 6, 2026
Merged via the queue into Rust-GCC:master with commit 13d989d Jan 6, 2026
12 checks passed
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.

2 participants