public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Add support for generics within operator overloads Date: Wed, 8 Jun 2022 11:54:47 +0000 (GMT) [thread overview] Message-ID: <20220608115447.A38403AA8009@sourceware.org> (raw) https://gcc.gnu.org/g:ec23757d36928b9e59e3236790378cf824e7ab49 commit ec23757d36928b9e59e3236790378cf824e7ab49 Author: Philip Herron <philip.herron@embecosm.com> Date: Thu Nov 25 14:02:25 2021 +0000 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 Diff: --- gcc/rust/typecheck/rust-hir-type-check-expr.h | 22 +++++++++++++++++----- 1 file 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 492342647e5..f8b9f051fa6 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);
reply other threads:[~2022-06-08 11:54 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608115447.A38403AA8009@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).