TyTy::TypeBoundPredicateItem item = TyTy::TypeBoundPredicateItem::error ();
if (predicate.get_name ().compare ("FnOnce") == 0)
{
- item = predicate.lookup_associated_item ("call_once");
+ item = predicate.lookup_associated_item ("call_once").value ();
}
else if (predicate.get_name ().compare ("FnMut") == 0)
{
- item = predicate.lookup_associated_item ("call_mut");
+ item = predicate.lookup_associated_item ("call_mut").value ();
}
else if (predicate.get_name ().compare ("Fn") == 0)
{
- item = predicate.lookup_associated_item ("call");
+ item = predicate.lookup_associated_item ("call").value ();
}
else
{
&receiver_bounds,
const TyTy::BaseType *receiver, const TyTy::BaseType *root, location_t locus)
{
- TyTy::TypeBoundPredicateItem predicate_item
+ tl::optional<TyTy::TypeBoundPredicateItem> predicate_item
= predicate->lookup_associated_item (ref->get_identifier ());
- rust_assert (!predicate_item.is_error ());
+ rust_assert (predicate_item.has_value ());
// This is the expected end type
- TyTy::BaseType *trait_item_type = predicate_item.get_tyty_for_receiver (root);
+ TyTy::BaseType *trait_item_type
+ = predicate_item->get_tyty_for_receiver (root);
rust_assert (trait_item_type->get_kind () == TyTy::TypeKind::FNDEF);
TyTy::FnType *trait_item_fntype
= static_cast<TyTy::FnType *> (trait_item_type);
std::vector<predicate_candidate> predicate_items;
for (auto &bound : specified_bounds)
{
- TyTy::TypeBoundPredicateItem lookup
+ tl::optional<TyTy::TypeBoundPredicateItem> lookup
= bound.lookup_associated_item (segment_name.as_string ());
- if (lookup.is_error ())
+ if (!lookup.has_value ())
continue;
- TyTy::BaseType *ty = lookup.get_tyty_for_receiver (&receiver);
+ TyTy::BaseType *ty = lookup->get_tyty_for_receiver (&receiver);
if (ty->get_kind () == TyTy::TypeKind::FNDEF)
{
TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
if (fnty->is_method ())
- predicate_items.emplace_back (lookup, fnty);
+ predicate_items.emplace_back (lookup.value (), fnty);
}
}
{
const TraitReference *trait_ref = predicate.get ();
- TyTy::TypeBoundPredicateItem item
+ tl::optional<TyTy::TypeBoundPredicateItem> item
= predicate.lookup_associated_item (search.as_string ());
- if (item.is_error ())
+ if (!item.has_value ())
return;
- if (ignore_mandatory_trait_items && item.needs_implementation ())
+ if (ignore_mandatory_trait_items && item->needs_implementation ())
return;
- const TraitItemReference *trait_item_ref = item.get_raw_item ();
+ const TraitItemReference *trait_item_ref = item->get_raw_item ();
PathProbeCandidate::CandidateType candidate_type;
switch (trait_item_ref->get_trait_item_type ())
{
break;
}
- TyTy::BaseType *trait_item_tyty = item.get_raw_item ()->get_tyty ();
+ TyTy::BaseType *trait_item_tyty = item->get_raw_item ()->get_tyty ();
if (receiver->get_kind () != TyTy::DYNAMIC)
- trait_item_tyty = item.get_tyty_for_receiver (receiver);
+ trait_item_tyty = item->get_tyty_for_receiver (receiver);
PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref,
trait_item_ref,
}
// get the item from the predicate
- resolved_trait_item = trait_reference.lookup_associated_item (raw_trait_item);
- rust_assert (!resolved_trait_item.is_error ());
+ resolved_trait_item
+ = trait_reference.lookup_associated_item (raw_trait_item).value ();
// merge the attributes
const HIR::TraitItem *hir_trait_item
}
// get the item from the predicate
- resolved_trait_item = trait_reference.lookup_associated_item (raw_trait_item);
- rust_assert (!resolved_trait_item.is_error ());
+ resolved_trait_item
+ = trait_reference.lookup_associated_item (raw_trait_item).value ();
// merge the attributes
const HIR::TraitItem *hir_trait_item
}
// get the item from the predicate
- resolved_trait_item = trait_reference.lookup_associated_item (raw_trait_item);
- rust_assert (!resolved_trait_item.is_error ());
+ resolved_trait_item
+ = trait_reference.lookup_associated_item (raw_trait_item).value ();
// merge the attributes
const HIR::TraitItem *hir_trait_item
// lookup the associated item from the specified bound
HIR::PathExprSegment &item_seg = expr.get_segments ().at (0);
HIR::PathIdentSegment item_seg_identifier = item_seg.get_segment ();
- TyTy::TypeBoundPredicateItem item
+ tl::optional<TyTy::TypeBoundPredicateItem> item
= specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
- if (item.is_error ())
+ if (!item.has_value ())
{
rust_error_at (item_seg.get_locus (), "unknown associated item");
return;
// and we dont need to worry if the trait item is actually implemented or
// not because this will have already been validated as part of the trait
// impl block
- infered = item.get_tyty_for_receiver (root);
+ infered = item->get_tyty_for_receiver (root);
root_resolved_node_id
- = item.get_raw_item ()->get_mappings ().get_nodeid ();
+ = item->get_raw_item ()->get_mappings ().get_nodeid ();
}
else
{
// lookup the associated item from the specified bound
HIR::TypePathSegment &item_seg = path.get_associated_segment ();
HIR::PathIdentSegment item_seg_identifier = item_seg.get_ident_segment ();
- TyTy::TypeBoundPredicateItem item
+ tl::optional<TyTy::TypeBoundPredicateItem> item
= specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
- if (item.is_error ())
+ if (!item.has_value ())
{
std::string item_seg_ident_name, rich_msg;
item_seg_ident_name = qual_path_type.get_trait ().as_string ();
// and we dont need to worry if the trait item is actually implemented or
// not because this will have already been validated as part of the trait
// impl block
- translated = item.get_tyty_for_receiver (root);
+ translated = item->get_tyty_for_receiver (root);
}
else
{
std::string identifier = it.first;
TyTy::BaseType *type = it.second;
- TypeBoundPredicateItem item = lookup_associated_item (identifier);
- rust_assert (!item.is_error ());
+ tl::optional<TypeBoundPredicateItem> item
+ = lookup_associated_item (identifier);
- const auto item_ref = item.get_raw_item ();
+ if (!item.has_value ())
+ continue;
+
+ const auto item_ref = item->get_raw_item ();
item_ref->associated_type_set (type);
}
return trait_ref->lookup_trait_item (search, &trait_item_ref);
}
-TypeBoundPredicateItem
+tl::optional<TypeBoundPredicateItem>
TypeBoundPredicate::lookup_associated_item (const std::string &search) const
{
auto trait_ref = get ();
for (auto &super_trait : super_traits)
{
auto lookup = super_trait.lookup_associated_item (search);
- if (!lookup.is_error ())
+ if (lookup.has_value ())
return lookup;
}
- return TypeBoundPredicateItem::error ();
+ return tl::nullopt;
}
TypeBoundPredicateItem::TypeBoundPredicateItem (
return &parent;
}
-TypeBoundPredicateItem
+tl::optional<TypeBoundPredicateItem>
TypeBoundPredicate::lookup_associated_item (
const Resolver::TraitItemReference *ref) const
{
std::string identifier = it.first;
TyTy::BaseType *type = it.second;
- TypeBoundPredicateItem item = lookup_associated_item (identifier);
- if (!item.is_error ())
+ tl::optional<TypeBoundPredicateItem> item
+ = lookup_associated_item (identifier);
+ if (item.has_value ())
{
- const auto item_ref = item.get_raw_item ();
+ const auto item_ref = item->get_raw_item ();
item_ref->associated_type_set (type);
}
}
TypeBoundPredicateItem
TypeBoundPredicate::lookup_associated_type (const std::string &search)
{
- TypeBoundPredicateItem item = lookup_associated_item (search);
+ tl::optional<TypeBoundPredicateItem> item = lookup_associated_item (search);
// only need to check that it is infact an associated type because other
// wise if it was not found it will just be an error node anyway
- if (!item.is_error ())
+ if (item.has_value ())
{
- const auto raw = item.get_raw_item ();
+ const auto raw = item->get_raw_item ();
if (raw->get_trait_item_type ()
!= Resolver::TraitItemReference::TraitItemType::TYPE)
return TypeBoundPredicateItem::error ();
}
- return item;
+ return item.value ();
}
std::vector<TypeBoundPredicateItem>
return false;
std::string item_name = item->get_impl_item_name ();
- TypeBoundPredicateItem lookup
+ tl::optional<TypeBoundPredicateItem> lookup
= predicate.lookup_associated_item (item_name);
- if (lookup.is_error ())
+ if (!lookup.has_value ())
return false;
- const auto *item_ref = lookup.get_raw_item ();
+ const auto *item_ref = lookup->get_raw_item ();
TyTy::BaseType *bound_ty = item_ref->get_tyty ();
// compare the types
bool contains_item (const std::string &search) const;
- TypeBoundPredicateItem
+ tl::optional<TypeBoundPredicateItem>
lookup_associated_item (const std::string &search) const;
- TypeBoundPredicateItem
+ tl::optional<TypeBoundPredicateItem>
lookup_associated_item (const Resolver::TraitItemReference *ref) const;
// WARNING THIS WILL ALWAYS RETURN NULLPTR