This old can_eq interface was an old method to try and check if types can match up
by taking into account generics but its not maintained properly and we already have
a new wrapper Resolver::types_compatable (type, type, locus, emit_errors) which
just calls unify_site_and infer with commit false. There are only a few places left
to update.
One minor downside is that i need to remove const in some places because the unify
interface is non const. Ideally we would want to avoid writing a seperate const unify
anyway so i think this is not ideal but fine for us.
gcc/rust/ChangeLog:
* typecheck/rust-autoderef.cc: remove useless assertion
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsafe_ptr): refactor
(TypeCoercionRules::coerce_borrowed_pointer): remove FIXME this is fine
* typecheck/rust-hir-inherent-impl-overlap.h: use types_compatable
* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): remove const
(PathProbeType::Probe): likewise
(PathProbeImplTrait::PathProbeImplTrait): likewise
(PathProbeImplTrait::Probe): likewise
* typecheck/rust-hir-path-probe.h: likewise
* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): likewise
* typecheck/rust-hir-type-check-base.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): use types_compatable
* typecheck/rust-hir-type-check.h: remove const
* typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_associated_impl_mapping):
likewise
(TypeCheckContext::lookup_associated_impl_mapping_for_self): remove can_Eq
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionArg::get_tyty): remove const version
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.cc (BaseType::get_root): likewise
* typecheck/rust-tyty.h: likewise
gcc/testsuite/ChangeLog:
* rust/compile/generics8.rs: extra error message
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
const TyTy::ADTType *adt = static_cast<const TyTy::ADTType *> (lhs);
auto s = fn->get_self_type ()->get_root ();
- rust_assert (s->can_eq (adt, false));
rust_assert (s->get_kind () == TyTy::TypeKind::ADT);
const TyTy::ADTType *self_adt
= static_cast<const TyTy::ADTType *> (s);
default:
{
- // FIXME this can probably turn into a unify_and
- if (receiver->can_eq (expected, false))
+ if (types_compatable (TyTy::TyWithLocation (receiver),
+ TyTy::TyWithLocation (expected), UNKNOWN_LOCATION,
+ false))
return CoercionResult{{}, expected->clone ()};
return CoercionResult::get_error ();
default:
{
- // FIXME
- // we might be able to replace this with a can_eq because we default
- // back to a final unity anyway
rust_debug ("coerce_borrowed_pointer -- unify");
TyTy::BaseType *result
= unify_site_and (receiver->get_ref (),
if (query == candidate)
continue;
- if (query->can_eq (candidate, false))
+ if (!types_compatable (TyTy::TyWithLocation (query),
+ TyTy::TyWithLocation (candidate),
+ UNKNOWN_LOCATION, false))
+ continue;
+
+ // we might be in the case that we have:
+ //
+ // *const T vs *const [T]
+ //
+ // so lets use an equality check when the
+ // candidates are both generic to be sure we dont emit a false
+ // positive
+
+ bool a = query->is_concrete ();
+ bool b = candidate->is_concrete ();
+ bool both_generic = !a && !b;
+ if (both_generic)
{
- // we might be in the case that we have:
- //
- // *const T vs *const [T]
- //
- // so lets use an equality check when the
- // candidates are both generic to be sure we dont emit a false
- // positive
-
- bool a = query->is_concrete ();
- bool b = candidate->is_concrete ();
- bool both_generic = !a && !b;
- if (both_generic)
- {
- if (!query->is_equal (*candidate))
- continue;
- }
-
- possible_collision (it->second, iy->second);
+ if (!query->is_equal (*candidate))
+ continue;
}
+
+ possible_collision (it->second, iy->second);
}
}
}
// PathProbeType
-PathProbeType::PathProbeType (const TyTy::BaseType *receiver,
+PathProbeType::PathProbeType (TyTy::BaseType *receiver,
const HIR::PathIdentSegment &query,
DefId specific_trait_id)
: TypeCheckBase (), receiver (receiver), search (query),
{}
std::set<PathProbeCandidate>
-PathProbeType::Probe (const TyTy::BaseType *receiver,
+PathProbeType::Probe (TyTy::BaseType *receiver,
const HIR::PathIdentSegment &segment_name,
bool probe_impls, bool probe_bounds,
bool ignore_mandatory_trait_items,
// PathProbImplTrait
-PathProbeImplTrait::PathProbeImplTrait (const TyTy::BaseType *receiver,
+PathProbeImplTrait::PathProbeImplTrait (TyTy::BaseType *receiver,
const HIR::PathIdentSegment &query,
const TraitReference *trait_reference)
: PathProbeType (receiver, query, UNKNOWN_DEFID),
{}
std::set<PathProbeCandidate>
-PathProbeImplTrait::Probe (const TyTy::BaseType *receiver,
+PathProbeImplTrait::Probe (TyTy::BaseType *receiver,
const HIR::PathIdentSegment &segment_name,
const TraitReference *trait_reference)
{
{
public:
static std::set<PathProbeCandidate>
- Probe (const TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &segment_name, bool probe_impls,
- bool probe_bounds, bool ignore_mandatory_trait_items,
+ Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
+ bool probe_impls, bool probe_bounds, bool ignore_mandatory_trait_items,
DefId specific_trait_id = UNKNOWN_DEFID);
void visit (HIR::TypeAlias &alias) override;
bool ignore_mandatory_trait_items);
protected:
- PathProbeType (const TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &query, DefId specific_trait_id);
+ PathProbeType (TyTy::BaseType *receiver, const HIR::PathIdentSegment &query,
+ DefId specific_trait_id);
std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>>
union_bounds (
bool is_receiver_generic () const;
- const TyTy::BaseType *receiver;
+ TyTy::BaseType *receiver;
const HIR::PathIdentSegment &search;
std::set<PathProbeCandidate> candidates;
HIR::ImplBlock *current_impl;
{
public:
static std::set<PathProbeCandidate>
- Probe (const TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &segment_name,
+ Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
const TraitReference *trait_reference);
private:
- PathProbeImplTrait (const TyTy::BaseType *receiver,
+ PathProbeImplTrait (TyTy::BaseType *receiver,
const HIR::PathIdentSegment &query,
const TraitReference *trait_reference);
{
for (const auto &c : constraints.get_mappings ())
{
- const TyTy::BaseType *arg = c.get_tyty ();
+ auto arg = c.get_tyty ();
if (arg != nullptr)
{
- const TyTy::BaseType *p = arg->get_root ();
+ const auto p = arg->get_root ();
constrained_symbols.insert (p->get_ty_ref ());
if (p->has_substitutions_defined ())
{
const std::vector<TyTy::SubstitutionParamMapping> ¶ms_to_constrain,
const TyTy::SubstitutionArgumentMappings &constraint_a,
const TyTy::SubstitutionArgumentMappings &constraint_b,
- const TyTy::BaseType *reference)
+ TyTy::BaseType *reference)
{
bool check_result = false;
bool check_completed
const std::vector<TyTy::SubstitutionParamMapping> ¶ms_to_constrain,
const TyTy::SubstitutionArgumentMappings &constraint_a,
const TyTy::SubstitutionArgumentMappings &constraint_b,
- const TyTy::BaseType *reference);
+ TyTy::BaseType *reference);
TyTy::BaseType *resolve_literal (const Analysis::NodeMapping &mappings,
HIR::Literal &literal, location_t locus);
bool ok = context->lookup_builtin ("usize", &size_ty);
rust_assert (ok);
- bool maybe_simple_array_access = index_expr_ty->can_eq (size_ty, false);
+ bool maybe_simple_array_access
+ = types_compatable (TyTy::TyWithLocation (index_expr_ty),
+ TyTy::TyWithLocation (size_ty), expr.get_locus (),
+ false);
if (maybe_simple_array_access
&& direct_array_expr_ty->get_kind () == TyTy::TypeKind::ARRAY)
{
bool lookup_associated_type_mapping (HirId id, HirId *mapping);
void insert_associated_impl_mapping (HirId trait_id,
- const TyTy::BaseType *impl_type,
+ TyTy::BaseType *impl_type,
HirId impl_id);
bool lookup_associated_impl_mapping_for_self (HirId trait_id,
- const TyTy::BaseType *self,
+ TyTy::BaseType *self,
HirId *mapping);
void insert_autoderef_mappings (HirId id,
std::map<HirId, AssociatedImplTrait> associated_impl_traits;
// trait-id -> list of < self-tyty:impl-id>
- std::map<HirId, std::vector<std::pair<const TyTy::BaseType *, HirId>>>
+ std::map<HirId, std::vector<std::pair<TyTy::BaseType *, HirId>>>
associated_traits_to_impls;
std::map<HirId, HirId> associated_type_mappings;
}
void
-TypeCheckContext::insert_associated_impl_mapping (
- HirId trait_id, const TyTy::BaseType *impl_type, HirId impl_id)
+TypeCheckContext::insert_associated_impl_mapping (HirId trait_id,
+ TyTy::BaseType *impl_type,
+ HirId impl_id)
{
auto it = associated_traits_to_impls.find (trait_id);
if (it == associated_traits_to_impls.end ())
}
bool
-TypeCheckContext::lookup_associated_impl_mapping_for_self (
- HirId trait_id, const TyTy::BaseType *self, HirId *mapping)
+TypeCheckContext::lookup_associated_impl_mapping_for_self (HirId trait_id,
+ TyTy::BaseType *self,
+ HirId *mapping)
{
auto it = associated_traits_to_impls.find (trait_id);
if (it == associated_traits_to_impls.end ())
for (auto &item : it->second)
{
- if (item.first->can_eq (self, false))
+ if (types_compatable (TyTy::TyWithLocation (item.first),
+ TyTy::TyWithLocation (self), UNKNOWN_LOCATION,
+ false))
{
*mapping = item.second;
return true;
// then match the generics applied
for (size_t i = 0; i < get_num_substitutions (); i++)
{
- const SubstitutionParamMapping &a = substitutions.at (i);
- const SubstitutionParamMapping &b = other.substitutions.at (i);
+ SubstitutionParamMapping a = substitutions.at (i);
+ SubstitutionParamMapping b = other.substitutions.at (i);
- const auto ap = a.get_param_ty ();
- const auto bp = b.get_param_ty ();
+ auto ap = a.get_param_ty ();
+ auto bp = b.get_param_ty ();
- const BaseType *apd = ap->destructure ();
- const BaseType *bpd = bp->destructure ();
+ BaseType *apd = ap->destructure ();
+ BaseType *bpd = bp->destructure ();
- // FIXME use the unify_and infer inteface or try coerce
- if (!apd->can_eq (bpd, false /*emit_errors*/))
- {
- if (!bpd->can_eq (apd, false /*emit_errors*/))
- return false;
- }
+ if (!Resolver::types_compatable (TyTy::TyWithLocation (apd),
+ TyTy::TyWithLocation (bpd),
+ UNKNOWN_LOCATION, false))
+ return false;
}
return true;
}
BaseType *
-SubstitutionArg::get_tyty ()
-{
- return argument;
-}
-
-const BaseType *
SubstitutionArg::get_tyty () const
{
return argument;
SubstitutionArg &operator= (const SubstitutionArg &other);
- BaseType *get_tyty ();
-
- const BaseType *get_tyty () const;
+ BaseType *get_tyty () const;
const SubstitutionParamMapping *get_param_mapping () const;
}
}
-const BaseType *
-BaseType::get_root () const
+BaseType *
+BaseType::get_root ()
{
- // FIXME this needs to be it its own visitor class with a vector adjustments
- const TyTy::BaseType *root = this;
+ TyTy::BaseType *root = this;
if (const auto r = root->try_as<const ReferenceType> ())
{
void debug () const;
- // FIXME this will eventually go away
- const BaseType *get_root () const;
+ BaseType *get_root ();
// This will get the monomorphized type from Params, Placeholders or
// Projections if available or error
struct Foo<A, B>(A, B);
impl<T> Foo<i32, T> {
- fn test(a: T) -> T {
+ fn test(a: T) -> T { // { dg-error "duplicate definitions with name .test." }
a
}
}