diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-12-19 16:43:49 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-01-07 21:04:52 +0000 |
commit | e891887bf6ab7b4601f22cfa0e19f206a1d52d51 (patch) | |
tree | e226ee50ea820edcd650add5fe780636ea8cb253 /gcc/rust/backend/rust-compile-expr.h | |
parent | 5bccf14d99253f3f39f12701b8a0066ed95f2e59 (diff) | |
download | gcc-e891887bf6ab7b4601f22cfa0e19f206a1d52d51.zip gcc-e891887bf6ab7b4601f22cfa0e19f206a1d52d51.tar.gz gcc-e891887bf6ab7b4601f22cfa0e19f206a1d52d51.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/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 9e7af42..45e0d3c 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -99,7 +99,9 @@ protected: tree resolve_operator_overload ( LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs, tree rhs, HIR::Expr &lhs_expr, - tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr); + tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr, + HIR::PathIdentSegment specified_segment + = HIR::PathIdentSegment::create_error ()); tree compile_bool_literal (const HIR::LiteralExpr &expr, const TyTy::BaseType *tyty); |