https://gcc.gnu.org/g:0c71fe149e1fad6de7839b160ca12c3716bb8579
commit r17-1896-g0c71fe149e1fad6de7839b160ca12c3716bb8579 Author: Lishin <[email protected]> Date: Thu Jun 11 09:24:45 2026 +0000 gccrs: Clean up drop compile headers 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]> Diff: --- gcc/rust/backend/rust-compile-context.h | 2 +- gcc/rust/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(-) diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index b50326a3a70f..336fbeea7807 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 000000000000..12ce9b453d37 --- /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 6d24c277c7a1..e15eb320dd63 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 e16baab7e75b..2a710d6ceb96 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
