[PR testsuite/116860] Testsuite adjustment for recently added tests
[official-gcc.git] / gcc / rust / typecheck / rust-tyty-subst.cc
blobf9f11a0651b651444af235a0a3e1f332fbefc625
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
8 // version.
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 // for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 #include "rust-tyty-subst.h"
21 #include "rust-system.h"
22 #include "rust-tyty.h"
23 #include "rust-hir-type-check.h"
24 #include "rust-substitution-mapper.h"
25 #include "rust-hir-type-check-type.h"
26 #include "rust-type-util.h"
28 namespace Rust {
29 namespace TyTy {
31 SubstitutionParamMapping::SubstitutionParamMapping (
32 const HIR::TypeParam &generic, ParamType *param)
33 : generic (generic), param (param)
36 SubstitutionParamMapping::SubstitutionParamMapping (
37 const SubstitutionParamMapping &other)
38 : generic (other.generic), param (other.param)
41 std::string
42 SubstitutionParamMapping::as_string () const
44 if (param == nullptr)
45 return "nullptr";
47 return param->get_name ();
50 SubstitutionParamMapping
51 SubstitutionParamMapping::clone () const
53 return SubstitutionParamMapping (generic,
54 static_cast<ParamType *> (param->clone ()));
57 ParamType *
58 SubstitutionParamMapping::get_param_ty ()
60 return param;
63 const ParamType *
64 SubstitutionParamMapping::get_param_ty () const
66 return param;
69 const HIR::TypeParam &
70 SubstitutionParamMapping::get_generic_param () const
72 return generic;
75 bool
76 SubstitutionParamMapping::needs_substitution () const
78 return !(get_param_ty ()->is_concrete ());
81 location_t
82 SubstitutionParamMapping::get_param_locus () const
84 return generic.get_locus ();
87 bool
88 SubstitutionParamMapping::param_has_default_ty () const
90 return generic.has_type ();
93 BaseType *
94 SubstitutionParamMapping::get_default_ty () const
96 TyVar var (generic.get_type_mappings ().get_hirid ());
97 return var.get_tyty ();
100 bool
101 SubstitutionParamMapping::need_substitution () const
103 if (!param->can_resolve ())
104 return true;
106 auto resolved = param->resolve ();
107 return !resolved->is_concrete ();
110 bool
111 SubstitutionParamMapping::fill_param_ty (
112 SubstitutionArgumentMappings &subst_mappings, location_t locus)
114 SubstitutionArg arg = SubstitutionArg::error ();
115 bool ok = subst_mappings.get_argument_for_symbol (get_param_ty (), &arg);
116 if (!ok)
117 return true;
119 TyTy::BaseType &type = *arg.get_tyty ();
120 if (type.get_kind () == TyTy::TypeKind::INFER)
122 type.inherit_bounds (*param);
125 if (type.get_kind () == TypeKind::PARAM)
127 // delete param;
128 param = static_cast<ParamType *> (type.clone ());
130 else
132 // check the substitution is compatible with bounds
133 rust_debug_loc (locus,
134 "fill_param_ty bounds_compatible: param %s type %s",
135 param->get_name ().c_str (), type.get_name ().c_str ());
137 if (!param->is_implicit_self_trait ())
139 if (!param->bounds_compatible (type, locus, true))
140 return false;
143 // recursively pass this down to all HRTB's
144 for (auto &bound : param->get_specified_bounds ())
145 bound.handle_substitions (subst_mappings);
147 param->set_ty_ref (type.get_ref ());
148 subst_mappings.on_param_subst (*param, arg);
151 return true;
154 void
155 SubstitutionParamMapping::override_context ()
157 if (!param->can_resolve ())
158 return;
160 auto mappings = Analysis::Mappings::get ();
161 auto context = Resolver::TypeCheckContext::get ();
163 context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (),
164 UNKNOWN_NODEID,
165 param->get_ref (),
166 UNKNOWN_LOCAL_DEFID),
167 param->resolve ());
170 SubstitutionArg::SubstitutionArg (const SubstitutionParamMapping *param,
171 BaseType *argument)
172 : param (param), argument (argument)
174 if (param != nullptr)
175 original_param = param->get_param_ty ();
178 SubstitutionArg::SubstitutionArg (const SubstitutionArg &other)
179 : param (other.param), original_param (other.original_param),
180 argument (other.argument)
183 SubstitutionArg &
184 SubstitutionArg::operator= (const SubstitutionArg &other)
186 param = other.param;
187 argument = other.argument;
188 original_param = other.original_param;
190 return *this;
193 BaseType *
194 SubstitutionArg::get_tyty ()
196 return argument;
199 const BaseType *
200 SubstitutionArg::get_tyty () const
202 return argument;
205 const SubstitutionParamMapping *
206 SubstitutionArg::get_param_mapping () const
208 return param;
211 const ParamType *
212 SubstitutionArg::get_param_ty () const
214 return original_param;
217 SubstitutionArg
218 SubstitutionArg::error ()
220 return SubstitutionArg (nullptr, nullptr);
223 bool
224 SubstitutionArg::is_error () const
226 return param == nullptr || argument == nullptr;
229 bool
230 SubstitutionArg::is_conrete () const
232 if (argument == nullptr)
233 return false;
235 if (argument->get_kind () == TyTy::TypeKind::PARAM)
236 return false;
238 return argument->is_concrete ();
241 std::string
242 SubstitutionArg::as_string () const
244 return original_param->as_string ()
245 + (argument != nullptr ? ":" + argument->as_string () : "");
248 const RegionParamList &
249 SubstitutionArgumentMappings::get_regions () const
251 return regions;
254 RegionParamList &
255 SubstitutionArgumentMappings::get_mut_regions ()
257 return regions;
260 // SubstitutionArgumentMappings
262 SubstitutionArgumentMappings::SubstitutionArgumentMappings (
263 std::vector<SubstitutionArg> mappings,
264 std::map<std::string, BaseType *> binding_args, RegionParamList regions,
265 location_t locus, ParamSubstCb param_subst_cb, bool trait_item_flag,
266 bool error_flag)
267 : mappings (std::move (mappings)), binding_args (binding_args),
268 regions (regions), locus (locus), param_subst_cb (param_subst_cb),
269 trait_item_flag (trait_item_flag), error_flag (error_flag)
272 SubstitutionArgumentMappings::SubstitutionArgumentMappings (
273 const SubstitutionArgumentMappings &other)
274 : mappings (other.mappings), binding_args (other.binding_args),
275 regions (other.regions), locus (other.locus), param_subst_cb (nullptr),
276 trait_item_flag (other.trait_item_flag), error_flag (other.error_flag)
279 SubstitutionArgumentMappings &
280 SubstitutionArgumentMappings::operator= (
281 const SubstitutionArgumentMappings &other)
283 mappings = other.mappings;
284 binding_args = other.binding_args;
285 regions = other.regions;
286 locus = other.locus;
287 param_subst_cb = nullptr;
288 trait_item_flag = other.trait_item_flag;
289 error_flag = other.error_flag;
291 return *this;
294 SubstitutionArgumentMappings
295 SubstitutionArgumentMappings::error ()
297 return SubstitutionArgumentMappings ({}, {}, 0, UNDEF_LOCATION, nullptr,
298 false, true);
301 SubstitutionArgumentMappings
302 SubstitutionArgumentMappings::empty (size_t num_regions)
304 return SubstitutionArgumentMappings ({}, {}, num_regions, UNDEF_LOCATION,
305 nullptr, false, false);
308 bool
309 SubstitutionArgumentMappings::is_error () const
311 return error_flag;
314 bool
315 SubstitutionArgumentMappings::get_argument_for_symbol (
316 const ParamType *param_to_find, SubstitutionArg *argument) const
318 for (const auto &mapping : mappings)
320 const ParamType *p = mapping.get_param_ty ();
321 if (p->get_symbol () == param_to_find->get_symbol ())
323 *argument = mapping;
324 return true;
327 return false;
329 tl::optional<size_t>
330 SubstitutionArgumentMappings::find_symbol (const ParamType &param_to_find) const
332 auto it = std::find_if (mappings.begin (), mappings.end (),
333 [param_to_find] (const SubstitutionArg &arg) {
334 return arg.get_param_ty ()->get_symbol ()
335 == param_to_find.get_symbol ();
337 if (it == mappings.end ())
338 return tl::nullopt;
339 return std::distance (mappings.begin (), it);
342 bool
343 SubstitutionArgumentMappings::get_argument_at (size_t index,
344 SubstitutionArg *argument)
346 if (index > mappings.size ())
347 return false;
349 *argument = mappings.at (index);
350 return true;
353 bool
354 SubstitutionArgumentMappings::is_concrete () const
356 for (auto &mapping : mappings)
358 if (!mapping.is_conrete ())
359 return false;
361 return true;
364 location_t
365 SubstitutionArgumentMappings::get_locus () const
367 return locus;
370 size_t
371 SubstitutionArgumentMappings::size () const
373 return mappings.size ();
376 bool
377 SubstitutionArgumentMappings::is_empty () const
379 return size () == 0;
382 std::vector<SubstitutionArg> &
383 SubstitutionArgumentMappings::get_mappings ()
385 return mappings;
388 const std::vector<SubstitutionArg> &
389 SubstitutionArgumentMappings::get_mappings () const
391 return mappings;
394 std::map<std::string, BaseType *> &
395 SubstitutionArgumentMappings::get_binding_args ()
397 return binding_args;
400 const std::map<std::string, BaseType *> &
401 SubstitutionArgumentMappings::get_binding_args () const
403 return binding_args;
406 std::string
407 SubstitutionArgumentMappings::as_string () const
409 std::string buffer;
410 for (auto &mapping : mappings)
412 buffer += mapping.as_string () + ", ";
414 return "<" + buffer + ">";
417 void
418 SubstitutionArgumentMappings::on_param_subst (const ParamType &p,
419 const SubstitutionArg &a) const
421 if (param_subst_cb == nullptr)
422 return;
424 param_subst_cb (p, a);
427 ParamSubstCb
428 SubstitutionArgumentMappings::get_subst_cb () const
430 return param_subst_cb;
433 bool
434 SubstitutionArgumentMappings::trait_item_mode () const
436 return trait_item_flag;
439 // SubstitutionRef
441 SubstitutionRef::SubstitutionRef (
442 std::vector<SubstitutionParamMapping> substitutions,
443 SubstitutionArgumentMappings arguments, RegionConstraints region_constraints)
444 : substitutions (substitutions), used_arguments (arguments),
445 region_constraints (region_constraints)
448 bool
449 SubstitutionRef::has_substitutions () const
451 return substitutions.size () > 0;
454 std::string
455 SubstitutionRef::subst_as_string () const
457 std::string buffer;
458 for (size_t i = 0; i < substitutions.size (); i++)
460 const SubstitutionParamMapping &sub = substitutions.at (i);
461 buffer += sub.as_string ();
463 if ((i + 1) < substitutions.size ())
464 buffer += ", ";
467 return buffer.empty () ? "" : "<" + buffer + ">";
470 bool
471 SubstitutionRef::supports_associated_bindings () const
473 return get_num_associated_bindings () > 0;
476 size_t
477 SubstitutionRef::get_num_associated_bindings () const
479 return 0;
482 TypeBoundPredicateItem
483 SubstitutionRef::lookup_associated_type (const std::string &search)
485 return TypeBoundPredicateItem::error ();
488 size_t
489 SubstitutionRef::get_num_substitutions () const
491 return substitutions.size ();
493 size_t
494 SubstitutionRef::get_num_lifetime_params () const
496 return used_arguments.get_regions ().size ();
498 size_t
499 SubstitutionRef::get_num_type_params () const
501 return get_num_substitutions ();
504 std::vector<SubstitutionParamMapping> &
505 SubstitutionRef::get_substs ()
507 return substitutions;
510 const std::vector<SubstitutionParamMapping> &
511 SubstitutionRef::get_substs () const
513 return substitutions;
516 std::vector<SubstitutionParamMapping>
517 SubstitutionRef::clone_substs () const
519 std::vector<SubstitutionParamMapping> clone;
521 for (auto &sub : substitutions)
522 clone.push_back (sub.clone ());
524 return clone;
527 void
528 SubstitutionRef::override_context ()
530 for (auto &sub : substitutions)
532 sub.override_context ();
536 bool
537 SubstitutionRef::needs_substitution () const
539 return std::any_of (substitutions.begin (), substitutions.end (),
540 std::mem_fn (
541 &SubstitutionParamMapping::needs_substitution));
544 bool
545 SubstitutionRef::was_substituted () const
547 return !needs_substitution ();
550 SubstitutionArgumentMappings &
551 SubstitutionRef::get_substitution_arguments ()
553 return used_arguments;
556 const SubstitutionArgumentMappings &
557 SubstitutionRef::get_substitution_arguments () const
559 return used_arguments;
562 size_t
563 SubstitutionRef::num_required_substitutions () const
565 size_t n = 0;
566 for (auto &p : substitutions)
568 if (p.needs_substitution ())
569 n++;
571 return n;
574 size_t
575 SubstitutionRef::min_required_substitutions () const
577 size_t n = 0;
578 for (auto &p : substitutions)
580 if (p.needs_substitution () && !p.param_has_default_ty ())
581 n++;
583 return n;
586 const SubstitutionArgumentMappings &
587 SubstitutionRef::get_used_arguments () const
589 return used_arguments;
592 tl::optional<SubstitutionArg>
593 SubstitutionRef::get_arg_at (size_t i) const
595 auto param_ty = get_substs ().at (i).get_param_ty ();
596 SubstitutionArg arg = SubstitutionArg::error ();
597 get_used_arguments ().get_argument_for_symbol (param_ty, &arg);
598 if (arg.is_error ())
599 return tl::nullopt;
600 return arg;
603 const RegionConstraints &
604 SubstitutionRef::get_region_constraints () const
606 return region_constraints;
609 SubstitutionArgumentMappings
610 SubstitutionRef::get_mappings_from_generic_args (
611 HIR::GenericArgs &args, const std::vector<Region> &regions)
613 std::map<std::string, BaseType *> binding_arguments;
614 if (args.get_binding_args ().size () > 0)
616 if (supports_associated_bindings ())
618 if (args.get_binding_args ().size () > get_num_associated_bindings ())
620 rich_location r (line_table, args.get_locus ());
622 rust_error_at (r,
623 "generic item takes at most %lu type binding "
624 "arguments but %lu were supplied",
625 (unsigned long) get_num_associated_bindings (),
626 (unsigned long) args.get_binding_args ().size ());
627 return SubstitutionArgumentMappings::error ();
630 for (auto &binding : args.get_binding_args ())
632 BaseType *resolved
633 = Resolver::TypeCheckType::Resolve (binding.get_type ().get ());
634 if (resolved == nullptr
635 || resolved->get_kind () == TyTy::TypeKind::ERROR)
637 rust_error_at (binding.get_locus (),
638 "failed to resolve type arguments");
639 return SubstitutionArgumentMappings::error ();
642 // resolve to relevant binding
643 auto binding_item = lookup_associated_type (
644 binding.get_identifier ().as_string ());
645 if (binding_item.is_error ())
647 rust_error_at (
648 binding.get_locus (), "unknown associated type binding: %s",
649 binding.get_identifier ().as_string ().c_str ());
650 return SubstitutionArgumentMappings::error ();
653 binding_arguments[binding.get_identifier ().as_string ()]
654 = resolved;
657 else
659 rich_location r (line_table, args.get_locus ());
660 for (auto &binding : args.get_binding_args ())
661 r.add_range (binding.get_locus ());
663 rust_error_at (r, ErrorCode::E0229,
664 "associated type bindings are not allowed here");
665 return SubstitutionArgumentMappings::error ();
669 // for inherited arguments
670 size_t offs = used_arguments.size ();
671 if (args.get_type_args ().size () + offs > substitutions.size ())
673 rich_location r (line_table, args.get_locus ());
674 if (!substitutions.empty ())
675 r.add_range (substitutions.front ().get_param_locus ());
677 rust_error_at (
679 "generic item takes at most %lu type arguments but %lu were supplied",
680 (unsigned long) substitutions.size (),
681 (unsigned long) args.get_type_args ().size ());
682 return SubstitutionArgumentMappings::error ();
685 if (args.get_type_args ().size () + offs < min_required_substitutions ())
687 rich_location r (line_table, args.get_locus ());
688 r.add_range (substitutions.front ().get_param_locus ());
690 rust_error_at (
691 r, ErrorCode::E0107,
692 "generic item takes at least %lu type arguments but %lu were supplied",
693 (unsigned long) (min_required_substitutions () - offs),
694 (unsigned long) args.get_type_args ().size ());
695 return SubstitutionArgumentMappings::error ();
698 std::vector<SubstitutionArg> mappings = used_arguments.get_mappings ();
699 for (auto &arg : args.get_type_args ())
701 BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ());
702 if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR)
704 rust_error_at (args.get_locus (), "failed to resolve type arguments");
705 return SubstitutionArgumentMappings::error ();
708 SubstitutionArg subst_arg (&substitutions.at (offs), resolved);
709 offs++;
710 mappings.push_back (std::move (subst_arg));
713 // we must need to fill out defaults
714 size_t left_over
715 = num_required_substitutions () - min_required_substitutions ();
716 if (left_over > 0)
718 for (size_t offs = mappings.size (); offs < substitutions.size (); offs++)
720 SubstitutionParamMapping &param = substitutions.at (offs);
721 rust_assert (param.param_has_default_ty ());
723 BaseType *resolved = param.get_default_ty ();
724 if (resolved->get_kind () == TypeKind::ERROR)
725 return SubstitutionArgumentMappings::error ();
727 // this resolved default might already contain default parameters
728 if (!resolved->is_concrete ())
730 SubstitutionArgumentMappings intermediate (
731 mappings, binding_arguments,
732 {used_arguments.get_regions ().size ()}, args.get_locus ());
733 resolved = Resolver::SubstMapperInternal::Resolve (resolved,
734 intermediate);
736 if (resolved->get_kind () == TypeKind::ERROR)
737 return SubstitutionArgumentMappings::error ();
740 SubstitutionArg subst_arg (&param, resolved);
741 mappings.push_back (std::move (subst_arg));
745 return {mappings, binding_arguments,
746 RegionParamList::from_subst (used_arguments.get_regions ().size (),
747 regions),
748 args.get_locus ()};
751 BaseType *
752 SubstitutionRef::infer_substitions (location_t locus)
754 std::vector<SubstitutionArg> args;
755 std::map<std::string, BaseType *> argument_mappings;
756 for (auto &p : get_substs ())
758 if (p.needs_substitution ())
760 const std::string &symbol = p.get_param_ty ()->get_symbol ();
761 auto it = argument_mappings.find (symbol);
762 bool have_mapping = it != argument_mappings.end ();
764 if (have_mapping)
766 args.push_back (SubstitutionArg (&p, it->second));
768 else
770 TyVar infer_var = TyVar::get_implicit_infer_var (locus);
771 args.push_back (SubstitutionArg (&p, infer_var.get_tyty ()));
772 argument_mappings[symbol] = infer_var.get_tyty ();
775 else
777 args.push_back (SubstitutionArg (&p, p.get_param_ty ()->resolve ()));
781 // FIXME do we need to add inference variables to all the possible bindings?
782 // it might just lead to inference variable hell not 100% sure if rustc does
783 // this i think the language might needs this to be explicitly set
785 SubstitutionArgumentMappings infer_arguments (std::move (args),
786 {} /* binding_arguments */,
787 used_arguments.get_regions (),
788 locus);
789 return handle_substitions (infer_arguments);
792 SubstitutionArgumentMappings
793 SubstitutionRef::adjust_mappings_for_this (
794 SubstitutionArgumentMappings &mappings)
796 std::vector<SubstitutionArg> resolved_mappings;
797 for (size_t i = 0; i < substitutions.size (); i++)
799 auto &subst = substitutions.at (i);
801 SubstitutionArg arg = SubstitutionArg::error ();
802 if (mappings.size () == substitutions.size ())
804 mappings.get_argument_at (i, &arg);
806 else
808 if (subst.needs_substitution ())
810 // get from passed in mappings
811 mappings.get_argument_for_symbol (subst.get_param_ty (), &arg);
813 else
815 // we should already have this somewhere
816 used_arguments.get_argument_for_symbol (subst.get_param_ty (),
817 &arg);
821 bool ok = !arg.is_error ();
822 if (ok)
824 SubstitutionArg adjusted (&subst, arg.get_tyty ());
825 resolved_mappings.push_back (std::move (adjusted));
829 if (resolved_mappings.empty ())
830 return SubstitutionArgumentMappings::error ();
832 return SubstitutionArgumentMappings (resolved_mappings,
833 mappings.get_binding_args (),
834 mappings.get_regions (),
835 mappings.get_locus (),
836 mappings.get_subst_cb (),
837 mappings.trait_item_mode ());
840 bool
841 SubstitutionRef::are_mappings_bound (SubstitutionArgumentMappings &mappings)
843 std::vector<SubstitutionArg> resolved_mappings;
844 for (size_t i = 0; i < substitutions.size (); i++)
846 auto &subst = substitutions.at (i);
848 SubstitutionArg arg = SubstitutionArg::error ();
849 if (mappings.size () == substitutions.size ())
851 mappings.get_argument_at (i, &arg);
853 else
855 if (subst.needs_substitution ())
857 // get from passed in mappings
858 mappings.get_argument_for_symbol (subst.get_param_ty (), &arg);
860 else
862 // we should already have this somewhere
863 used_arguments.get_argument_for_symbol (subst.get_param_ty (),
864 &arg);
868 bool ok = !arg.is_error ();
869 if (ok)
871 SubstitutionArg adjusted (&subst, arg.get_tyty ());
872 resolved_mappings.push_back (std::move (adjusted));
876 return !resolved_mappings.empty ();
879 // this function assumes that the mappings being passed are for the same type as
880 // this new substitution reference so ordering matters here
881 SubstitutionArgumentMappings
882 SubstitutionRef::solve_mappings_from_receiver_for_self (
883 SubstitutionArgumentMappings &mappings) const
885 std::vector<SubstitutionArg> resolved_mappings;
887 rust_assert (mappings.size () == get_num_substitutions ());
888 for (size_t i = 0; i < get_num_substitutions (); i++)
890 const SubstitutionParamMapping &param_mapping = substitutions.at (i);
891 SubstitutionArg &arg = mappings.get_mappings ().at (i);
893 if (param_mapping.needs_substitution ())
895 SubstitutionArg adjusted (&param_mapping, arg.get_tyty ());
896 resolved_mappings.push_back (std::move (adjusted));
900 return SubstitutionArgumentMappings (resolved_mappings,
901 mappings.get_binding_args (),
902 mappings.get_regions (),
903 mappings.get_locus ());
906 void
907 SubstitutionRef::prepare_higher_ranked_bounds ()
909 for (const auto &subst : get_substs ())
911 const TyTy::ParamType *pty = subst.get_param_ty ();
912 for (const auto &bound : pty->get_specified_bounds ())
914 const auto ref = bound.get ();
915 ref->clear_associated_type_projections ();
920 bool
921 SubstitutionRef::monomorphize ()
923 for (const auto &subst : get_substs ())
925 const TyTy::ParamType *pty = subst.get_param_ty ();
927 if (!pty->can_resolve ())
928 continue;
930 const TyTy::BaseType *binding = pty->resolve ();
931 if (binding->get_kind () == TyTy::TypeKind::PARAM)
932 continue;
934 for (const auto &bound : pty->get_specified_bounds ())
936 bool ambigious = false;
937 auto associated
938 = Resolver::lookup_associated_impl_block (bound, binding,
939 &ambigious);
940 if (associated == nullptr && ambigious)
942 // go for the first one? or error out?
943 auto &mappings = *Analysis::Mappings::get ();
944 const auto &type_param = subst.get_generic_param ();
945 const auto *trait_ref = bound.get ();
947 rich_location r (line_table, type_param.get_locus ());
948 r.add_range (bound.get_locus ());
949 r.add_range (mappings.lookup_location (binding->get_ref ()));
951 rust_error_at (r, "ambiguous type bound for trait %s and type %s",
952 trait_ref->get_name ().c_str (),
953 binding->get_name ().c_str ());
954 return false;
957 if (associated != nullptr)
959 associated->setup_associated_types (binding, bound);
964 return true;
967 } // namespace TyTy
968 } // namespace Rust