https://gcc.gnu.org/g:c4ec1bc7b2ff98e20b20fd34a490b0d711b19f2c

commit r15-9301-gc4ec1bc7b2ff98e20b20fd34a490b0d711b19f2c
Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
Date:   Thu Apr 3 14:40:15 2025 +0200

    gccrs: Rename label getter in ContinueExpr
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-collector.cc (TokenCollector::visit):
            Call unchecked getter.
            * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):
            Likewise.
            * ast/rust-ast.cc (ContinueExpr::as_string): Likewise.
            * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
            * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise.
            * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
            * ast/rust-expr.h: Add new getter for the optional and rename getter
            to get_label_unchecked.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc              | 2 +-
 gcc/rust/ast/rust-ast-visitor.cc                | 2 +-
 gcc/rust/ast/rust-ast.cc                        | 2 +-
 gcc/rust/ast/rust-expr.h                        | 7 +++++--
 gcc/rust/hir/rust-ast-lower-expr.cc             | 2 +-
 gcc/rust/resolve/rust-ast-resolve-expr.cc       | 6 +++---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 2 +-
 7 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 3297407e6e82..165b7617fe4a 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -1279,7 +1279,7 @@ TokenCollector::visit (ContinueExpr &expr)
 {
   push (Rust::Token::make (CONTINUE, expr.get_locus ()));
   if (expr.has_label ())
-    visit (expr.get_label ());
+    visit (expr.get_label_unchecked ());
 }
 
 void
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index b72e063987f3..702a176b266a 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -478,7 +478,7 @@ DefaultASTVisitor::visit (AST::ContinueExpr &expr)
 {
   visit_outer_attrs (expr);
   if (expr.has_label ())
-    visit (expr.get_label ());
+    visit (expr.get_label_unchecked ());
 }
 
 void
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 1d92bf3b1636..670e6d2413d1 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -1631,7 +1631,7 @@ ContinueExpr::as_string () const
   std::string str ("continue ");
 
   if (has_label ())
-    str += get_label ().as_string ();
+    str += get_label_unchecked ().as_string ();
 
   return str;
 }
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 70cb6d403551..4c832f9a06f4 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -2879,8 +2879,11 @@ public:
     outer_attrs = std::move (new_attrs);
   }
 
-  Lifetime &get_label () { return label.value (); }
-  const Lifetime &get_label () const { return label.value (); }
+  Lifetime &get_label_unchecked () { return label.value (); }
+  const Lifetime &get_label_unchecked () const { return label.value (); }
+
+  tl::optional<Lifetime> &get_label () { return label; }
+  const tl::optional<Lifetime> &get_label () const { return label; }
 
   Expr::Kind get_expr_kind () const override { return Expr::Kind::Continue; }
 
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index ea1623f809e6..944c0bbf4d15 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -622,7 +622,7 @@ ASTLoweringExpr::visit (AST::ContinueExpr &expr)
 {
   tl::optional<HIR::Lifetime> break_label;
   if (expr.has_label ())
-    break_label = lower_lifetime (expr.get_label ());
+    break_label = lower_lifetime (expr.get_label_unchecked ());
 
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc 
b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 4bfd1b3ca4fe..54d92854128c 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -594,7 +594,7 @@ ResolveExpr::visit (AST::ContinueExpr &expr)
 {
   if (expr.has_label ())
     {
-      auto label = expr.get_label ();
+      auto label = expr.get_label_unchecked ();
       if (label.get_lifetime_type () != AST::Lifetime::LifetimeType::NAMED)
        {
          rust_error_at (label.get_locus (),
@@ -608,8 +608,8 @@ ResolveExpr::visit (AST::ContinueExpr &expr)
                                    label.get_lifetime_name ()),
            &resolved_node))
        {
-         rust_error_at (expr.get_label ().get_locus (), ErrorCode::E0426,
-                        "use of undeclared label %qs",
+         rust_error_at (expr.get_label_unchecked ().get_locus (),
+                        ErrorCode::E0426, "use of undeclared label %qs",
                         label.as_string ().c_str ());
          return;
        }
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 3e69d3436733..b22be2a1a2d1 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -242,7 +242,7 @@ void
 Late::visit (AST::ContinueExpr &expr)
 {
   if (expr.has_label ())
-    resolve_label (expr.get_label ());
+    resolve_label (expr.get_label_unchecked ());
 
   DefaultResolver::visit (expr);
 }

Reply via email to