https://gcc.gnu.org/g:2cf21f899577fa534bcf0e5854d77a82472234ab
commit r16-2859-g2cf21f899577fa534bcf0e5854d77a82472234ab Author: Arthur Cohen <arthur.co...@embecosm.com> Date: Fri Apr 18 18:30:46 2025 +0200 gccrs: derive(Ord, PartialOrd): Handle tuples properly gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (is_last): Remove. (DeriveOrd::visit_tuple): Fix implementation. Diff: --- gcc/rust/expand/rust-derive-ord.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/gcc/rust/expand/rust-derive-ord.cc b/gcc/rust/expand/rust-derive-ord.cc index 2403e9c2a33d..e39c6b44ca46 100644 --- a/gcc/rust/expand/rust-derive-ord.cc +++ b/gcc/rust/expand/rust-derive-ord.cc @@ -123,15 +123,6 @@ DeriveOrd::make_cmp_arms () builder.match_arm (std::move (non_equal))}; } -template <typename T> -inline bool -is_last (T &elt, std::vector<T> &vec) -{ - rust_assert (!vec.empty ()); - - return &elt == &vec.back (); -} - std::unique_ptr<Expr> DeriveOrd::recursive_match (std::vector<SelfOther> &&members) { @@ -210,7 +201,14 @@ DeriveOrd::visit_struct (StructStruct &item) // straightforward once we have `visit_struct` working void DeriveOrd::visit_tuple (TupleStruct &item) -{} +{ + auto fields = SelfOther::indexes (builder, item.get_fields ()); + + auto match_expr = recursive_match (std::move (fields)); + + expanded = cmp_impl (builder.block (std::move (match_expr)), + item.get_identifier (), item.get_generic_params ()); +} // for enums, we need to generate a match for each of the enum's variant that // contains data and then do the same thing as visit_struct or visit_enum. if