-
Notifications
You must be signed in to change notification settings - Fork 205
Improved Expr parser errors #4330
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
Merged
Merged
+1,473
−1,185
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6af4be8 to
adf8940
Compare
CohenArthur
approved these changes
Dec 17, 2025
Member
CohenArthur
left a comment
There was a problem hiding this 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!
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]>
88b3510 to
7d5edde
Compare
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]>
7d5edde to
dfc822a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.