From: Lishin <[email protected]>
Move DropCandidate into a small drop-specific header and fix the
include sturcture.
Also add missing copyright headers, fix the include guard name, and
assert that Drop lookup returns a single function candidate.
gcc/rust/ChangeLog:
* backend/rust-compile-context.h: Include
rust-compile-drop-candidate.h instead of rust-compile-drop.h.
* backend/rust-compile-drop.cc: Add copyright header.
(CompileDrop::compile_drop_call): Assert that Drop lookup returns a
single function candidate.
* backend/rust-compile-drop.h: Add copyright header. Include
rust-compile-context.h.
(RUST_COMPILE_DROP): Rename to...
(RUST_COMPILE_DROP_H): ...this.
(DropCandidate): Move to...
* backend/rust-compile-drop-candidate.h: ...this new file.
Signed-off-by: Lishin <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/9af2a5f747071f9c608e6f89557be875040a91a0
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4564
gcc/rust/backend/rust-compile-context.h | 2 +-
.../backend/rust-compile-drop-candidate.h | 40 +++++++++++++++++
gcc/rust/backend/rust-compile-drop.cc | 44 +++++++++++++------
gcc/rust/backend/rust-compile-drop.h | 39 ++++++++--------
4 files changed, 90 insertions(+), 35 deletions(-)
create mode 100644 gcc/rust/backend/rust-compile-drop-candidate.h
diff --git a/gcc/rust/backend/rust-compile-context.h
b/gcc/rust/backend/rust-compile-context.h
index b50326a3a..336fbeea7 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -20,7 +20,7 @@
#define RUST_COMPILE_CONTEXT
#include "rust-system.h"
-#include "rust-compile-drop.h"
+#include "rust-compile-drop-candidate.h"
#include "rust-hir-map.h"
#include "rust-name-resolver.h"
#include "rust-hir-type-check.h"
diff --git a/gcc/rust/backend/rust-compile-drop-candidate.h
b/gcc/rust/backend/rust-compile-drop-candidate.h
new file mode 100644
index 000000000..12ce9b453
--- /dev/null
+++ b/gcc/rust/backend/rust-compile-drop-candidate.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2026 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_COMPILE_DROP_CANDIDATE_H
+#define RUST_COMPILE_DROP_CANDIDATE_H
+
+#include "rust-system.h"
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace Compile {
+
+struct DropCandidate
+{
+ DropCandidate (HirId hirid, location_t locus) : hirid (hirid), locus (locus)
+ {}
+
+ HirId hirid;
+ location_t locus;
+};
+
+} // namespace Compile
+} // namespace Rust
+
+#endif // RUST_COMPILE_DROP_CANDIDATE_H
\ No newline at end of file
diff --git a/gcc/rust/backend/rust-compile-drop.cc
b/gcc/rust/backend/rust-compile-drop.cc
index 6d24c277c..e15eb320d 100644
--- a/gcc/rust/backend/rust-compile-drop.cc
+++ b/gcc/rust/backend/rust-compile-drop.cc
@@ -1,3 +1,21 @@
+// Copyright (C) 2026 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
#include "rust-compile-drop.h"
#include "rust-compile-base.h"
#include "rust-compile-context.h"
@@ -52,23 +70,21 @@ CompileDrop::compile_drop_call (Context *ctx, Bvariable
*var,
auto candidates
= Resolver::PathProbeImplTrait::Probe (ty->get_root (), segment, drop_ref);
- for (auto &candidate : candidates)
- {
- if (!candidate.is_impl_candidate ()
- || candidate.ty->get_kind () != TyTy::TypeKind::FNDEF)
- continue;
+ rust_assert (candidates.size () == 1);
- auto *fn_type = static_cast<TyTy::FnType *> (candidate.ty);
- tree fn_addr
- = CompileInherentImplItem::Compile (candidate.item.impl.impl_item, ctx,
- fn_type, locus);
+ auto &candidate = *candidates.begin ();
+ rust_assert (candidate.is_impl_candidate ());
+ rust_assert (candidate.ty->get_kind () == TyTy::TypeKind::FNDEF);
- tree var_expr = Backend::var_expression (var, locus);
- tree var_addr = HIRCompileBase::address_expression (var_expr, locus);
+ auto *fn_type = static_cast<TyTy::FnType *> (candidate.ty);
+ tree fn_addr
+ = CompileInherentImplItem::Compile (candidate.item.impl.impl_item, ctx,
+ fn_type, locus);
- return Backend::call_expression (fn_addr, {var_addr}, nullptr, locus);
- }
- return NULL_TREE;
+ tree var_expr = Backend::var_expression (var, locus);
+ tree var_addr = HIRCompileBase::address_expression (var_expr, locus);
+
+ return Backend::call_expression (fn_addr, {var_addr}, nullptr, locus);
}
void
diff --git a/gcc/rust/backend/rust-compile-drop.h
b/gcc/rust/backend/rust-compile-drop.h
index e16baab7e..2a710d6ce 100644
--- a/gcc/rust/backend/rust-compile-drop.h
+++ b/gcc/rust/backend/rust-compile-drop.h
@@ -1,29 +1,28 @@
-#ifndef RUST_COMPILE_DROP
-#define RUST_COMPILE_DROP
+// Copyright (C) 2026 Free Software Foundation, Inc.
-#include "rust-system.h"
-#include "rust-hir-map.h"
+// This file is part of GCC.
-class Bvariable;
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
-namespace Rust {
-
-namespace TyTy {
-class BaseType;
-}
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
-namespace Compile {
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
-class Context;
+#ifndef RUST_COMPILE_DROP_H
+#define RUST_COMPILE_DROP_H
-struct DropCandidate
-{
- DropCandidate (HirId hirid, location_t locus) : hirid (hirid), locus (locus)
- {}
+#include "rust-compile-context.h"
- HirId hirid;
- location_t locus;
-};
+namespace Rust {
+namespace Compile {
class CompileDrop
{
@@ -39,4 +38,4 @@ public:
} // namespace Compile
} // namespace Rust
-#endif // RUST_COMPILE_DROP
\ No newline at end of file
+#endif // RUST_COMPILE_DROP_H
\ No newline at end of file
--
2.54.0