aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-12-19 16:43:49 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:56:55 +0100
commitef4028cd8472edd3b898dc5a2ac353b82c6303f4 (patch)
tree2faa0162ab48ce84b2fda24bf471d85d5ae6bf0b /gcc/rust/hir/tree
parenta362f8a7d78da919d3e8ad5d924109a3c1521131 (diff)
downloadgcc-ef4028cd8472edd3b898dc5a2ac353b82c6303f4.zip
gcc-ef4028cd8472edd3b898dc5a2ac353b82c6303f4.tar.gz
gcc-ef4028cd8472edd3b898dc5a2ac353b82c6303f4.tar.bz2
gccrs: add support for lang_item eq and PartialEq trait
The Eq and Partial Ord are very similar to the operator overloads we support for add/sub/etc... but they differ in that usually the function call name matches the name of the lang item. This time we need to have support to send in a new path for the method call on the lang item we want instead of just the name of the lang item. NOTE: this test case doesnt work correctly yet we need to support the derive of partial eq on enums to generate the correct comparison code for that. Fixes Rust-GCC#3302 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): handle partial_eq possible call * backend/rust-compile-expr.h: handle case where lang item calls differ from name * hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): new helper * hir/tree/rust-hir-expr.h: likewise * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): handle partial_eq (TypeCheckExpr::resolve_operator_overload): likewise * typecheck/rust-hir-type-check-expr.h: likewise * util/rust-lang-item.cc (LangItem::ComparisonToLangItem): map comparison to lang item (LangItem::ComparisonToSegment): likewise * util/rust-lang-item.h: new lang items PartialOrd and Eq * util/rust-operators.h (enum class): likewise gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/cmp1.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/hir/tree')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.cc6
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h2
2 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
index 4a902c6..2ded789 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.cc
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -1298,6 +1298,12 @@ OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
locus (expr.get_locus ())
{}
+OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
AnonConst::AnonConst (NodeId id, std::unique_ptr<Expr> expr)
: id (id), expr (std::move (expr))
{
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 1273466..f8f2128 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -2816,6 +2816,8 @@ public:
OperatorExprMeta (HIR::ArrayIndexExpr &expr);
+ OperatorExprMeta (HIR::ComparisonExpr &expr);
+
const Analysis::NodeMapping &get_mappings () const { return node_mappings; }
const Analysis::NodeMapping &get_lvalue_mappings () const