From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id A6AEE3858C30; Tue, 28 Feb 2023 22:37:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6AEE3858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677623829; bh=MSLK4MScoDeGtbTAIRP+ufjla1xZF6wfCX5aNaMDgBo=; h=From:To:Subject:Date:From; b=m9Zd17NDhMLRh/F5veqyotlbBManH86QHt1JJXk37Nh3gJKI/9fYPj2Q6qYRQSLX+ k+972er1wWbc1ySJZ8AbSiA0Sd2WY60JD8mzhGUcdbVhHZA9iqkeOiRYCW2jwZ/Xbf PBu9zf8Vvp/cktBoO6YcXedYNnbI1z1pP44hImck= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] gccrs: Generic pointers are coerceable X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 83863c69193c27ad6dcfb67d86691ef6fb3e1486 X-Git-Newrev: 4b43f026aac8f0b9a918082551abca6bfa4d9912 Message-Id: <20230228223709.A6AEE3858C30@sourceware.org> Date: Tue, 28 Feb 2023 22:37:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4b43f026aac8f0b9a918082551abca6bfa4d9912 commit 4b43f026aac8f0b9a918082551abca6bfa4d9912 Author: Philip Herron Date: Sun Feb 26 22:08:26 2023 +0000 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 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. Diff: --- gcc/rust/backend/rust-compile-expr.cc | 9 ++- gcc/rust/typecheck/rust-coercion.cc | 25 ++++--- gcc/rust/typecheck/rust-hir-type-check.h | 1 + gcc/rust/typecheck/rust-type-util.cc | 51 +++++++++++++- gcc/rust/typecheck/rust-type-util.h | 7 +- gcc/rust/typecheck/rust-typecheck-context.cc | 10 +++ gcc/rust/typecheck/rust-unify.cc | 99 +++++++++++++++++++--------- gcc/rust/typecheck/rust-unify.h | 25 ++++++- gcc/testsuite/rust/compile/issue-1930.rs | 4 ++ 9 files changed, 181 insertions(+), 50 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index d7945dbf26b..200f3a2a07e 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); diff --git a/gcc/rust/typecheck/rust-coercion.cc b/gcc/rust/typecheck/rust-coercion.cc index bea40840fbf..fdc8bdd7acb 100644 --- a/gcc/rust/typecheck/rust-coercion.cc +++ b/gcc/rust/typecheck/rust-coercion.cc @@ -18,7 +18,7 @@ #include "rust-hir-type-check-base.h" #include "rust-coercion.h" -#include "rust-unify.h" +#include "rust-type-util.h" namespace Rust { namespace Resolver { @@ -146,7 +146,7 @@ TypeCoercionRules::coerce_unsafe_ptr (TyTy::BaseType *receiver, TyTy::PointerType *expected, Mutability to_mutbl) { - rust_debug ("coerce_unsafe_ptr(a={%s}, b={%s})", + rust_debug ("coerce_unsafe_ptr(receiver={%s}, expected={%s})", receiver->debug_str ().c_str (), expected->debug_str ().c_str ()); Mutability from_mutbl = Mutability::Imm; @@ -184,13 +184,21 @@ TypeCoercionRules::coerce_unsafe_ptr (TyTy::BaseType *receiver, return TypeCoercionRules::CoercionResult::get_error (); } - TyTy::PointerType *result + TyTy::PointerType *coerced_mutability = new TyTy::PointerType (receiver->get_ref (), TyTy::TyVar (element->get_ref ()), to_mutbl); - if (!result->can_eq (expected, false)) - return CoercionResult::get_error (); - return CoercionResult{{}, result}; + TyTy::BaseType *result + = unify_site_and (receiver->get_ref (), TyTy::TyWithLocation (expected), + TyTy::TyWithLocation (coerced_mutability), + Location () /*unify_locus*/, false /*emit_errors*/, + true /*commit_if_ok*/, true /*infer*/, + true /*cleanup on error*/); + bool unsafe_ptr_coerceion_ok = result->get_kind () != TyTy::TypeKind::ERROR; + if (unsafe_ptr_coerceion_ok) + return CoercionResult{{}, result}; + + return TypeCoercionRules::CoercionResult::get_error (); } /// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`. @@ -220,9 +228,8 @@ TypeCoercionRules::coerce_borrowed_pointer (TyTy::BaseType *receiver, // back to a final unity anyway rust_debug ("coerce_borrowed_pointer -- unify"); TyTy::BaseType *result - = UnifyRules::Resolve (TyTy::TyWithLocation (receiver), - TyTy::TyWithLocation (expected), locus, - true /* commit */, true /* emit_errors */); + = unify_site (receiver->get_ref (), TyTy::TyWithLocation (receiver), + TyTy::TyWithLocation (expected), locus); return CoercionResult{{}, result}; } } diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 6d4b9b8a62f..5c5623a0bf6 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -84,6 +84,7 @@ public: TyTy::BaseType *type); void insert_implicit_type (TyTy::BaseType *type); bool lookup_type (HirId id, TyTy::BaseType **type) const; + void clear_type (TyTy::BaseType *ty); void insert_implicit_type (HirId id, TyTy::BaseType *type); diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc index dbd10366fd7..ff7c805c943 100644 --- a/gcc/rust/typecheck/rust-type-util.cc +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -117,8 +117,57 @@ unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, rust_debug ("unify_site id={%u} expected={%s} expr={%s}", id, expected->debug_str ().c_str (), expr->debug_str ().c_str ()); + std::vector commits; + std::vector infers; return UnifyRules::Resolve (lhs, rhs, unify_locus, true /*commit*/, - true /*emit_error*/); + true /*emit_error*/, false /*infer*/, commits, + infers); +} + +TyTy::BaseType * +unify_site_and (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, + Location unify_locus, bool emit_errors, bool commit_if_ok, + bool implicit_infer_vars, bool cleanup) +{ + TypeCheckContext &context = *TypeCheckContext::get (); + + TyTy::BaseType *expected = lhs.get_ty (); + TyTy::BaseType *expr = rhs.get_ty (); + + rust_debug ( + "unify_site_and commit %s infer %s id={%u} expected={%s} expr={%s}", + commit_if_ok ? "true" : "false", implicit_infer_vars ? "true" : "false", id, + expected->debug_str ().c_str (), expr->debug_str ().c_str ()); + + std::vector commits; + std::vector infers; + TyTy::BaseType *result + = UnifyRules::Resolve (lhs, rhs, unify_locus, false /*commit inline*/, + emit_errors, implicit_infer_vars, commits, infers); + bool ok = result->get_kind () != TyTy::TypeKind::ERROR; + if (ok && commit_if_ok) + { + for (auto &c : commits) + { + UnifyRules::commit (c.lhs, c.rhs, c.resolved); + } + } + else if (cleanup) + { + // FIXME + // reset the get_next_hir_id + + for (auto &i : infers) + { + i.param->set_ref (i.pref); + i.param->set_ty_ref (i.ptyref); + + // remove the inference variable + context.clear_type (i.infer); + delete i.infer; + } + } + return result; } TyTy::BaseType * diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h index 01333d8b984..8ecba738ff4 100644 --- a/gcc/rust/typecheck/rust-type-util.h +++ b/gcc/rust/typecheck/rust-type-util.h @@ -30,13 +30,18 @@ class BaseType; namespace Resolver { -extern bool +bool query_type (HirId reference, TyTy::BaseType **result); TyTy::BaseType * unify_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, Location unify_locus); +TyTy::BaseType * +unify_site_and (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, + Location unify_locus, bool emit_errors, bool commit_if_ok, + bool implicit_infer_vars, bool cleanup); + TyTy::BaseType * coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, Location coercion_locus); diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc index 27ff96986dc..096ce26f1fa 100644 --- a/gcc/rust/typecheck/rust-typecheck-context.cc +++ b/gcc/rust/typecheck/rust-typecheck-context.cc @@ -108,6 +108,16 @@ TypeCheckContext::lookup_type (HirId id, TyTy::BaseType **type) const return true; } +void +TypeCheckContext::clear_type (TyTy::BaseType *ty) +{ + auto it = resolved.find (ty->get_ref ()); + if (it == resolved.end ()) + return; + + resolved.erase (it); +} + void TypeCheckContext::insert_type_by_node_id (NodeId ref, HirId id) { diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index e96d6b70379..37ef71ec22e 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -22,19 +22,26 @@ namespace Rust { namespace Resolver { UnifyRules::UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, - Location locus, bool commit_flag, bool emit_error) + Location locus, bool commit_flag, bool emit_error, + bool infer, std::vector &commits, + std::vector &infers) : lhs (lhs), rhs (rhs), locus (locus), commit_flag (commit_flag), - emit_error (emit_error), mappings (*Analysis::Mappings::get ()), + emit_error (emit_error), infer_flag (infer), commits (commits), + infers (infers), mappings (*Analysis::Mappings::get ()), context (*TypeCheckContext::get ()) {} TyTy::BaseType * UnifyRules::Resolve (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, - Location locus, bool commit_flag, bool emit_error) + Location locus, bool commit_flag, bool emit_error, + bool infer, std::vector &commits, + std::vector &infers) { - UnifyRules r (lhs, rhs, locus, commit_flag, emit_error); - TyTy::BaseType *result = r.go (); + UnifyRules r (lhs, rhs, locus, commit_flag, emit_error, infer, commits, + infers); + TyTy::BaseType *result = r.go (); + commits.push_back ({lhs.get_ty (), rhs.get_ty (), result}); if (r.commit_flag) UnifyRules::commit (lhs.get_ty (), rhs.get_ty (), result); @@ -142,6 +149,28 @@ UnifyRules::go () } } + // inject inference vars if required + bool got_param = rtype->get_kind () == TyTy::TypeKind::PARAM; + bool lhs_is_infer_var = ltype->get_kind () == TyTy::TypeKind::INFER; + bool expected_is_concrete = ltype->is_concrete () && !lhs_is_infer_var; + bool needs_infer = expected_is_concrete && got_param; + if (infer_flag && needs_infer) + { + TyTy::ParamType *p = static_cast (rtype); + TyTy::TyVar iv = TyTy::TyVar::get_implicit_infer_var (rhs.get_locus ()); + rust_assert (iv.get_tyty ()->get_kind () == TyTy::TypeKind::INFER); + TyTy::InferType *i = static_cast (iv.get_tyty ()); + + infers.push_back ({p->get_ref (), p->get_ty_ref (), p, i}); + + // FIXME + // this is hacky to set the implicit param lets make this a function + p->set_ty_ref (i->get_ref ()); + + // set the rtype now to the new inference var + rtype = i; + } + switch (ltype->get_kind ()) { case TyTy::INFER: @@ -367,7 +396,8 @@ UnifyRules::expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype) = UnifyRules::Resolve (TyTy::TyWithLocation (this_field_ty), TyTy::TyWithLocation (other_field_ty), locus, commit_flag, - false /* emit_error */); + false /* emit_error */, infer_flag, + commits, infers); if (unified_ty->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -392,7 +422,8 @@ UnifyRules::expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype) auto res = UnifyRules::Resolve (TyTy::TyWithLocation (pa), TyTy::TyWithLocation (pb), locus, - commit_flag, false /* emit_error */); + commit_flag, false /* emit_error */, + infer_flag, commits, infers); if (res->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -497,7 +528,8 @@ UnifyRules::expect_reference (TyTy::ReferenceType *ltype, TyTy::BaseType *rtype) TyTy::BaseType *base_resolved = UnifyRules::Resolve (TyTy::TyWithLocation (base_type), TyTy::TyWithLocation (other_base_type), locus, - commit_flag, false /* emit_error */); + commit_flag, false /* emit_error */, + infer_flag, commits, infers); if (base_resolved->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -566,7 +598,8 @@ UnifyRules::expect_pointer (TyTy::PointerType *ltype, TyTy::BaseType *rtype) TyTy::BaseType *base_resolved = UnifyRules::Resolve (TyTy::TyWithLocation (base_type), TyTy::TyWithLocation (other_base_type), locus, - commit_flag, false /* emit_error */); + commit_flag, false /* emit_error */, + infer_flag, commits, infers); if (base_resolved->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -693,7 +726,7 @@ UnifyRules::expect_array (TyTy::ArrayType *ltype, TyTy::BaseType *rtype) TyTy::BaseType *element_unify = UnifyRules::Resolve ( TyTy::TyWithLocation (ltype->get_element_type ()), TyTy::TyWithLocation (type.get_element_type ()), locus, commit_flag, - false /* emit_error*/); + false /* emit_error*/, infer_flag, commits, infers); if (element_unify->get_kind () != TyTy::TypeKind::ERROR) { @@ -752,7 +785,7 @@ UnifyRules::expect_slice (TyTy::SliceType *ltype, TyTy::BaseType *rtype) TyTy::BaseType *element_unify = UnifyRules::Resolve ( TyTy::TyWithLocation (ltype->get_element_type ()), TyTy::TyWithLocation (type.get_element_type ()), locus, commit_flag, - false /* emit_error*/); + false /* emit_error*/, infer_flag, commits, infers); if (element_unify->get_kind () != TyTy::TypeKind::ERROR) { @@ -820,18 +853,18 @@ UnifyRules::expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype) auto unified_param = UnifyRules::Resolve (TyTy::TyWithLocation (a), TyTy::TyWithLocation (b), locus, - commit_flag, false /* emit_errors */); + commit_flag, false /* emit_errors */, + infer_flag, commits, infers); if (unified_param->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); } } - auto unified_return - = UnifyRules::Resolve (TyTy::TyWithLocation ( - ltype->get_return_type ()), - TyTy::TyWithLocation (type.get_return_type ()), - locus, commit_flag, false /* emit_errors */); + auto unified_return = UnifyRules::Resolve ( + TyTy::TyWithLocation (ltype->get_return_type ()), + TyTy::TyWithLocation (type.get_return_type ()), locus, commit_flag, + false /* emit_errors */, infer_flag, commits, infers); if (unified_return->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -897,18 +930,18 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype) auto unified_param = UnifyRules::Resolve (TyTy::TyWithLocation (a), TyTy::TyWithLocation (b), locus, - commit_flag, false /* emit_errors */); + commit_flag, false /* emit_errors */, + infer_flag, commits, infers); if (unified_param->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); } } - auto unified_return - = UnifyRules::Resolve (TyTy::TyWithLocation ( - ltype->get_return_type ()), - TyTy::TyWithLocation (type.get_return_type ()), - locus, commit_flag, false /* emit_errors */); + auto unified_return = UnifyRules::Resolve ( + TyTy::TyWithLocation (ltype->get_return_type ()), + TyTy::TyWithLocation (type.get_return_type ()), locus, commit_flag, + false /* emit_errors */, infer_flag, commits, infers); if (unified_return->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -926,7 +959,8 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype) auto unified_result = UnifyRules::Resolve (TyTy::TyWithLocation (this_ret_type), TyTy::TyWithLocation (other_ret_type), locus, - commit_flag, false /*emit_errors*/); + commit_flag, false /*emit_errors*/, infer_flag, + commits, infers); if (unified_result->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -945,7 +979,8 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype) auto unified_param = UnifyRules::Resolve (TyTy::TyWithLocation (this_param), TyTy::TyWithLocation (other_param), locus, - commit_flag, false /* emit_errors */); + commit_flag, false /* emit_errors */, + infer_flag, commits, infers); if (unified_param->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -1012,7 +1047,8 @@ UnifyRules::expect_tuple (TyTy::TupleType *ltype, TyTy::BaseType *rtype) TyTy::BaseType *unified_ty = UnifyRules::Resolve (TyTy::TyWithLocation (bo), TyTy::TyWithLocation (fo), locus, - commit_flag, false /* emit_errors */); + commit_flag, false /* emit_errors */, + infer_flag, commits, infers); if (unified_ty->get_kind () == TyTy::TypeKind::ERROR) return new TyTy::ErrorType (0); @@ -1604,11 +1640,10 @@ UnifyRules::expect_closure (TyTy::ClosureType *ltype, TyTy::BaseType *rtype) return new TyTy::ErrorType (0); } - TyTy::BaseType *args_res - = UnifyRules::Resolve (TyTy::TyWithLocation ( - <ype->get_parameters ()), - TyTy::TyWithLocation (&type.get_parameters ()), - locus, commit_flag, false /* emit_error */); + TyTy::BaseType *args_res = UnifyRules::Resolve ( + TyTy::TyWithLocation (<ype->get_parameters ()), + TyTy::TyWithLocation (&type.get_parameters ()), locus, commit_flag, + false /* emit_error */, infer_flag, commits, infers); if (args_res->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); @@ -1617,7 +1652,7 @@ UnifyRules::expect_closure (TyTy::ClosureType *ltype, TyTy::BaseType *rtype) TyTy::BaseType *res = UnifyRules::Resolve ( TyTy::TyWithLocation (<ype->get_result_type ()), TyTy::TyWithLocation (&type.get_result_type ()), locus, commit_flag, - false /* emit_error */); + false /* emit_error */, infer_flag, commits, infers); if (res == nullptr || res->get_kind () == TyTy::TypeKind::ERROR) { return new TyTy::ErrorType (0); diff --git a/gcc/rust/typecheck/rust-unify.h b/gcc/rust/typecheck/rust-unify.h index 15672f1dcb9..53acf21c7d4 100644 --- a/gcc/rust/typecheck/rust-unify.h +++ b/gcc/rust/typecheck/rust-unify.h @@ -28,9 +28,25 @@ namespace Resolver { class UnifyRules { public: + struct InferenceSite + { + HirId pref; + HirId ptyref; + TyTy::ParamType *param; + TyTy::InferType *infer; + }; + struct CommitSite + { + TyTy::BaseType *lhs; + TyTy::BaseType *rhs; + TyTy::BaseType *resolved; + }; + static TyTy::BaseType *Resolve (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, Location locus, - bool commit_flag, bool emit_error); + bool commit_flag, bool emit_error, bool infer, + std::vector &commits, + std::vector &infers); static void commit (TyTy::BaseType *base, TyTy::BaseType *other, TyTy::BaseType *resolved); @@ -69,7 +85,9 @@ protected: private: UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs, - Location locus, bool commit_flag, bool emit_error); + Location locus, bool commit_flag, bool emit_error, bool infer, + std::vector &commits, + std::vector &infers); void emit_type_mismatch () const; @@ -83,6 +101,9 @@ private: Location locus; bool commit_flag; bool emit_error; + bool infer_flag; + std::vector &commits; + std::vector &infers; Analysis::Mappings &mappings; TypeCheckContext &context; diff --git a/gcc/testsuite/rust/compile/issue-1930.rs b/gcc/testsuite/rust/compile/issue-1930.rs new file mode 100644 index 00000000000..ab30ccc7da4 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1930.rs @@ -0,0 +1,4 @@ +// { dg-options "-w" } +fn test(x: *mut T) { + let x = x as *mut u8; +}