diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2025-04-01 19:55:28 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2025-04-07 08:18:19 +0000 |
commit | 46673ec062176f4c2826dabbde6a401167d73441 (patch) | |
tree | 208e1d0741b5c494df99e159e07176510b4e259f /gcc/rust/hir/rust-ast-lower-expr.cc | |
parent | 8a65b913d4c4f00c2b8aa6827c733786e4a0266e (diff) | |
download | gcc-46673ec062176f4c2826dabbde6a401167d73441.zip gcc-46673ec062176f4c2826dabbde6a401167d73441.tar.gz gcc-46673ec062176f4c2826dabbde6a401167d73441.tar.bz2 |
Migrate error state to optionals
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::self_ref_param): Remove error state
and use optional.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check label
before visiting.
* ast/rust-ast.cc (ContinueExpr::as_string): Retrieve label value.
(Lifetime::as_string): Retrieve lifetime value.
(ReferenceType::as_string): Likewise.
(SelfParam::as_string): Likewise.
* ast/rust-ast.h: Remove lifetime and LifetimeParam error state.
* ast/rust-desugar-for-loops.cc (DesugarForLoops::DesugarCtx::make_break_arm):
Use optional instead of error state.
* ast/rust-expr.h (class ContinueExpr): Make label optional.
* ast/rust-item.h (class SelfParam): Make lifetime optional.
* ast/rust-type.h (class ReferenceType): Likewise.
* backend/rust-compile-base.cc: Use optional for self param instead
of error state.
* backend/rust-compile-base.h: Update function prototype.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use optional.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Lower
lifetime only if it exists.
* hir/rust-ast-lower-block.h: Lower loop label only if it exists.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Remove
references to error state.
(ASTLowerTraitItem::visit): Lower self param only if it exists.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Use nullopt
for default value instead of SelfParam error state.
* hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Lower label
only if it exists.
* hir/rust-hir-dump.cc (Dump::do_traitfunctiondecl): Print self only if
it exists.
(Dump::visit): Liewise.
* hir/tree/rust-hir-bound.h: Remove error state.
* hir/tree/rust-hir-expr.cc (ContinueExpr::ContinueExpr): Use optional
in constructor for loop label.
(BreakExpr::BreakExpr): Likewise.
* hir/tree/rust-hir-expr.h (class ContinueExpr): Remove error state
implementation.
(class BreakExpr): Likewise.
* hir/tree/rust-hir-generic-param.h: Likewise.
* hir/tree/rust-hir-item.cc (SelfParam::SelfParam): Make lifetime
optional.
(Function::Function): Make self param optional.
* hir/tree/rust-hir-item.h (class Function): Likewise.
* hir/tree/rust-hir-type.cc (ReferenceType::ReferenceType): Make
lifetime optional.
* hir/tree/rust-hir-type.h (class ReferenceType): Likewise.
* hir/tree/rust-hir.cc (ContinueExpr::as_string): Use new getter.
(BreakExpr::as_string): Likewise.
(Lifetime::as_string): Likewise.
(ReferenceType::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(SelfParam::as_string): Remove error state checking.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Adapt to
optional.
(Parser::parse_lifetime_params): Likewise.
(Parser::parse_lifetime_params_objs): Likewise.
(Parser::parse_lifetime_param): Likewise.
(Parser::parse_lifetime_where_clause_item): Likewise.
(Parser::parse_type_param_bound): Likewise.
(Parser::parse_lifetime_bounds): Likewise.
(Parser::parse_path_generic_args): Likewise.
(Parser::parse_self_param): Likewise.
(Parser::parse_break_expr): Likewise.
(Parser::parse_continue_expr): Likewise.
(Parser::parse_reference_type_inner): Likewise.
* parse/rust-parse.h (class ParseLifetimeParamError): Add new class for
lifetime param parsing errors.
(class ParseLifetimeError): Add new class for lifetime parsing errors.
(enum ParseSelfError): Add new class for self param parsing errors.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit):
Use unchecked getter in checked context. And make anonymous region.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/hir/rust-ast-lower-expr.cc')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index 575eea6..7bb7320 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -597,8 +597,10 @@ ASTLoweringExpr::visit (AST::ForLoopExpr &expr) void ASTLoweringExpr::visit (AST::BreakExpr &expr) { - HIR::Lifetime break_label - = lower_lifetime (expr.get_label ().get_lifetime ()); + tl::optional<HIR::Lifetime> break_label = tl::nullopt; + if (expr.has_label ()) + break_label = lower_lifetime (expr.get_label ().get_lifetime ()); + HIR::Expr *break_expr = expr.has_break_expr () ? ASTLoweringExpr::translate (expr.get_break_expr ()) @@ -618,7 +620,9 @@ ASTLoweringExpr::visit (AST::BreakExpr &expr) void ASTLoweringExpr::visit (AST::ContinueExpr &expr) { - HIR::Lifetime break_label = lower_lifetime (expr.get_label ()); + tl::optional<HIR::Lifetime> break_label; + if (expr.has_label ()) + break_label = lower_lifetime (expr.get_label ()); auto crate_num = mappings.get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), |