From: Arthur Cohen <arthur.co...@embecosm.com> gcc/rust/ChangeLog:
* expand/rust-derive-partial-eq.cc (DerivePartialEq::tuple_indexes): Remove. (DerivePartialEq::field_acccesses): Remove. (DerivePartialEq::visit_tuple): Use new API. (DerivePartialEq::visit_struct): Likewise. * expand/rust-derive-partial-eq.h: Remove declarations. --- gcc/rust/expand/rust-derive-partial-eq.cc | 22 ++-------------------- gcc/rust/expand/rust-derive-partial-eq.h | 14 +------------- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/gcc/rust/expand/rust-derive-partial-eq.cc b/gcc/rust/expand/rust-derive-partial-eq.cc index 22368bcb2b0..13a09fce059 100644 --- a/gcc/rust/expand/rust-derive-partial-eq.cc +++ b/gcc/rust/expand/rust-derive-partial-eq.cc @@ -83,24 +83,6 @@ DerivePartialEq::eq_fn (std::unique_ptr<Expr> &&cmp_expression, std::move (block)); } -DerivePartialEq::SelfOther -DerivePartialEq::tuple_indexes (int idx) -{ - return SelfOther{ - builder.tuple_idx ("self", idx), - builder.tuple_idx ("other", idx), - }; -} - -DerivePartialEq::SelfOther -DerivePartialEq::field_acccesses (const std::string &field_name) -{ - return SelfOther{ - builder.field_access (builder.identifier ("self"), field_name), - builder.field_access (builder.identifier ("other"), field_name), - }; -} - std::unique_ptr<Expr> DerivePartialEq::build_eq_expression ( std::vector<SelfOther> &&field_expressions) @@ -137,7 +119,7 @@ DerivePartialEq::visit_tuple (TupleStruct &item) auto fields = std::vector<SelfOther> (); for (size_t idx = 0; idx < item.get_fields ().size (); idx++) - fields.emplace_back (tuple_indexes (idx)); + fields.emplace_back (SelfOther::index (builder, idx)); auto fn = eq_fn (build_eq_expression (std::move (fields)), type_name); @@ -153,7 +135,7 @@ DerivePartialEq::visit_struct (StructStruct &item) for (auto &field : item.get_fields ()) fields.emplace_back ( - field_acccesses (field.get_field_name ().as_string ())); + SelfOther::field (builder, field.get_field_name ().as_string ())); auto fn = eq_fn (build_eq_expression (std::move (fields)), type_name); diff --git a/gcc/rust/expand/rust-derive-partial-eq.h b/gcc/rust/expand/rust-derive-partial-eq.h index 12d793d81bc..fdfe4dacb85 100644 --- a/gcc/rust/expand/rust-derive-partial-eq.h +++ b/gcc/rust/expand/rust-derive-partial-eq.h @@ -21,6 +21,7 @@ #include "rust-derive.h" #include "rust-path.h" +#include "rust-derive-cmp-common.h" namespace Rust { namespace AST { @@ -46,19 +47,6 @@ private: std::unique_ptr<AssociatedItem> eq_fn (std::unique_ptr<Expr> &&cmp_expression, std::string type_name); - /** - * A pair of two expressions from each instance being compared. E.g. this - * could be `self.0` and `other.0`, or `self.field` and `other.field` - */ - struct SelfOther - { - std::unique_ptr<Expr> self_expr; - std::unique_ptr<Expr> other_expr; - }; - - SelfOther tuple_indexes (int idx); - SelfOther field_acccesses (const std::string &field_name); - /** * Build a suite of equality arithmetic expressions chained together by a * boolean AND operator -- 2.49.0