diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-11-25 14:02:25 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-25 14:11:25 +0000 |
commit | ec23757d36928b9e59e3236790378cf824e7ab49 (patch) | |
tree | 51ee5e938c29b56bddf8eb4ee0d818b38b7c440e /gcc | |
parent | 12b7154e90f676222262fe3d6935a950805a8566 (diff) | |
download | gcc-ec23757d36928b9e59e3236790378cf824e7ab49.zip gcc-ec23757d36928b9e59e3236790378cf824e7ab49.tar.gz gcc-ec23757d36928b9e59e3236790378cf824e7ab49.tar.bz2 |
Add support for generics within operator overloads
This ports over some code from the method-call expr to try and infer the
arguments in the function definition when required.
Addresses #809
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 4923426..f8b9f05 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -1293,6 +1293,8 @@ protected: return false; // mark the required tree addressable + Adjuster adj (lhs); + TyTy::BaseType *receiver_adjusted_self_ty = adj.adjust_type (adjustments); if (Adjuster::needs_address (adjustments)) AddressTakenResolver::SetAddressTaken (*expr.get_expr ().get ()); @@ -1324,14 +1326,12 @@ protected: TyTy::FnType *fntype = static_cast<TyTy::FnType *> (lookup); rust_assert (fntype->is_method ()); - Adjuster adj (lhs); - TyTy::BaseType *adjusted = adj.adjust_type (adjustments); - bool is_lang_item_impl = trait_reference->get_mappings ().get_defid () == respective_lang_item_id; bool self_is_lang_item_self - = fntype->get_self_type ()->is_equal (*adjusted); + = fntype->get_self_type ()->is_equal ( + *receiver_adjusted_self_ty); bool recursive_operator_overload = is_lang_item_impl && self_is_lang_item_self; @@ -1415,8 +1415,20 @@ protected: } } + // handle generics + if (!receiver_is_type_param) + { + if (lookup->needs_generic_substitutions ()) + { + lookup = SubstMapper::InferSubst (lookup, expr.get_locus ()); + } + } + // type check the arguments if required TyTy::FnType *type = static_cast<TyTy::FnType *> (lookup); + rust_assert (type->num_params () > 0); + auto fnparam = type->param_at (0); + fnparam.second->unify (receiver_adjusted_self_ty); // typecheck the self if (rhs == nullptr) { rust_assert (type->num_params () == 1); @@ -1429,7 +1441,7 @@ protected: } // get the return type - TyTy::BaseType *function_ret_tyty = fn->get_return_type ()->clone (); + TyTy::BaseType *function_ret_tyty = type->get_return_type ()->clone (); // store the expected fntype context->insert_operator_overload (expr.get_mappings ().get_hirid (), type); |