aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-02-26 22:08:26 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:19:00 +0100
commit24c4394cc4e3a5aa4f455763a92bd2e41412bebc (patch)
treec872ee184579f564ffdb4cba0f01f04d67506494 /gcc/rust/backend/rust-compile-expr.cc
parent00b8eff7bda39ebd7ca9e278c33736f7f9e09994 (diff)
downloadgcc-24c4394cc4e3a5aa4f455763a92bd2e41412bebc.zip
gcc-24c4394cc4e3a5aa4f455763a92bd2e41412bebc.tar.gz
gcc-24c4394cc4e3a5aa4f455763a92bd2e41412bebc.tar.bz2
gccrs: Generic pointers are coerceable
This is a complex type-system change where it begins out journey to get rid of our can_eq interface. Rust allows: let x:*mut T let y = x as *mut u8; Which requires us to consider find a way to infer what T should be so as to keep unify happy. This means we need to introduce a new unify_and interface where we can optionally inject inference variables as well as only commit the inference variable joins when they are sucsessful. So for this case we can then inject an implicit inference variables for T that can unify against u8 to make this a valid type-resolution. Fixes #1930 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): update to new inteface * typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsafe_ptr): likewise (TypeCoercionRules::coerce_borrowed_pointer): likewise * typecheck/rust-hir-type-check.h: likewise * typecheck/rust-type-util.cc (unify_site_and): new interface to allow for infer and commit * typecheck/rust-type-util.h (unify_site_and): likewise * typecheck/rust-typecheck-context.cc (TypeCheckContext::clear_type): new interface * typecheck/rust-unify.cc (UnifyRules::UnifyRules): update (UnifyRules::Resolve): new optional flags for commit and infer (UnifyRules::go): likewise (UnifyRules::expect_adt): refactor to use new interface (UnifyRules::expect_reference): likewise (UnifyRules::expect_pointer): likewise (UnifyRules::expect_array): likewise (UnifyRules::expect_slice): likewise (UnifyRules::expect_fndef): likewise (UnifyRules::expect_fnptr): likewise (UnifyRules::expect_tuple): likewise (UnifyRules::expect_closure): likewise * typecheck/rust-unify.h: refactor interface gcc/testsuite/ChangeLog: * rust/compile/issue-1930.rs: New test.
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc9
1 files changed, 4 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 731928a..1a98f4a 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -26,7 +26,7 @@
#include "rust-compile-block.h"
#include "rust-compile-implitem.h"
#include "rust-constexpr.h"
-#include "rust-unify.h"
+#include "rust-type-util.h"
#include "rust-gcc.h"
#include "fold-const.h"
@@ -2007,10 +2007,9 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
{
TyTy::BaseType *infer_impl_call
= candidate_call->infer_substitions (expr_locus);
- monomorphized = Resolver::UnifyRules::Resolve (
- TyTy::TyWithLocation (infer_impl_call),
- TyTy::TyWithLocation (fntype), expr_locus, true /* commit */,
- true /* emit_errors */);
+ monomorphized
+ = Resolver::unify_site (ref, TyTy::TyWithLocation (infer_impl_call),
+ TyTy::TyWithLocation (fntype), expr_locus);
}
return CompileInherentImplItem::Compile (impl_item, ctx, monomorphized);