Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
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.
9 :
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.
14 :
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/>.
18 :
19 : #include "rust-hir-type-check-type.h"
20 : #include "options.h"
21 : #include "optional.h"
22 : #include "rich-location.h"
23 : #include "rust-hir-map.h"
24 : #include "rust-hir-trait-resolve.h"
25 : #include "rust-hir-type-check-expr.h"
26 : #include "rust-hir-path-probe-type.h"
27 : #include "rust-finalized-name-resolution-context.h"
28 : #include "rust-mapping-common.h"
29 : #include "rust-rib.h"
30 : #include "rust-substitution-mapper.h"
31 : #include "rust-type-util.h"
32 : #include "rust-system.h"
33 : #include "rust-compile-base.h"
34 : #include "rust-resolve-builtins.h"
35 : #include "rust-tyty.h"
36 : #include "text-range-label.h"
37 :
38 : namespace Rust {
39 : namespace Resolver {
40 :
41 : HIR::GenericArgs
42 0 : TypeCheckResolveGenericArguments::resolve (HIR::TypePathSegment &segment)
43 : {
44 0 : TypeCheckResolveGenericArguments resolver (segment.get_locus ());
45 0 : switch (segment.get_type ())
46 : {
47 0 : case HIR::TypePathSegment::SegmentType::GENERIC:
48 0 : resolver.visit (static_cast<HIR::TypePathSegmentGeneric &> (segment));
49 0 : break;
50 :
51 : default:
52 : break;
53 : }
54 0 : return resolver.args;
55 0 : }
56 :
57 : void
58 0 : TypeCheckResolveGenericArguments::visit (HIR::TypePathSegmentGeneric &generic)
59 : {
60 0 : args = generic.get_generic_args ();
61 0 : }
62 :
63 : TyTy::BaseType *
64 711591 : TypeCheckType::Resolve (HIR::Type &type, ResolutionMode mode)
65 : {
66 : // is it already resolved?
67 711591 : auto context = TypeCheckContext::get ();
68 711591 : TyTy::BaseType *resolved = nullptr;
69 711591 : bool already_resolved
70 711591 : = context->lookup_type (type.get_mappings ().get_hirid (), &resolved);
71 711591 : if (already_resolved && mode == ResolutionMode::REFERENCE)
72 250367 : return resolved;
73 :
74 461224 : TypeCheckType resolver (type.get_mappings ().get_hirid (), mode);
75 461224 : type.accept_vis (resolver);
76 461124 : rust_assert (resolver.translated != nullptr);
77 461124 : resolver.context->insert_type (type.get_mappings (), resolver.translated);
78 461124 : return resolver.translated;
79 461124 : }
80 :
81 : void
82 5995 : TypeCheckType::visit (HIR::BareFunctionType &fntype)
83 : {
84 5995 : auto binder_pin = context->push_lifetime_binder ();
85 5997 : for (auto &lifetime_param : fntype.get_for_lifetimes ())
86 : {
87 2 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
88 : }
89 :
90 5995 : TyTy::BaseType *return_type;
91 5995 : if (fntype.has_return_type ())
92 : {
93 5942 : return_type = TypeCheckType::Resolve (fntype.get_return_type ());
94 : }
95 : else
96 : {
97 : // needs a new implicit ID
98 53 : HirId ref = mappings.get_next_hir_id ();
99 53 : return_type = TyTy::TupleType::get_unit_type ();
100 53 : context->insert_implicit_type (ref, return_type);
101 : }
102 :
103 5995 : std::vector<TyTy::TyVar> params;
104 5995 : params.reserve (fntype.get_function_params ().size ());
105 :
106 42159 : for (auto ¶m : fntype.get_function_params ())
107 : {
108 36164 : TyTy::BaseType *ptype = TypeCheckType::Resolve (param.get_type ());
109 36164 : params.emplace_back (ptype->get_ref ());
110 : }
111 :
112 5995 : translated
113 11990 : = new TyTy::FnPtr (fntype.get_mappings ().get_hirid (), fntype.get_locus (),
114 : std::move (params),
115 5995 : TyTy::TyVar (return_type->get_ref ()),
116 5995 : fntype.get_function_qualifiers ().get_abi (),
117 23980 : fntype.get_function_qualifiers ().get_unsafety ());
118 5995 : }
119 :
120 : void
121 5093 : TypeCheckType::visit (HIR::TupleType &tuple)
122 : {
123 5093 : if (tuple.is_unit_type ())
124 : {
125 592 : translated = TyTy::TupleType::get_unit_type ();
126 592 : return;
127 : }
128 :
129 4501 : std::vector<TyTy::TyVar> fields;
130 4501 : fields.reserve (tuple.get_elems ().size ());
131 :
132 13077 : for (auto &elem : tuple.get_elems ())
133 : {
134 8576 : auto field_ty = TypeCheckType::Resolve (*elem);
135 8576 : fields.emplace_back (field_ty->get_ref ());
136 : }
137 :
138 9002 : translated = new TyTy::TupleType (tuple.get_mappings ().get_hirid (),
139 13503 : tuple.get_locus (), fields);
140 4501 : }
141 :
142 : void
143 359885 : TypeCheckType::visit (HIR::TypePath &path)
144 : {
145 : // this can happen so we need to look up the root then resolve the
146 : // remaining segments if possible
147 359885 : bool wasBigSelf = false;
148 359885 : size_t offset = 0;
149 359885 : TyTy::BaseType *root = resolve_root_path (path, &offset, &wasBigSelf);
150 359852 : if (root->get_kind () == TyTy::TypeKind::ERROR)
151 : {
152 11 : rust_debug_loc (path.get_locus (), "failed to resolve type-path type");
153 356383 : return;
154 : }
155 :
156 359841 : TyTy::BaseType *path_type = root;
157 359841 : if (mode == ResolutionMode::REFERENCE)
158 : {
159 : // A recursive path must keep referring to the in-progress nominal ADT.
160 : // Cloning its currently empty variant list would leave a permanently
161 : // incomplete snapshot in the recursive field.
162 346333 : auto *root_adt = root->try_as<TyTy::ADTType> ();
163 56178 : bool recursive_root
164 56178 : = root_adt != nullptr && root_adt->get_variants ().empty ();
165 345792 : if (!recursive_root)
166 : {
167 345792 : path_type = root->clone ();
168 345792 : path_type->set_ref (path.get_mappings ().get_hirid ());
169 : }
170 346333 : context->insert_implicit_type (path.get_mappings ().get_hirid (),
171 : path_type);
172 : }
173 :
174 359841 : bool fully_resolved = offset >= path.get_segments ().size ();
175 359841 : if (fully_resolved)
176 : {
177 356372 : translated = path_type;
178 356372 : rust_debug_loc (path.get_locus (), "root resolved type-path to: [%s]",
179 : translated->debug_str ().c_str ());
180 : return;
181 : }
182 :
183 3469 : translated
184 3469 : = resolve_segments (path.get_mappings ().get_hirid (), path.get_segments (),
185 3469 : offset, path_type, path.get_mappings (),
186 3469 : path.get_locus (), wasBigSelf);
187 :
188 3469 : if (auto p = translated->try_as<TyTy::ProjectionType> ())
189 3466 : translated
190 3466 : = normalize_projection (p, path.get_locus (), false /*emit errors*/,
191 : false /*unify self*/);
192 :
193 3469 : rust_debug_loc (path.get_locus (), "resolved type-path to: [%s]",
194 : translated->debug_str ().c_str ());
195 : }
196 :
197 : void
198 26869 : TypeCheckType::visit (HIR::QualifiedPathInType &path)
199 : {
200 26869 : HIR::QualifiedPathType qual_path_type = path.get_path_type ();
201 26869 : TyTy::BaseType *root = TypeCheckType::Resolve (qual_path_type.get_type ());
202 26869 : if (root->get_kind () == TyTy::TypeKind::ERROR)
203 : {
204 0 : rust_debug_loc (path.get_locus (), "failed to resolve the root");
205 : return;
206 : }
207 :
208 26869 : if (!qual_path_type.has_as_clause ())
209 : {
210 1 : translated
211 1 : = resolve_segments (path.get_mappings ().get_hirid (),
212 : path.get_segments (), 0, translated,
213 1 : path.get_mappings (), path.get_locus (), false);
214 :
215 1 : return;
216 : }
217 :
218 : // Resolve the trait now
219 26868 : auto &trait_path_ref = qual_path_type.get_trait ();
220 26868 : TraitReference *trait_ref = TraitResolver::Resolve (trait_path_ref);
221 26868 : if (trait_ref->is_error ())
222 : return;
223 :
224 : // get the predicate for the bound
225 26868 : auto specified_bound
226 : = get_predicate_from_bound (qual_path_type.get_trait (),
227 26868 : qual_path_type.get_type (),
228 26868 : BoundPolarity::RegularBound, true);
229 26868 : if (specified_bound.is_error ())
230 : return;
231 :
232 : // inherit the bound
233 26868 : root->inherit_bound (specified_bound);
234 :
235 : // lookup the associated item from the specified bound
236 26868 : HIR::TypePathSegment &item_seg = path.get_associated_segment ();
237 26868 : HIR::PathIdentSegment item_seg_identifier = item_seg.get_ident_segment ();
238 26868 : tl::optional<TyTy::TypeBoundPredicateItem> item
239 26868 : = specified_bound.lookup_associated_item (item_seg_identifier.to_string ());
240 26868 : if (!item.has_value ())
241 : {
242 1 : std::string item_seg_ident_name, rich_msg;
243 1 : item_seg_ident_name = qual_path_type.get_trait ().to_string ();
244 2 : rich_msg = "not found in `" + item_seg_ident_name + "`";
245 :
246 1 : rich_location richloc (line_table, item_seg.get_locus ());
247 1 : richloc.add_fixit_replace (rich_msg.c_str ());
248 :
249 2 : rust_error_at (richloc, ErrorCode::E0576,
250 : "cannot find associated type %qs in trait %qs",
251 1 : item_seg_identifier.to_string ().c_str (),
252 : item_seg_ident_name.c_str ());
253 1 : return;
254 1 : }
255 :
256 : // Build projection via the predicates own rebasing helper so the
257 : // projection's substitutions are populated with the trait-coord args from
258 : // the qualified path:
259 : // (<Bar<i32> as Foo<i32>>::A -> Projection Self=Bar<i32>, T=i32)
260 26867 : TyTy::BaseType *rebased_item = item->get_tyty_for_receiver (root);
261 26867 : if (auto *proj = rebased_item->try_as<TyTy::ProjectionType> ())
262 26867 : translated
263 26867 : = normalize_projection (proj, path.get_locus (), false /*emit errors*/,
264 : false /*unify self*/);
265 : else
266 : translated = rebased_item;
267 :
268 : // like a TypePath, give the result its own ref so &T and *T look up the
269 : // substituted type and not the one the impl declared
270 26801 : translated = translated->clone ();
271 26801 : translated->set_ref (path.get_mappings ().get_hirid ());
272 :
273 : // turbo-fish segment path::<ty>
274 26801 : if (item_seg.get_type () == HIR::TypePathSegment::SegmentType::GENERIC)
275 : {
276 7 : auto &generic_seg = static_cast<HIR::TypePathSegmentGeneric &> (item_seg);
277 :
278 : // turbo-fish segment path::<ty>
279 7 : if (generic_seg.has_generic_args ())
280 : {
281 7 : if (!translated->has_substitutions_defined ())
282 : {
283 0 : rust_error_at (item_seg.get_locus (),
284 : "substitutions not supported for %s",
285 0 : translated->as_string ().c_str ());
286 0 : translated
287 0 : = new TyTy::ErrorType (path.get_mappings ().get_hirid ());
288 0 : return;
289 : }
290 7 : translated
291 7 : = SubstMapper::Resolve (translated, path.get_locus (),
292 7 : &generic_seg.get_generic_args (),
293 7 : context->regions_from_generic_args (
294 7 : generic_seg.get_generic_args ()));
295 :
296 : // unwrap the sweets
297 7 : if (auto *proj = translated->try_as<TyTy::ProjectionType> ())
298 7 : if (!proj->is_trait_position () && proj->get () != nullptr)
299 7 : translated = proj->get ();
300 : }
301 : }
302 :
303 : // continue on as a path-in-expression
304 26801 : bool fully_resolved = path.get_segments ().empty ();
305 26801 : if (fully_resolved)
306 : return;
307 :
308 0 : translated
309 0 : = resolve_segments (path.get_mappings ().get_hirid (), path.get_segments (),
310 0 : 0, translated, path.get_mappings (), path.get_locus (),
311 : false);
312 53605 : }
313 :
314 : TyTy::BaseType *
315 359885 : TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
316 : bool *wasBigSelf)
317 : {
318 359885 : TyTy::BaseType *root_tyty = nullptr;
319 359885 : *offset = 0;
320 :
321 715060 : for (size_t i = 0; i < path.get_num_segments (); i++)
322 : {
323 364378 : std::unique_ptr<HIR::TypePathSegment> &seg = path.get_segments ().at (i);
324 :
325 364378 : bool have_more_segments = (path.get_num_segments () - 1 != i);
326 364378 : bool is_root = *offset == 0;
327 364378 : NodeId ast_node_id = seg->get_mappings ().get_nodeid ();
328 :
329 : // then lookup the reference_node_id
330 364378 : NodeId ref_node_id = UNKNOWN_NODEID;
331 :
332 364378 : if (seg->is_lang_item ())
333 50 : ref_node_id = Analysis::Mappings::get ().get_lang_item_node (
334 50 : seg->get_lang_item ());
335 : else
336 : {
337 364328 : auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get ();
338 :
339 : // assign the ref_node_id if we've found something
340 364328 : nr_ctx.lookup (ast_node_id, Resolver2_0::Namespace::Types)
341 725188 : .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
342 :
343 : // TODO: Should we add a special method to the name resolver to handle
344 : // that case? Resolving something in the Types NS when we want to
345 : // prioritize builtin types over modules or other conflicting things?
346 728656 : if (auto builtin_type_id
347 364328 : = Resolver2_0::Builtins::find_builtin_node_id (seg->to_string ()))
348 198303 : if (mappings.is_module (ref_node_id))
349 156 : ref_node_id = builtin_type_id.value ();
350 : }
351 :
352 : // ref_node_id is the NodeId that the segments refers to.
353 364378 : if (ref_node_id == UNKNOWN_NODEID)
354 : {
355 3468 : if (is_root)
356 : {
357 0 : rust_error_at (seg->get_locus (),
358 : "unknown reference for resolved name: %qs",
359 0 : seg->to_string ().c_str ());
360 0 : return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
361 : }
362 3468 : else if (root_tyty == nullptr)
363 : {
364 1 : rust_error_at (seg->get_locus (),
365 : "unknown reference for resolved name: %qs",
366 1 : seg->to_string ().c_str ());
367 1 : return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
368 : }
369 : return root_tyty;
370 : }
371 :
372 360910 : if (seg->is_ident_only () && seg->to_string () == "Self")
373 18171 : *wasBigSelf = true;
374 :
375 : // node back to HIR
376 360910 : tl::optional<HirId> hid = mappings.lookup_node_to_hir (ref_node_id);
377 360910 : if (!hid.has_value ())
378 : {
379 0 : if (is_root)
380 : {
381 0 : rust_error_at (seg->get_locus (), "789 reverse lookup failure");
382 0 : rust_debug_loc (
383 : seg->get_locus (),
384 : "failure with [%s] mappings [%s] ref_node_id [%u]",
385 : seg->to_string ().c_str (),
386 : seg->get_mappings ().as_string ().c_str (), ref_node_id);
387 :
388 0 : return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
389 : }
390 :
391 : return root_tyty;
392 : }
393 360910 : auto ref = hid.value ();
394 :
395 360910 : auto seg_is_module = mappings.hir.modules.lookup (ref).has_value ();
396 360910 : auto seg_is_crate = mappings.is_local_hirid_crate (ref);
397 360910 : if (seg_is_module || seg_is_crate)
398 : {
399 : // A::B::C::this_is_a_module::D::E::F
400 : // ^^^^^^^^^^^^^^^^
401 : // Currently handling this.
402 982 : if (have_more_segments)
403 : {
404 982 : (*offset)++;
405 982 : continue;
406 : }
407 :
408 : // In the case of :
409 : // A::B::C::this_is_a_module
410 : // ^^^^^^^^^^^^^^^^
411 : // This is an error, we are not expecting a module.
412 0 : rust_error_at (seg->get_locus (), "expected value, got module");
413 :
414 0 : return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
415 : }
416 :
417 359928 : TyTy::BaseType *lookup = nullptr;
418 359928 : if (!query_type (ref, &lookup))
419 : {
420 2 : if (is_root || root_tyty == nullptr)
421 : {
422 2 : rust_error_at (seg->get_locus (),
423 : "failed to resolve type path segment: %qs",
424 2 : seg->to_string ().c_str ());
425 2 : return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
426 : }
427 :
428 : return root_tyty;
429 : }
430 :
431 : // if we have a previous segment type
432 359893 : if (root_tyty != nullptr)
433 : {
434 : // if this next segment needs substitution we must apply the
435 : // previous type arguments
436 : //
437 : // such as: GenericStruct::<_>::new(123, 456)
438 44 : if (lookup->needs_generic_substitutions ())
439 : {
440 0 : if (!root_tyty->needs_generic_substitutions ())
441 : {
442 0 : auto used_args_in_prev_segment
443 0 : = GetUsedSubstArgs::From (root_tyty);
444 0 : lookup
445 0 : = SubstMapperInternal::Resolve (lookup,
446 : used_args_in_prev_segment);
447 0 : }
448 : }
449 : }
450 :
451 : // turbo-fish segment path::<ty>
452 359893 : if (seg->is_generic_segment ())
453 : {
454 38710 : auto &generic_segment
455 38710 : = static_cast<HIR::TypePathSegmentGeneric &> (*seg);
456 :
457 38710 : auto regions = context->regions_from_generic_args (
458 38710 : generic_segment.get_generic_args ());
459 38710 : lookup = SubstMapper::Resolve (lookup, path.get_locus (),
460 38710 : &generic_segment.get_generic_args (),
461 : regions);
462 38710 : if (lookup->get_kind () == TyTy::TypeKind::ERROR)
463 4 : return new TyTy::ErrorType (seg->get_mappings ().get_hirid ());
464 38710 : }
465 321183 : else if (lookup->needs_generic_substitutions ())
466 : {
467 375 : HIR::GenericArgs empty
468 375 : = HIR::GenericArgs::create_empty (path.get_locus ());
469 375 : lookup
470 375 : = SubstMapper::Resolve (lookup, path.get_locus (), &empty,
471 375 : context->regions_from_generic_args (empty));
472 375 : }
473 :
474 359889 : *offset = *offset + 1;
475 359889 : root_tyty = lookup;
476 :
477 : // this enforces the proper get_segments checks to take place
478 714082 : auto *maybe_adt = root_tyty->try_as<const TyTy::ADTType> ();
479 56178 : if (maybe_adt && maybe_adt->is_enum ())
480 : return root_tyty;
481 : }
482 :
483 : return root_tyty;
484 : }
485 :
486 : bool
487 2473 : TypeCheckType::resolve_associated_type (const std::string &search,
488 : TypeCheckBlockContextItem &ctx,
489 : TyTy::BaseType **result)
490 : {
491 2473 : if (ctx.is_trait_block ())
492 : {
493 2307 : HIR::Trait &trait = ctx.get_trait ();
494 3028 : for (auto &item : trait.get_trait_items ())
495 : {
496 2863 : if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::TYPE)
497 597 : continue;
498 :
499 2266 : if (item->trait_identifier () == search)
500 : {
501 2142 : HirId item_id = item->get_mappings ().get_hirid ();
502 2142 : if (query_type (item_id, result))
503 2473 : return true;
504 : }
505 : }
506 :
507 : // FIXME
508 : // query any parent trait?
509 :
510 : return false;
511 : }
512 :
513 : // look for any segment in here which matches
514 166 : HIR::ImplBlock &block = ctx.get_impl_block ();
515 209 : for (auto &item : block.get_impl_items ())
516 : {
517 185 : if (item->get_impl_item_type () != HIR::ImplItem::TYPE_ALIAS)
518 26 : continue;
519 :
520 159 : if (item->get_impl_item_name () == search)
521 : {
522 142 : HirId item_id = item->get_impl_mappings ().get_hirid ();
523 142 : if (query_type (item_id, result))
524 2473 : return true;
525 : }
526 : }
527 :
528 : return false;
529 : }
530 :
531 : bool
532 3469 : TypeCheckType::try_resolve_contextual_self_associated_type (
533 : const HIR::TypePathSegment &segment, bool first_segment,
534 : bool ty_seg_is_big_self, TyTy::BaseType **result)
535 : {
536 3469 : if (!first_segment || !ty_seg_is_big_self
537 3469 : || !context->block_context ().is_in_context ())
538 : return false;
539 :
540 2473 : TypeCheckBlockContextItem ctx = context->block_context ().peek ();
541 2473 : return resolve_associated_type (segment.to_string (), ctx, result);
542 : }
543 :
544 : TyTy::BaseType *
545 3470 : TypeCheckType::resolve_segments (
546 : HirId expr_id, std::vector<std::unique_ptr<HIR::TypePathSegment>> &segments,
547 : size_t offset, TyTy::BaseType *tyseg,
548 : const Analysis::NodeMapping &expr_mappings, location_t expr_locus,
549 : bool tySegIsBigSelf)
550 : {
551 6936 : for (size_t i = offset; i < segments.size (); i++)
552 : {
553 3469 : auto &seg = segments.at (i);
554 3469 : const auto &ident_segment = seg->get_ident_segment ();
555 3469 : bool first_segment = i == offset;
556 3469 : TyTy::BaseType *associated_type = nullptr;
557 :
558 3469 : bool selfResolveOk
559 3469 : = try_resolve_contextual_self_associated_type (*seg, first_segment,
560 : tySegIsBigSelf,
561 : &associated_type);
562 3469 : if (selfResolveOk)
563 : {
564 2284 : tyseg = associated_type;
565 : }
566 : else
567 : {
568 1185 : if (auto adt = tyseg->try_as<TyTy::ADTType> ())
569 : {
570 16 : if (adt->is_enum ())
571 : {
572 2 : rich_location r (line_table, seg->get_locus ());
573 2 : text_range_label label ("enum declared here");
574 :
575 2 : auto item_lookup = mappings.lookup_defid (adt->get_id ());
576 2 : if (item_lookup.has_value ())
577 : {
578 2 : auto &item = item_lookup.value ();
579 2 : r.add_range (item->get_locus (), SHOW_RANGE_WITHOUT_CARET,
580 : &label);
581 : }
582 :
583 2 : TyTy::VariantDef *v;
584 4 : if (adt->lookup_variant (ident_segment.to_string (), &v))
585 : {
586 2 : rust_error_at (
587 : r, ErrorCode::E0573,
588 : "expected type, found variant of %<%s::%s%>",
589 4 : adt->get_name ().c_str (),
590 2 : v->get_identifier ().c_str ());
591 2 : return new TyTy::ErrorType (expr_id);
592 : }
593 2 : }
594 : }
595 :
596 1183 : auto result = TypePathProbe::Probe (tyseg, ident_segment);
597 1183 : auto &candidates = result.type_candidates;
598 :
599 1183 : if (candidates.empty ())
600 : {
601 2 : rust_error_at (seg->get_locus (),
602 : "failed to resolve path segment %<%s%> as a type",
603 1 : ident_segment.to_string ().c_str ());
604 1 : return new TyTy::ErrorType (expr_id);
605 : }
606 :
607 1182 : if (candidates.size () > 1)
608 : {
609 0 : ReportMultipleCandidateError::Report (candidates, ident_segment,
610 : seg->get_locus ());
611 0 : return new TyTy::ErrorType (expr_id);
612 : }
613 :
614 1182 : auto &candidate = *candidates.begin ();
615 1182 : tyseg = candidate.ty;
616 1183 : }
617 :
618 3466 : if (seg->is_generic_segment ())
619 : {
620 20 : auto &generic_segment
621 20 : = static_cast<HIR::TypePathSegmentGeneric &> (*seg);
622 :
623 20 : std::vector<TyTy::Region> regions;
624 0 : for (auto &lifetime :
625 20 : generic_segment.get_generic_args ().get_lifetime_args ())
626 : {
627 0 : auto region = context->lookup_and_resolve_lifetime (lifetime);
628 0 : if (!region.has_value ())
629 : {
630 0 : rust_error_at (lifetime.get_locus (),
631 : "failed to resolve lifetime");
632 0 : return new TyTy::ErrorType (expr_id);
633 : }
634 0 : regions.push_back (region.value ());
635 : }
636 :
637 20 : tyseg = SubstMapper::Resolve (tyseg, expr_locus,
638 20 : &generic_segment.get_generic_args (),
639 : regions);
640 20 : if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
641 0 : return new TyTy::ErrorType (expr_id);
642 20 : }
643 : }
644 :
645 : return tyseg;
646 : }
647 :
648 : void
649 293 : TypeCheckType::visit (HIR::TraitObjectType &type)
650 : {
651 293 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
652 665 : for (auto &bound : type.get_type_param_bounds ())
653 : {
654 : // TODO: here we need to check if there are additional bounds that aren't
655 : // auto traits. this is an error. for example, `dyn A + Sized + Sync` is
656 : // okay, because Sized and Sync are both auto traits but `dyn A + Copy +
657 : // Clone` is not okay and should error out.
658 :
659 372 : if (bound->get_bound_type ()
660 : != HIR::TypeParamBound::BoundType::TRAITBOUND)
661 29 : continue;
662 :
663 343 : HIR::TypeParamBound &b = *bound.get ();
664 343 : HIR::TraitBound &trait_bound = static_cast<HIR::TraitBound &> (b);
665 :
666 343 : auto binder_pin = context->push_lifetime_binder ();
667 350 : for (auto &lifetime_param : trait_bound.get_for_lifetimes ())
668 : {
669 7 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
670 : }
671 :
672 343 : TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
673 : trait_bound.get_path (),
674 343 : tl::nullopt /*this will setup a PLACEHOLDER for self*/);
675 :
676 343 : if (!predicate.is_error ()
677 343 : && predicate.is_object_safe (true, type.get_locus ()))
678 341 : specified_bounds.push_back (std::move (predicate));
679 343 : }
680 :
681 : // The dyn_drop lint: a trait object with a `Drop` bound is pointless, as
682 : // values are dropped automatically regardless of the bound.
683 293 : if (flag_unused_check_2_0)
684 1 : if (auto drop = mappings.lookup_lang_item (LangItem::Kind::DROP))
685 2 : for (auto &bound : specified_bounds)
686 2 : if (bound.get_id () == drop.value ())
687 1 : rust_warning_at (type.get_locus (), OPT_Wunused,
688 : "this trait object has a %<Drop%> bound, which has "
689 : "no effect");
690 :
691 293 : RustIdent ident{CanonicalPath::create_empty (), type.get_locus ()};
692 293 : translated
693 293 : = new TyTy::DynamicObjectType (type.get_mappings ().get_hirid (), ident,
694 586 : std::move (specified_bounds));
695 293 : }
696 :
697 : void
698 38 : TypeCheckType::visit (HIR::ParenthesisedType &type)
699 : {
700 : // I think this really needs to be a tuple.. but will sort that out when we
701 : // fix the parser issue
702 38 : translated = TypeCheckType::Resolve (type.get_type_in_parens ());
703 38 : }
704 :
705 : void
706 1527 : TypeCheckType::visit (HIR::ArrayType &type)
707 : {
708 1527 : auto element_type = TypeCheckType::Resolve (type.get_element_type ());
709 1527 : context->push_const_context ();
710 1527 : auto capacity_type = TypeCheckExpr::Resolve (type.get_size_expr ());
711 1526 : context->pop_const_context ();
712 :
713 1526 : if (capacity_type->get_kind () == TyTy::TypeKind::ERROR)
714 0 : return;
715 :
716 1526 : TyTy::BaseType *expected_ty = nullptr;
717 1526 : bool ok = context->lookup_builtin ("usize", &expected_ty);
718 1526 : rust_assert (ok);
719 :
720 1526 : TyTy::BaseConstType *const_type = nullptr;
721 1526 : if (capacity_type->get_kind () == TyTy::TypeKind::CONST)
722 : {
723 362 : const_type = capacity_type->as_const_type ();
724 :
725 724 : unify_site (type.get_size_expr ().get_mappings ().get_hirid (),
726 362 : TyTy::TyWithLocation (expected_ty),
727 : TyTy::TyWithLocation (const_type->get_specified_type (),
728 362 : type.get_size_expr ().get_locus ()),
729 362 : type.get_size_expr ().get_locus ());
730 : }
731 : else
732 : {
733 1164 : HirId size_id = type.get_size_expr ().get_mappings ().get_hirid ();
734 1164 : TyTy::BaseType *result
735 2328 : = unify_site (size_id, TyTy::TyWithLocation (expected_ty),
736 : TyTy::TyWithLocation (capacity_type,
737 1164 : type.get_size_expr ().get_locus ()),
738 1164 : type.get_size_expr ().get_locus ());
739 :
740 1164 : if (result->is<TyTy::ErrorType> ())
741 2 : const_type = new TyTy::ConstErrorType (expected_ty, size_id, size_id);
742 : else
743 : {
744 1162 : auto ctx = Compile::Context::get ();
745 1162 : tree capacity_expr
746 1162 : = Compile::HIRCompileBase::query_compile_const_expr (
747 : ctx, capacity_type, type.get_size_expr ());
748 :
749 1162 : const_type = new TyTy::ConstValueType (capacity_expr, expected_ty,
750 2324 : size_id, size_id);
751 : }
752 :
753 1164 : context->insert_type (type.get_size_expr ().get_mappings (),
754 1164 : const_type->as_base_type ());
755 : }
756 :
757 1526 : translated
758 1526 : = new TyTy::ArrayType (type.get_mappings ().get_hirid (), type.get_locus (),
759 : TyTy::TyVar (
760 1526 : const_type->as_base_type ()->get_ref ()),
761 4578 : TyTy::TyVar (element_type->get_ref ()));
762 : }
763 :
764 : void
765 1932 : TypeCheckType::visit (HIR::SliceType &type)
766 : {
767 1932 : TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ());
768 1932 : translated
769 1932 : = new TyTy::SliceType (type.get_mappings ().get_hirid (), type.get_locus (),
770 3864 : TyTy::TyVar (base->get_ref ()));
771 1932 : }
772 : void
773 49665 : TypeCheckType::visit (HIR::ReferenceType &type)
774 : {
775 49665 : TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ());
776 49665 : rust_assert (type.has_lifetime ());
777 49665 : auto region = context->lookup_and_resolve_lifetime (type.get_lifetime ());
778 49665 : if (!region.has_value ())
779 : {
780 2 : rust_error_at (type.get_locus (), "failed to resolve lifetime");
781 2 : translated = new TyTy::ErrorType (type.get_mappings ().get_hirid ());
782 2 : return;
783 : }
784 148989 : translated = new TyTy::ReferenceType (type.get_mappings ().get_hirid (),
785 49663 : TyTy::TyVar (base->get_ref ()),
786 99326 : type.get_mut (), region.value ());
787 : }
788 :
789 : void
790 8563 : TypeCheckType::visit (HIR::RawPointerType &type)
791 : {
792 8563 : TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ());
793 8563 : translated
794 17126 : = new TyTy::PointerType (type.get_mappings ().get_hirid (),
795 8563 : TyTy::TyVar (base->get_ref ()), type.get_mut ());
796 8563 : }
797 :
798 : void
799 227 : TypeCheckType::visit (HIR::InferredType &type)
800 : {
801 454 : translated = new TyTy::InferType (type.get_mappings ().get_hirid (),
802 : TyTy::InferType::InferTypeKind::GENERAL,
803 : TyTy::InferType::TypeHint::Default (),
804 454 : type.get_locus ());
805 227 : }
806 :
807 : void
808 392 : TypeCheckType::visit (HIR::NeverType &type)
809 : {
810 392 : TyTy::BaseType *lookup = nullptr;
811 392 : bool ok = context->lookup_builtin ("!", &lookup);
812 392 : rust_assert (ok);
813 :
814 392 : translated = lookup->clone ();
815 392 : }
816 :
817 : void
818 745 : TypeCheckType::visit (HIR::ImplTraitType &type)
819 : {
820 745 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
821 1493 : for (auto &bound : type.get_type_param_bounds ())
822 : {
823 748 : if (bound->get_bound_type ()
824 : != HIR::TypeParamBound::BoundType::TRAITBOUND)
825 2 : continue;
826 :
827 746 : HIR::TypeParamBound &b = *bound.get ();
828 746 : HIR::TraitBound &trait_bound = static_cast<HIR::TraitBound &> (b);
829 :
830 746 : auto binder_pin = context->push_lifetime_binder ();
831 746 : for (auto &lifetime_param : trait_bound.get_for_lifetimes ())
832 : {
833 0 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
834 : }
835 :
836 746 : TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
837 : trait_bound.get_path (),
838 746 : tl::nullopt /*this will setup a PLACEHOLDER for self*/);
839 :
840 746 : if (!predicate.is_error ()
841 746 : && predicate.is_object_safe (true, type.get_locus ()))
842 735 : specified_bounds.push_back (std::move (predicate));
843 746 : }
844 :
845 2235 : translated = new TyTy::OpaqueType (type.get_locus (),
846 745 : type.get_mappings ().get_hirid (),
847 745 : specified_bounds);
848 745 : }
849 :
850 : TyTy::ParamType *
851 82144 : TypeResolveGenericParam::Resolve (HIR::GenericParam ¶m,
852 : bool resolve_trait_bounds, bool apply_sized)
853 : {
854 82144 : TypeResolveGenericParam resolver (apply_sized, resolve_trait_bounds);
855 82144 : switch (param.get_kind ())
856 : {
857 82144 : case HIR::GenericParam::GenericKind::TYPE:
858 82144 : resolver.visit (static_cast<HIR::TypeParam &> (param));
859 82144 : break;
860 :
861 0 : case HIR::GenericParam::GenericKind::CONST:
862 0 : resolver.visit (static_cast<HIR::ConstGenericParam &> (param));
863 0 : break;
864 :
865 0 : case HIR::GenericParam::GenericKind::LIFETIME:
866 0 : resolver.visit (static_cast<HIR::LifetimeParam &> (param));
867 0 : break;
868 : }
869 82144 : return resolver.resolved;
870 82144 : }
871 :
872 : void
873 75912 : TypeResolveGenericParam::ApplyAnyTraitBounds (HIR::TypeParam ¶m,
874 : TyTy::ParamType *pty)
875 : {
876 75912 : TypeResolveGenericParam resolver (true, true);
877 75912 : resolver.apply_trait_bounds (param, pty);
878 75912 : }
879 :
880 : void
881 0 : TypeResolveGenericParam::visit (HIR::LifetimeParam ¶m)
882 : {
883 : // nothing to do
884 0 : }
885 :
886 : void
887 0 : TypeResolveGenericParam::visit (HIR::ConstGenericParam ¶m)
888 : {
889 : // TODO
890 0 : }
891 :
892 : void
893 82144 : TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
894 : {
895 82144 : if (param.has_type ())
896 705 : TypeCheckType::Resolve (param.get_type ());
897 :
898 164288 : resolved = new TyTy::ParamType (param.get_type_representation ().as_string (),
899 : param.get_locus (),
900 82144 : param.get_mappings ().get_hirid (),
901 246432 : param.get_mappings ().get_hirid (), {});
902 :
903 82144 : if (resolve_trait_bounds)
904 7185 : apply_trait_bounds (param, resolved);
905 82144 : }
906 :
907 : void
908 83097 : TypeResolveGenericParam::apply_trait_bounds (HIR::TypeParam ¶m,
909 : TyTy::ParamType *pty)
910 : {
911 83097 : std::unique_ptr<HIR::Type> implicit_self_bound = nullptr;
912 83097 : if (param.has_type_param_bounds ())
913 : {
914 : // We need two possible parameter types. One with no Bounds and one with
915 : // the bounds. the Self type for the bounds cannot itself contain the
916 : // bounds otherwise it will be a trait cycle
917 13356 : HirId implicit_id = mappings.get_next_hir_id ();
918 13356 : TyTy::ParamType *p
919 13356 : = new TyTy::ParamType (param.get_type_representation ().as_string (),
920 : param.get_locus (), implicit_id,
921 : pty->get_decl_id (),
922 26712 : {} /*empty specified bounds*/);
923 13356 : context->insert_implicit_type (implicit_id, p);
924 :
925 : // generate an implicit HIR Type we can apply to the predicate
926 13356 : Analysis::NodeMapping mappings (param.get_mappings ().get_crate_num (),
927 13356 : param.get_mappings ().get_nodeid (),
928 : implicit_id,
929 13356 : param.get_mappings ().get_local_defid ());
930 13356 : RawPath<std::unique_ptr<HIR::TypePathSegment>> path ({}, false);
931 26712 : implicit_self_bound = std::make_unique<HIR::TypePath> (
932 40068 : HIR::TypePath (mappings, std::move (path), BUILTINS_LOCATION));
933 13356 : }
934 :
935 83097 : std::map<DefId, std::vector<TyTy::TypeBoundPredicate>> predicates;
936 :
937 : // https://doc.rust-lang.org/std/marker/trait.Sized.html
938 : // All type parameters have an implicit bound of Sized. The special syntax
939 : // ?Sized can be used to remove this bound if it’s not appropriate.
940 : //
941 : // We can only do this when we are not resolving the implicit Self for Sized
942 : // itself
943 83097 : if (apply_sized)
944 : {
945 77247 : TyTy::TypeBoundPredicate sized_predicate
946 77247 : = get_marker_predicate (LangItem::Kind::SIZED, param.get_locus ());
947 :
948 154494 : predicates[sized_predicate.get_id ()] = {sized_predicate};
949 77247 : }
950 :
951 : // resolve the bounds
952 83097 : if (param.has_type_param_bounds ())
953 : {
954 27958 : for (auto &bound : param.get_type_param_bounds ())
955 : {
956 14602 : switch (bound->get_bound_type ())
957 : {
958 13876 : case HIR::TypeParamBound::BoundType::TRAITBOUND:
959 13876 : {
960 13876 : HIR::TraitBound &b = static_cast<HIR::TraitBound &> (*bound);
961 :
962 13876 : TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
963 : b.get_path (),
964 : tl::optional<std::reference_wrapper<HIR::Type>> (
965 13876 : std::ref (*implicit_self_bound)),
966 13876 : b.get_polarity ());
967 13876 : if (!predicate.is_error ())
968 : {
969 13875 : switch (predicate.get_polarity ())
970 : {
971 3221 : case BoundPolarity::AntiBound:
972 3221 : {
973 3221 : bool found = predicates.find (predicate.get_id ())
974 3221 : != predicates.end ();
975 3221 : if (found)
976 3221 : predicates.erase (predicate.get_id ());
977 : else
978 : {
979 : // emit error message
980 0 : rich_location r (line_table, b.get_locus ());
981 0 : r.add_range (predicate.get ()->get_locus ());
982 0 : rust_error_at (
983 : r, "antibound for %s is not applied here",
984 0 : predicate.get ()->get_name ().c_str ());
985 0 : }
986 : }
987 : break;
988 :
989 10654 : default:
990 10654 : {
991 10654 : if (predicates.find (predicate.get_id ())
992 10654 : == predicates.end ())
993 : {
994 10651 : predicates[predicate.get_id ()] = {};
995 : }
996 10654 : predicates[predicate.get_id ()].push_back (predicate);
997 : }
998 10654 : break;
999 : }
1000 : }
1001 13876 : }
1002 13876 : break;
1003 :
1004 : default:
1005 : break;
1006 : }
1007 : }
1008 : }
1009 :
1010 : // now to flat map the specified_bounds into the raw specified predicates
1011 83097 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
1012 167774 : for (auto it = predicates.begin (); it != predicates.end (); it++)
1013 : {
1014 169357 : for (const auto &predicate : it->second)
1015 : {
1016 84680 : specified_bounds.push_back (predicate);
1017 : }
1018 : }
1019 :
1020 : // inherit them
1021 83097 : pty->inherit_bounds (specified_bounds);
1022 83097 : }
1023 :
1024 : void
1025 2 : ResolveWhereClauseItem::Resolve (HIR::WhereClauseItem &item,
1026 : TyTy::RegionConstraints ®ion_constraints)
1027 : {
1028 2 : ResolveWhereClauseItem resolver (region_constraints);
1029 :
1030 2 : auto binder_pin = resolver.context->push_lifetime_binder ();
1031 :
1032 2 : switch (item.get_item_type ())
1033 : {
1034 2 : case HIR::WhereClauseItem::LIFETIME:
1035 2 : resolver.visit (static_cast<HIR::LifetimeWhereClauseItem &> (item));
1036 2 : break;
1037 :
1038 0 : case HIR::WhereClauseItem::TYPE_BOUND:
1039 0 : resolver.visit (static_cast<HIR::TypeBoundWhereClauseItem &> (item));
1040 0 : break;
1041 : }
1042 2 : }
1043 :
1044 : void
1045 181868 : ResolveWhereClauseItem::Resolve (HIR::WhereClause &clause,
1046 : TyTy::RegionConstraints ®ion_constraints)
1047 : {
1048 181868 : ResolveWhereClauseItem resolver (region_constraints);
1049 :
1050 181868 : class PlainTypePath : public HIR::HIRTypeVisitor
1051 : {
1052 : public:
1053 : bool matches = false;
1054 :
1055 0 : void visit (HIR::TypePathSegmentFunction &segment) override {}
1056 0 : void visit (HIR::QualifiedPathInType &path) override {}
1057 0 : void visit (HIR::TraitBound &bound) override {}
1058 0 : void visit (HIR::ImplTraitType &type) override {}
1059 0 : void visit (HIR::TraitObjectType &type) override {}
1060 0 : void visit (HIR::ParenthesisedType &type) override {}
1061 0 : void visit (HIR::TupleType &type) override {}
1062 0 : void visit (HIR::NeverType &type) override {}
1063 0 : void visit (HIR::RawPointerType &type) override {}
1064 0 : void visit (HIR::ReferenceType &type) override {}
1065 0 : void visit (HIR::ArrayType &type) override {}
1066 0 : void visit (HIR::SliceType &type) override {}
1067 0 : void visit (HIR::InferredType &type) override {}
1068 0 : void visit (HIR::BareFunctionType &type) override {}
1069 :
1070 6857 : void visit (HIR::TypePath &path) override
1071 : {
1072 6857 : bool is_single = path.get_segments ().size () == 1;
1073 6857 : bool final_seg_is_reg
1074 6857 : = path.get_final_segment ().get_type () == HIR::TypePathSegment::REG;
1075 :
1076 6857 : matches = is_single && final_seg_is_reg;
1077 6857 : }
1078 : };
1079 :
1080 181868 : resolver.defer_bindings = true;
1081 188727 : for (auto &item : clause.get_items ())
1082 6859 : if (item->get_item_type () == HIR::WhereClauseItem::TYPE_BOUND)
1083 : {
1084 6857 : auto &bound = static_cast<HIR::TypeBoundWhereClauseItem &> (*item);
1085 6857 : PlainTypePath plain;
1086 6857 : bound.get_bound_type ().accept_vis (plain);
1087 6857 : if (plain.matches)
1088 6651 : resolver.visit (bound);
1089 : }
1090 :
1091 181868 : resolver.defer_bindings = false;
1092 181868 : resolver.complete_bindings = true;
1093 188727 : for (auto &item : clause.get_items ())
1094 : {
1095 6859 : if (item->get_item_type () == HIR::WhereClauseItem::TYPE_BOUND)
1096 6857 : resolver.visit (static_cast<HIR::TypeBoundWhereClauseItem &> (*item));
1097 : else
1098 2 : Resolve (*item, region_constraints);
1099 : }
1100 181868 : }
1101 :
1102 : void
1103 2 : ResolveWhereClauseItem::visit (HIR::LifetimeWhereClauseItem &item)
1104 : {
1105 2 : auto lhs = context->lookup_and_resolve_lifetime (item.get_lifetime ());
1106 2 : if (!lhs.has_value ())
1107 : {
1108 0 : rust_error_at (UNKNOWN_LOCATION, "failed to resolve lifetime");
1109 : }
1110 4 : for (auto &lifetime : item.get_lifetime_bounds ())
1111 : {
1112 2 : auto rhs_i = context->lookup_and_resolve_lifetime (lifetime);
1113 2 : if (!rhs_i.has_value ())
1114 : {
1115 0 : rust_error_at (UNKNOWN_LOCATION, "failed to resolve lifetime");
1116 : }
1117 2 : region_constraints.region_region.emplace_back (lhs.value (),
1118 : rhs_i.value ());
1119 : }
1120 2 : }
1121 :
1122 : void
1123 13508 : ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
1124 : {
1125 13508 : auto binder_pin = context->push_lifetime_binder ();
1126 13508 : if (item.has_for_lifetimes ())
1127 : {
1128 28 : for (auto &lifetime_param : item.get_for_lifetimes ())
1129 : {
1130 14 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
1131 : }
1132 : }
1133 :
1134 13508 : auto &binding_type_path = item.get_bound_type ();
1135 13508 : TyTy::BaseType *binding
1136 13508 : = TypeCheckType::Resolve (binding_type_path,
1137 : TypeCheckType::ResolutionMode::CANONICAL);
1138 :
1139 13508 : if (defer_bindings && binding->get_kind () != TyTy::TypeKind::PARAM)
1140 1 : return;
1141 :
1142 : // FIXME double check there might be a trait cycle here see TypeParam handling
1143 :
1144 13507 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
1145 27784 : for (auto &bound : item.get_type_param_bounds ())
1146 : {
1147 14277 : switch (bound->get_bound_type ())
1148 : {
1149 14269 : case HIR::TypeParamBound::BoundType::TRAITBOUND:
1150 14269 : {
1151 14269 : auto *b = static_cast<HIR::TraitBound *> (bound.get ());
1152 :
1153 14269 : TyTy::TypeBoundPredicate predicate
1154 14269 : = get_predicate_from_bound (b->get_path (), binding_type_path,
1155 : BoundPolarity::RegularBound, false,
1156 14269 : false, defer_bindings);
1157 14269 : if (!predicate.is_error ())
1158 14269 : specified_bounds.push_back (std::move (predicate));
1159 14269 : }
1160 14269 : break;
1161 8 : case HIR::TypeParamBound::BoundType::LIFETIME:
1162 8 : {
1163 8 : if (defer_bindings)
1164 : break;
1165 8 : if (auto param = binding->try_as<TyTy::ParamType> ())
1166 : {
1167 4 : auto *b = static_cast<HIR::Lifetime *> (bound.get ());
1168 4 : auto region = context->lookup_and_resolve_lifetime (*b);
1169 4 : if (!region.has_value ())
1170 : {
1171 0 : rust_error_at (UNKNOWN_LOCATION,
1172 : "failed to resolve lifetime");
1173 : }
1174 4 : region_constraints.type_region.emplace_back (param,
1175 : region.value ());
1176 : }
1177 : }
1178 4 : break;
1179 :
1180 : default:
1181 : break;
1182 : }
1183 : }
1184 :
1185 27776 : for (const auto &predicate : specified_bounds)
1186 : {
1187 14269 : bool replaced = false;
1188 14269 : if (complete_bindings)
1189 : {
1190 17806 : for (auto &bound : binding->get_specified_bounds ())
1191 : {
1192 32154 : if (bound.get_id () == predicate.get_id ()
1193 7130 : && bound.get_locus () == predicate.get_locus ())
1194 : {
1195 5509 : bound = predicate;
1196 5509 : replaced = true;
1197 5509 : break;
1198 : }
1199 : }
1200 : }
1201 :
1202 5509 : if (!replaced)
1203 8760 : binding->inherit_bound (predicate);
1204 : }
1205 13508 : }
1206 :
1207 : } // namespace Resolver
1208 : } // namespace Rust
|