TyTy::BaseType *expected, location_t lvalue_locus,
location_t rvalue_locus);
- tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
+ tree coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
const TyTy::DynamicObjectType *ty,
location_t locus);
tree rvalue = expression;
location_t rvalue_locus = locus;
- const TyTy::BaseType *actual = adjustment.get_actual ();
- const TyTy::BaseType *expected = adjustment.get_expected ();
+ auto actual = adjustment.get_actual ();
+ auto expected = adjustment.get_expected ();
- const TyTy::DynamicObjectType *dyn
- = static_cast<const TyTy::DynamicObjectType *> (expected);
+ const auto dyn = static_cast<const TyTy::DynamicObjectType *> (expected);
rust_debug ("resolve_unsized_dyn_adjustment actual={%s} dyn={%s}",
actual->debug_str ().c_str (), dyn->debug_str ().c_str ());
}
tree
-HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
- const TyTy::BaseType *actual,
+HIRCompileBase::coerce_to_dyn_object (tree compiled_ref, TyTy::BaseType *actual,
const TyTy::DynamicObjectType *ty,
location_t locus)
{
// __trait_object_ptr
// [list of function ptrs]
- std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
- probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
-
+ auto probed_bounds_for_receiver = Resolver::TypeBoundsProbe::Probe (actual);
tree address_of_compiled_ref = null_pointer_node;
if (!actual->is_unit ())
address_of_compiled_ref = address_expression (compiled_ref, locus);
{
public:
static std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
- Probe (const TyTy::BaseType *receiver);
+ Probe (TyTy::BaseType *receiver);
static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver,
TraitReference *ref);
void assemble_builtin_candidate (LangItem::Kind item);
private:
- TypeBoundsProbe (const TyTy::BaseType *receiver);
+ TypeBoundsProbe (TyTy::BaseType *receiver);
- const TyTy::BaseType *receiver;
+ TyTy::BaseType *receiver;
std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> trait_references;
};
AssociatedImplTrait *
lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
- const TyTy::BaseType *binding, bool *ambigious)
+ TyTy::BaseType *binding, bool *ambigious)
{
auto context = TypeCheckContext::get ();
AssociatedImplTrait *
lookup_associated_impl_block (const TyTy::TypeBoundPredicate &bound,
- const TyTy::BaseType *binding,
+ TyTy::BaseType *binding,
bool *ambigious = nullptr);
} // namespace Resolver
namespace Rust {
namespace Resolver {
-TypeBoundsProbe::TypeBoundsProbe (const TyTy::BaseType *receiver)
+TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver)
: TypeCheckBase (), receiver (receiver)
{}
std::vector<std::pair<TraitReference *, HIR::ImplBlock *>>
-TypeBoundsProbe::Probe (const TyTy::BaseType *receiver)
+TypeBoundsProbe::Probe (TyTy::BaseType *receiver)
{
TypeBoundsProbe probe (receiver);
probe.scan ();
HIR::Trait *t = TraitResolver::ResolveHirItem (impl->get_trait_ref ());
if (t == nullptr)
return true;
- // DefId trait_id = t->get_mappings ().get_defid ();
- // if (context->trait_query_in_progress (trait_id))
- // return true;
HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
TyTy::BaseType *impl_type = nullptr;
return;
}
- location_t ref_locus = mappings.lookup_location (type.get_ref ());
- ok = base->bounds_compatible (type, ref_locus, false);
+ for (const auto &pred : base->get_specified_bounds ())
+ {
+ bool found = false;
+ for (const auto &opred : type.get_specified_bounds ())
+ {
+ found = pred.is_equal (opred);
+ if (found)
+ break;
+ }
+
+ if (!found)
+ {
+ ok = false;
+ break;
+ }
+ }
+
+ ok = true;
}
private:
if (!pty->can_resolve ())
continue;
- const TyTy::BaseType *binding = pty->resolve ();
+ TyTy::BaseType *binding = pty->resolve ();
if (binding->get_kind () == TyTy::TypeKind::PARAM)
continue;
// FIXME this is missing locus
bool
-BaseType::satisfies_bound (const TypeBoundPredicate &predicate,
- bool emit_error) const
+BaseType::satisfies_bound (const TypeBoundPredicate &predicate, bool emit_error)
{
const Resolver::TraitReference *query = predicate.get ();
for (const auto &bound : specified_bounds)
}
bool
-BaseType::bounds_compatible (const BaseType &other, location_t locus,
- bool emit_error) const
+BaseType::bounds_compatible (BaseType &other, location_t locus, bool emit_error)
{
std::vector<std::reference_wrapper<const TypeBoundPredicate>>
unsatisfied_bounds;
auto &&discriminant_opt = has_discriminant ()
? tl::optional<std::unique_ptr<HIR::Expr>> (
- get_discriminant ().clone_expr ())
+ get_discriminant ().clone_expr ())
: tl::nullopt;
return new VariantDef (id, defid, identifier, ident, type,
auto discriminant_opt = has_discriminant ()
? tl::optional<std::unique_ptr<HIR::Expr>> (
- get_discriminant ().clone_expr ())
+ get_discriminant ().clone_expr ())
: tl::nullopt;
return new VariantDef (id, defid, identifier, ident, type,
if (can_resolve () != other2.can_resolve ())
return false;
- return bounds_compatible (other, UNDEF_LOCATION, false);
+ if (num_specified_bounds () != other.num_specified_bounds ())
+ return false;
+
+ for (const auto &pred : specified_bounds)
+ {
+ bool found = false;
+ for (const auto &opred : other.get_specified_bounds ())
+ {
+ found = pred.is_equal (opred);
+ if (found)
+ break;
+ }
+
+ if (!found)
+ return false;
+ }
+
+ return true;
}
// StrType
if (num_specified_bounds () != other.num_specified_bounds ())
return false;
- return bounds_compatible (other, UNDEF_LOCATION, false);
+ for (const auto &pred : specified_bounds)
+ {
+ bool found = false;
+ for (const auto &opred : other.get_specified_bounds ())
+ {
+ found = pred.is_equal (opred);
+ if (found)
+ break;
+ }
+
+ if (!found)
+ return false;
+ }
+
+ return true;
}
const std::vector<
// 2. (For functions) have the same signature
virtual bool is_equal (const BaseType &other) const;
- bool satisfies_bound (const TypeBoundPredicate &predicate,
- bool emit_error) const;
+ bool satisfies_bound (const TypeBoundPredicate &predicate, bool emit_error);
- bool bounds_compatible (const BaseType &other, location_t locus,
- bool emit_error) const;
+ bool bounds_compatible (BaseType &other, location_t locus, bool emit_error);
void inherit_bounds (const BaseType &other);
TypeBoundPredicate (const TypeBoundPredicate &other);
- virtual ~TypeBoundPredicate (){};
+ virtual ~TypeBoundPredicate () {};
TypeBoundPredicate &operator= (const TypeBoundPredicate &other);