[COMMITTED 59/77] gccrs: Remove manual drop emission for explicit returns
[email protected] Fri, 7 Aug 2026 14:39:50 +0200
Newsgroups
gmane.comp.gcc.patches,gmane.comp.gcc.rust
Message-ID
<[email protected] >
From: Lishin <[email protected] >
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] >
---
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 fb01fc3db1a..e0947a787ca 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 ca6601705ed..36e3cdc1e35 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 b76f1bcc2ac..4be42161bfd 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
--
2.50.1