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

commit r17-3118-geb180fd6790b9c7d197a582faaa52788d96517ff
Author: Lishin <[email protected]>
Date:   Thu Jul 16 20:06:40 2026 +0000

    gccrs: Remove manual drop emission for explicit returns
    
    Let explicit returns handled by try-finally cleanup.
    Remove the manual drop emission and related helpers.
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-drop-builder.cc
            (DropBuilder::get_block_drop_candidate_stack): Remove.
            * backend/rust-compile-drop-builder.h
            (DropBuilder::get_block_drop_candidate_stack): Remove declaration.
            * backend/rust-compile-expr.cc
            (CompileExpr::visit (HIR::ReturnExpr &)): Stop emitting drops 
manually.
            Store the return statement in translated.
    
    Signed-off-by: Lishin <[email protected]>

Diff:
---
 gcc/rust/backend/rust-compile-drop-builder.cc | 7 -------
 gcc/rust/backend/rust-compile-drop-builder.h  | 2 --
 gcc/rust/backend/rust-compile-expr.cc         | 5 ++---
 3 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-drop-builder.cc 
b/gcc/rust/backend/rust-compile-drop-builder.cc
index fb01fc3db1ab..e0947a787ca4 100644
--- a/gcc/rust/backend/rust-compile-drop-builder.cc
+++ b/gcc/rust/backend/rust-compile-drop-builder.cc
@@ -38,12 +38,5 @@ DropBuilder::peek_block_drop_candidates ()
   return ctx.block_drop_candidates.back ();
 }
 
-const std::vector<std::vector<DropCandidate>> &
-DropBuilder::get_block_drop_candidate_stack () const
-{
-  rust_assert (!ctx.block_drop_candidates.empty ());
-  return ctx.block_drop_candidates;
-}
-
 } // namespace Compile
 } // namespace Rust
\ No newline at end of file
diff --git a/gcc/rust/backend/rust-compile-drop-builder.h 
b/gcc/rust/backend/rust-compile-drop-builder.h
index ca6601705ed7..36e3cdc1e356 100644
--- a/gcc/rust/backend/rust-compile-drop-builder.h
+++ b/gcc/rust/backend/rust-compile-drop-builder.h
@@ -33,8 +33,6 @@ public:
 
   void note_simple_drop_candidate (HirId hirid, location_t locus);
   std::vector<DropCandidate> &peek_block_drop_candidates ();
-  const std::vector<std::vector<DropCandidate>> &
-  get_block_drop_candidate_stack () const;
 
 private:
   Context &ctx;
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index b76f1bcc2ac3..4be42161bfd2 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -294,11 +294,10 @@ CompileExpr::visit (HIR::ReturnExpr &expr)
        = Backend::var_expression (fncontext.ret_addr, expr.get_locus ());
     }
 
-  CompileDrop (ctx).emit_return_scope_drop_calls ();
-
   tree return_stmt = Backend::return_statement (fncontext.fndecl, return_value,
                                                expr.get_locus ());
-  ctx->add_statement (return_stmt);
+
+  translated = return_stmt;
 }
 
 void

Reply via email to