@@ -575,10 +575,13 @@ TypeBoundPredicate::apply_argument_mappings (
575575 std::string identifier = it.first ;
576576 TyTy::BaseType *type = it.second ;
577577
578- TypeBoundPredicateItem item = lookup_associated_item (identifier);
579- rust_assert (!item. is_error () );
578+ tl::optional< TypeBoundPredicateItem> item
579+ = lookup_associated_item (identifier );
580580
581- const auto item_ref = item.get_raw_item ();
581+ if (!item.has_value ())
582+ continue ;
583+
584+ const auto item_ref = item->get_raw_item ();
582585 item_ref->associated_type_set (type);
583586 }
584587
@@ -599,7 +602,7 @@ TypeBoundPredicate::contains_item (const std::string &search) const
599602 return trait_ref->lookup_trait_item (search, &trait_item_ref);
600603}
601604
602- TypeBoundPredicateItem
605+ tl::optional< TypeBoundPredicateItem>
603606TypeBoundPredicate::lookup_associated_item (const std::string &search) const
604607{
605608 auto trait_ref = get ();
@@ -611,11 +614,11 @@ TypeBoundPredicate::lookup_associated_item (const std::string &search) const
611614 for (auto &super_trait : super_traits)
612615 {
613616 auto lookup = super_trait.lookup_associated_item (search);
614- if (! lookup.is_error ())
617+ if (lookup.has_value ())
615618 return lookup;
616619 }
617620
618- return TypeBoundPredicateItem::error () ;
621+ return tl:: nullopt ;
619622}
620623
621624TypeBoundPredicateItem::TypeBoundPredicateItem (
@@ -656,7 +659,7 @@ TypeBoundPredicateItem::get_parent () const
656659 return &parent;
657660}
658661
659- TypeBoundPredicateItem
662+ tl::optional< TypeBoundPredicateItem>
660663TypeBoundPredicate::lookup_associated_item (
661664 const Resolver::TraitItemReference *ref) const
662665{
@@ -732,10 +735,11 @@ TypeBoundPredicate::handle_substitions (
732735 std::string identifier = it.first ;
733736 TyTy::BaseType *type = it.second ;
734737
735- TypeBoundPredicateItem item = lookup_associated_item (identifier);
736- if (!item.is_error ())
738+ tl::optional<TypeBoundPredicateItem> item
739+ = lookup_associated_item (identifier);
740+ if (item.has_value ())
737741 {
738- const auto item_ref = item. get_raw_item ();
742+ const auto item_ref = item-> get_raw_item ();
739743 item_ref->associated_type_set (type);
740744 }
741745 }
@@ -799,18 +803,18 @@ TypeBoundPredicate::get_trait_hierachy (
799803TypeBoundPredicateItem
800804TypeBoundPredicate::lookup_associated_type (const std::string &search)
801805{
802- TypeBoundPredicateItem item = lookup_associated_item (search);
806+ tl::optional< TypeBoundPredicateItem> item = lookup_associated_item (search);
803807
804808 // only need to check that it is infact an associated type because other
805809 // wise if it was not found it will just be an error node anyway
806- if (! item.is_error ())
810+ if (item.has_value ())
807811 {
808- const auto raw = item. get_raw_item ();
812+ const auto raw = item-> get_raw_item ();
809813 if (raw->get_trait_item_type ()
810814 != Resolver::TraitItemReference::TraitItemType::TYPE)
811815 return TypeBoundPredicateItem::error ();
812816 }
813- return item;
817+ return item. value () ;
814818}
815819
816820std::vector<TypeBoundPredicateItem>
0 commit comments