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 490307 : TypeCheckType::Resolve (HIR::Type &type, ResolutionMode mode)
65 : {
66 : // is it already resolved?
67 490307 : auto context = TypeCheckContext::get ();
68 490307 : TyTy::BaseType *resolved = nullptr;
69 490307 : bool already_resolved
70 490307 : = context->lookup_type (type.get_mappings ().get_hirid (), &resolved);
71 490307 : if (already_resolved && mode == ResolutionMode::REFERENCE)
72 169931 : return resolved;
73 :
74 320376 : TypeCheckType resolver (type.get_mappings ().get_hirid (), mode);
75 320376 : type.accept_vis (resolver);
76 320312 : rust_assert (resolver.translated != nullptr);
77 320312 : resolver.context->insert_type (type.get_mappings (), resolver.translated);
78 320312 : return resolver.translated;
79 320312 : }
80 :
81 : void
82 3839 : TypeCheckType::visit (HIR::BareFunctionType &fntype)
83 : {
84 3839 : auto binder_pin = context->push_lifetime_binder ();
85 3841 : for (auto &lifetime_param : fntype.get_for_lifetimes ())
86 : {
87 2 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
88 : }
89 :
90 3839 : TyTy::BaseType *return_type;
91 3839 : if (fntype.has_return_type ())
92 : {
93 3798 : return_type = TypeCheckType::Resolve (fntype.get_return_type ());
94 : }
95 : else
96 : {
97 : // needs a new implicit ID
98 41 : HirId ref = mappings.get_next_hir_id ();
99 41 : return_type = TyTy::TupleType::get_unit_type ();
100 41 : context->insert_implicit_type (ref, return_type);
101 : }
102 :
103 3839 : std::vector<TyTy::TyVar> params;
104 3839 : params.reserve (fntype.get_function_params ().size ());
105 :
106 26871 : for (auto ¶m : fntype.get_function_params ())
107 : {
108 23032 : TyTy::BaseType *ptype = TypeCheckType::Resolve (param.get_type ());
109 23032 : params.emplace_back (ptype->get_ref ());
110 : }
111 :
112 3839 : translated
113 7678 : = new TyTy::FnPtr (fntype.get_mappings ().get_hirid (), fntype.get_locus (),
114 : std::move (params),
115 3839 : TyTy::TyVar (return_type->get_ref ()),
116 3839 : fntype.get_function_qualifiers ().get_abi (),
117 15356 : fntype.get_function_qualifiers ().get_unsafety ());
118 3839 : }
119 :
120 : void
121 3421 : TypeCheckType::visit (HIR::TupleType &tuple)
122 : {
123 3421 : if (tuple.is_unit_type ())
124 : {
125 412 : translated = TyTy::TupleType::get_unit_type ();
126 412 : return;
127 : }
128 :
129 3009 : std::vector<TyTy::TyVar> fields;
130 3009 : fields.reserve (tuple.get_elems ().size ());
131 :
132 8737 : for (auto &elem : tuple.get_elems ())
133 : {
134 5728 : auto field_ty = TypeCheckType::Resolve (*elem);
135 5728 : fields.emplace_back (field_ty->get_ref ());
136 : }
137 :
138 6018 : translated = new TyTy::TupleType (tuple.get_mappings ().get_hirid (),
139 9027 : tuple.get_locus (), fields);
140 3009 : }
141 :
142 : void
143 250177 : 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 250177 : bool wasBigSelf = false;
148 250177 : size_t offset = 0;
149 250177 : TyTy::BaseType *root = resolve_root_path (path, &offset, &wasBigSelf);
150 250156 : if (root->get_kind () == TyTy::TypeKind::ERROR)
151 : {
152 11 : rust_debug_loc (path.get_locus (), "failed to resolve type-path type");
153 247531 : return;
154 : }
155 :
156 250145 : TyTy::BaseType *path_type = root;
157 250145 : 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 241245 : auto *root_adt = root->try_as<TyTy::ADTType> ();
163 38058 : bool recursive_root
164 38058 : = root_adt != nullptr && root_adt->get_variants ().empty ();
165 240880 : if (!recursive_root)
166 : {
167 240880 : path_type = root->clone ();
168 240880 : path_type->set_ref (path.get_mappings ().get_hirid ());
169 : }
170 241245 : context->insert_implicit_type (path.get_mappings ().get_hirid (),
171 : path_type);
172 : }
173 :
174 250145 : bool fully_resolved = offset >= path.get_segments ().size ();
175 250145 : if (fully_resolved)
176 : {
177 247520 : translated = path_type;
178 247520 : rust_debug_loc (path.get_locus (), "root resolved type-path to: [%s]",
179 : translated->debug_str ().c_str ());
180 : return;
181 : }
182 :
183 2625 : translated
184 2625 : = resolve_segments (path.get_mappings ().get_hirid (), path.get_segments (),
185 2625 : offset, path_type, path.get_mappings (),
186 2625 : path.get_locus (), wasBigSelf);
187 :
188 2625 : if (auto p = translated->try_as<TyTy::ProjectionType> ())
189 2622 : translated
190 2622 : = normalize_projection (p, path.get_locus (), false /*emit errors*/,
191 : false /*unify self*/);
192 :
193 2625 : rust_debug_loc (path.get_locus (), "resolved type-path to: [%s]",
194 : translated->debug_str ().c_str ());
195 : }
196 :
197 : void
198 17193 : TypeCheckType::visit (HIR::QualifiedPathInType &path)
199 : {
200 17193 : HIR::QualifiedPathType qual_path_type = path.get_path_type ();
201 17193 : TyTy::BaseType *root = TypeCheckType::Resolve (qual_path_type.get_type ());
202 17193 : 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 17193 : 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 17192 : auto &trait_path_ref = qual_path_type.get_trait ();
220 17192 : TraitReference *trait_ref = TraitResolver::Resolve (trait_path_ref);
221 17192 : if (trait_ref->is_error ())
222 : return;
223 :
224 : // get the predicate for the bound
225 17192 : auto specified_bound
226 : = get_predicate_from_bound (qual_path_type.get_trait (),
227 17192 : qual_path_type.get_type (),
228 17192 : BoundPolarity::RegularBound, true);
229 17192 : if (specified_bound.is_error ())
230 : return;
231 :
232 : // inherit the bound
233 17192 : root->inherit_bound (specified_bound);
234 :
235 : // lookup the associated item from the specified bound
236 17192 : HIR::TypePathSegment &item_seg = path.get_associated_segment ();
237 17192 : HIR::PathIdentSegment item_seg_identifier = item_seg.get_ident_segment ();
238 17192 : tl::optional<TyTy::TypeBoundPredicateItem> item
239 17192 : = specified_bound.lookup_associated_item (item_seg_identifier.to_string ());
240 17192 : 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 17191 : TyTy::BaseType *rebased_item = item->get_tyty_for_receiver (root);
261 17191 : if (auto *proj = rebased_item->try_as<TyTy::ProjectionType> ())
262 17191 : translated
263 17191 : = 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 17149 : translated = translated->clone ();
271 17149 : translated->set_ref (path.get_mappings ().get_hirid ());
272 :
273 : // turbo-fish segment path::<ty>
274 17149 : 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 17149 : bool fully_resolved = path.get_segments ().empty ();
305 17149 : 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 34301 : }
313 :
314 : TyTy::BaseType *
315 250177 : TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
316 : bool *wasBigSelf)
317 : {
318 250177 : TyTy::BaseType *root_tyty = nullptr;
319 250177 : *offset = 0;
320 :
321 496792 : for (size_t i = 0; i < path.get_num_segments (); i++)
322 : {
323 253574 : std::unique_ptr<HIR::TypePathSegment> &seg = path.get_segments ().at (i);
324 :
325 253574 : bool have_more_segments = (path.get_num_segments () - 1 != i);
326 253574 : bool is_root = *offset == 0;
327 253574 : NodeId ast_node_id = seg->get_mappings ().get_nodeid ();
328 :
329 : // then lookup the reference_node_id
330 253574 : NodeId ref_node_id = UNKNOWN_NODEID;
331 :
332 253574 : 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 253524 : auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get ();
338 :
339 : // assign the ref_node_id if we've found something
340 253524 : nr_ctx.lookup (ast_node_id, Resolver2_0::Namespace::Types)
341 504424 : .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 507048 : if (auto builtin_type_id
347 253524 : = Resolver2_0::Builtins::find_builtin_node_id (seg->to_string ()))
348 137371 : if (mappings.is_module (ref_node_id))
349 100 : ref_node_id = builtin_type_id.value ();
350 : }
351 :
352 : // ref_node_id is the NodeId that the segments refers to.
353 253574 : if (ref_node_id == UNKNOWN_NODEID)
354 : {
355 2624 : 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 2624 : 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 250950 : if (seg->is_ident_only () && seg->to_string () == "Self")
373 15399 : *wasBigSelf = true;
374 :
375 : // node back to HIR
376 250950 : tl::optional<HirId> hid = mappings.lookup_node_to_hir (ref_node_id);
377 250950 : 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 250950 : auto ref = hid.value ();
394 :
395 250950 : auto seg_is_module = mappings.hir.modules.lookup (ref).has_value ();
396 250950 : auto seg_is_crate = mappings.is_local_hirid_crate (ref);
397 250950 : 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 746 : if (have_more_segments)
403 : {
404 746 : (*offset)++;
405 746 : 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 250204 : TyTy::BaseType *lookup = nullptr;
418 250204 : 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 250181 : 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 28 : 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 250181 : if (seg->is_generic_segment ())
453 : {
454 25418 : auto &generic_segment
455 25418 : = static_cast<HIR::TypePathSegmentGeneric &> (*seg);
456 :
457 25418 : auto regions = context->regions_from_generic_args (
458 25418 : generic_segment.get_generic_args ());
459 25418 : lookup = SubstMapper::Resolve (lookup, path.get_locus (),
460 25418 : &generic_segment.get_generic_args (),
461 : regions);
462 25418 : if (lookup->get_kind () == TyTy::TypeKind::ERROR)
463 4 : return new TyTy::ErrorType (seg->get_mappings ().get_hirid ());
464 25418 : }
465 224763 : else if (lookup->needs_generic_substitutions ())
466 : {
467 307 : HIR::GenericArgs empty
468 307 : = HIR::GenericArgs::create_empty (path.get_locus ());
469 307 : lookup
470 307 : = SubstMapper::Resolve (lookup, path.get_locus (), &empty,
471 307 : context->regions_from_generic_args (empty));
472 307 : }
473 :
474 250177 : *offset = *offset + 1;
475 250177 : root_tyty = lookup;
476 :
477 : // this enforces the proper get_segments checks to take place
478 496046 : auto *maybe_adt = root_tyty->try_as<const TyTy::ADTType> ();
479 38058 : if (maybe_adt && maybe_adt->is_enum ())
480 : return root_tyty;
481 : }
482 :
483 : return root_tyty;
484 : }
485 :
486 : bool
487 1929 : TypeCheckType::resolve_associated_type (const std::string &search,
488 : TypeCheckBlockContextItem &ctx,
489 : TyTy::BaseType **result)
490 : {
491 1929 : if (ctx.is_trait_block ())
492 : {
493 1763 : HIR::Trait &trait = ctx.get_trait ();
494 2264 : for (auto &item : trait.get_trait_items ())
495 : {
496 2147 : if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::TYPE)
497 393 : continue;
498 :
499 1754 : if (item->trait_identifier () == search)
500 : {
501 1646 : HirId item_id = item->get_mappings ().get_hirid ();
502 1646 : if (query_type (item_id, result))
503 1929 : 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 1929 : return true;
525 : }
526 : }
527 :
528 : return false;
529 : }
530 :
531 : bool
532 2625 : 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 2625 : if (!first_segment || !ty_seg_is_big_self
537 2625 : || !context->block_context ().is_in_context ())
538 : return false;
539 :
540 1929 : TypeCheckBlockContextItem ctx = context->block_context ().peek ();
541 1929 : return resolve_associated_type (segment.to_string (), ctx, result);
542 : }
543 :
544 : TyTy::BaseType *
545 2626 : 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 5248 : for (size_t i = offset; i < segments.size (); i++)
552 : {
553 2625 : auto &seg = segments.at (i);
554 2625 : const auto &ident_segment = seg->get_ident_segment ();
555 2625 : bool first_segment = i == offset;
556 2625 : TyTy::BaseType *associated_type = nullptr;
557 :
558 2625 : bool selfResolveOk
559 2625 : = try_resolve_contextual_self_associated_type (*seg, first_segment,
560 : tySegIsBigSelf,
561 : &associated_type);
562 2625 : if (selfResolveOk)
563 : {
564 1788 : tyseg = associated_type;
565 : }
566 : else
567 : {
568 837 : 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 835 : auto result = TypePathProbe::Probe (tyseg, ident_segment);
597 835 : auto &candidates = result.type_candidates;
598 :
599 835 : 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 834 : 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 834 : auto &candidate = *candidates.begin ();
615 834 : tyseg = candidate.ty;
616 835 : }
617 :
618 2622 : 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 269 : TypeCheckType::visit (HIR::TraitObjectType &type)
650 : {
651 269 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
652 593 : 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 324 : if (bound->get_bound_type ()
660 : != HIR::TypeParamBound::BoundType::TRAITBOUND)
661 21 : continue;
662 :
663 303 : HIR::TypeParamBound &b = *bound.get ();
664 303 : HIR::TraitBound &trait_bound = static_cast<HIR::TraitBound &> (b);
665 :
666 303 : auto binder_pin = context->push_lifetime_binder ();
667 310 : for (auto &lifetime_param : trait_bound.get_for_lifetimes ())
668 : {
669 7 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
670 : }
671 :
672 303 : TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
673 : trait_bound.get_path (),
674 303 : tl::nullopt /*this will setup a PLACEHOLDER for self*/);
675 :
676 303 : if (!predicate.is_error ()
677 303 : && predicate.is_object_safe (true, type.get_locus ()))
678 301 : specified_bounds.push_back (std::move (predicate));
679 303 : }
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 269 : 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 269 : RustIdent ident{CanonicalPath::create_empty (), type.get_locus ()};
692 269 : translated
693 269 : = new TyTy::DynamicObjectType (type.get_mappings ().get_hirid (), ident,
694 538 : std::move (specified_bounds));
695 269 : }
696 :
697 : void
698 26 : 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 26 : translated = TypeCheckType::Resolve (type.get_type_in_parens ());
703 26 : }
704 :
705 : void
706 1263 : TypeCheckType::visit (HIR::ArrayType &type)
707 : {
708 1263 : auto element_type = TypeCheckType::Resolve (type.get_element_type ());
709 1263 : context->push_const_context ();
710 1263 : auto capacity_type = TypeCheckExpr::Resolve (type.get_size_expr ());
711 1262 : context->pop_const_context ();
712 :
713 1262 : if (capacity_type->get_kind () == TyTy::TypeKind::ERROR)
714 0 : return;
715 :
716 1262 : TyTy::BaseType *expected_ty = nullptr;
717 1262 : bool ok = context->lookup_builtin ("usize", &expected_ty);
718 1262 : rust_assert (ok);
719 :
720 1262 : TyTy::BaseConstType *const_type = nullptr;
721 1262 : if (capacity_type->get_kind () == TyTy::TypeKind::CONST)
722 : {
723 246 : const_type = capacity_type->as_const_type ();
724 :
725 492 : unify_site (type.get_size_expr ().get_mappings ().get_hirid (),
726 246 : TyTy::TyWithLocation (expected_ty),
727 : TyTy::TyWithLocation (const_type->get_specified_type (),
728 246 : type.get_size_expr ().get_locus ()),
729 246 : type.get_size_expr ().get_locus ());
730 : }
731 : else
732 : {
733 1016 : HirId size_id = type.get_size_expr ().get_mappings ().get_hirid ();
734 1016 : TyTy::BaseType *result
735 2032 : = unify_site (size_id, TyTy::TyWithLocation (expected_ty),
736 : TyTy::TyWithLocation (capacity_type,
737 1016 : type.get_size_expr ().get_locus ()),
738 1016 : type.get_size_expr ().get_locus ());
739 :
740 1016 : if (result->is<TyTy::ErrorType> ())
741 2 : const_type = new TyTy::ConstErrorType (expected_ty, size_id, size_id);
742 : else
743 : {
744 1014 : auto ctx = Compile::Context::get ();
745 1014 : tree capacity_expr
746 1014 : = Compile::HIRCompileBase::query_compile_const_expr (
747 : ctx, capacity_type, type.get_size_expr ());
748 :
749 1014 : const_type = new TyTy::ConstValueType (capacity_expr, expected_ty,
750 2028 : size_id, size_id);
751 : }
752 :
753 1016 : context->insert_type (type.get_size_expr ().get_mappings (),
754 1016 : const_type->as_base_type ());
755 : }
756 :
757 1262 : translated
758 1262 : = new TyTy::ArrayType (type.get_mappings ().get_hirid (), type.get_locus (),
759 : TyTy::TyVar (
760 1262 : const_type->as_base_type ()->get_ref ()),
761 3786 : TyTy::TyVar (element_type->get_ref ()));
762 : }
763 :
764 : void
765 1564 : TypeCheckType::visit (HIR::SliceType &type)
766 : {
767 1564 : TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ());
768 1564 : translated
769 1564 : = new TyTy::SliceType (type.get_mappings ().get_hirid (), type.get_locus (),
770 3128 : TyTy::TyVar (base->get_ref ()));
771 1564 : }
772 : void
773 33357 : TypeCheckType::visit (HIR::ReferenceType &type)
774 : {
775 33357 : TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ());
776 33357 : rust_assert (type.has_lifetime ());
777 33357 : auto region = context->lookup_and_resolve_lifetime (type.get_lifetime ());
778 33357 : 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 100065 : translated = new TyTy::ReferenceType (type.get_mappings ().get_hirid (),
785 33355 : TyTy::TyVar (base->get_ref ()),
786 66710 : type.get_mut (), region.value ());
787 : }
788 :
789 : void
790 8211 : TypeCheckType::visit (HIR::RawPointerType &type)
791 : {
792 8211 : TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ());
793 8211 : translated
794 16422 : = new TyTy::PointerType (type.get_mappings ().get_hirid (),
795 8211 : TyTy::TyVar (base->get_ref ()), type.get_mut ());
796 8211 : }
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 340 : TypeCheckType::visit (HIR::NeverType &type)
809 : {
810 340 : TyTy::BaseType *lookup = nullptr;
811 340 : bool ok = context->lookup_builtin ("!", &lookup);
812 340 : rust_assert (ok);
813 :
814 340 : translated = lookup->clone ();
815 340 : }
816 :
817 : void
818 489 : TypeCheckType::visit (HIR::ImplTraitType &type)
819 : {
820 489 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
821 981 : for (auto &bound : type.get_type_param_bounds ())
822 : {
823 492 : if (bound->get_bound_type ()
824 : != HIR::TypeParamBound::BoundType::TRAITBOUND)
825 2 : continue;
826 :
827 490 : HIR::TypeParamBound &b = *bound.get ();
828 490 : HIR::TraitBound &trait_bound = static_cast<HIR::TraitBound &> (b);
829 :
830 490 : auto binder_pin = context->push_lifetime_binder ();
831 490 : for (auto &lifetime_param : trait_bound.get_for_lifetimes ())
832 : {
833 0 : context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
834 : }
835 :
836 490 : TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
837 : trait_bound.get_path (),
838 490 : tl::nullopt /*this will setup a PLACEHOLDER for self*/);
839 :
840 490 : if (!predicate.is_error ()
841 490 : && predicate.is_object_safe (true, type.get_locus ()))
842 483 : specified_bounds.push_back (std::move (predicate));
843 490 : }
844 :
845 1467 : translated = new TyTy::OpaqueType (type.get_locus (),
846 489 : type.get_mappings ().get_hirid (),
847 489 : specified_bounds);
848 489 : }
849 :
850 : TyTy::ParamType *
851 56376 : TypeResolveGenericParam::Resolve (HIR::GenericParam ¶m,
852 : bool resolve_trait_bounds, bool apply_sized)
853 : {
854 56376 : TypeResolveGenericParam resolver (apply_sized, resolve_trait_bounds);
855 56376 : switch (param.get_kind ())
856 : {
857 56376 : case HIR::GenericParam::GenericKind::TYPE:
858 56376 : resolver.visit (static_cast<HIR::TypeParam &> (param));
859 56376 : 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 56376 : return resolver.resolved;
870 56376 : }
871 :
872 : void
873 50532 : TypeResolveGenericParam::ApplyAnyTraitBounds (HIR::TypeParam ¶m,
874 : TyTy::ParamType *pty)
875 : {
876 50532 : TypeResolveGenericParam resolver (true, true);
877 50532 : resolver.apply_trait_bounds (param, pty);
878 50532 : }
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 56376 : TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
894 : {
895 56376 : if (param.has_type ())
896 597 : TypeCheckType::Resolve (param.get_type ());
897 :
898 112752 : resolved = new TyTy::ParamType (param.get_type_representation ().as_string (),
899 : param.get_locus (),
900 56376 : param.get_mappings ().get_hirid (),
901 169128 : param.get_mappings ().get_hirid (), {});
902 :
903 56376 : if (resolve_trait_bounds)
904 6489 : apply_trait_bounds (param, resolved);
905 56376 : }
906 :
907 : void
908 57021 : TypeResolveGenericParam::apply_trait_bounds (HIR::TypeParam ¶m,
909 : TyTy::ParamType *pty)
910 : {
911 57021 : std::unique_ptr<HIR::Type> implicit_self_bound = nullptr;
912 57021 : 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 9032 : HirId implicit_id = mappings.get_next_hir_id ();
918 9032 : TyTy::ParamType *p
919 9032 : = new TyTy::ParamType (param.get_type_representation ().as_string (),
920 : param.get_locus (), implicit_id,
921 : pty->get_decl_id (),
922 18064 : {} /*empty specified bounds*/);
923 9032 : context->insert_implicit_type (implicit_id, p);
924 :
925 : // generate an implicit HIR Type we can apply to the predicate
926 9032 : Analysis::NodeMapping mappings (param.get_mappings ().get_crate_num (),
927 9032 : param.get_mappings ().get_nodeid (),
928 : implicit_id,
929 9032 : param.get_mappings ().get_local_defid ());
930 9032 : RawPath<std::unique_ptr<HIR::TypePathSegment>> path ({}, false);
931 18064 : implicit_self_bound = std::make_unique<HIR::TypePath> (
932 27096 : HIR::TypePath (mappings, std::move (path), BUILTINS_LOCATION));
933 9032 : }
934 :
935 57021 : 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 57021 : if (apply_sized)
944 : {
945 51647 : TyTy::TypeBoundPredicate sized_predicate
946 51647 : = get_marker_predicate (LangItem::Kind::SIZED, param.get_locus ());
947 :
948 103294 : predicates[sized_predicate.get_id ()] = {sized_predicate};
949 51647 : }
950 :
951 : // resolve the bounds
952 57021 : if (param.has_type_param_bounds ())
953 : {
954 18878 : for (auto &bound : param.get_type_param_bounds ())
955 : {
956 9846 : switch (bound->get_bound_type ())
957 : {
958 9384 : case HIR::TypeParamBound::BoundType::TRAITBOUND:
959 9384 : {
960 9384 : HIR::TraitBound &b = static_cast<HIR::TraitBound &> (*bound);
961 :
962 9384 : TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
963 : b.get_path (),
964 : tl::optional<std::reference_wrapper<HIR::Type>> (
965 9384 : std::ref (*implicit_self_bound)),
966 9384 : b.get_polarity ());
967 9384 : if (!predicate.is_error ())
968 : {
969 9383 : switch (predicate.get_polarity ())
970 : {
971 2221 : case BoundPolarity::AntiBound:
972 2221 : {
973 2221 : bool found = predicates.find (predicate.get_id ())
974 2221 : != predicates.end ();
975 2221 : if (found)
976 2221 : 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 7162 : default:
990 7162 : {
991 7162 : if (predicates.find (predicate.get_id ())
992 7162 : == predicates.end ())
993 : {
994 7159 : predicates[predicate.get_id ()] = {};
995 : }
996 7162 : predicates[predicate.get_id ()].push_back (predicate);
997 : }
998 7162 : break;
999 : }
1000 : }
1001 9384 : }
1002 9384 : break;
1003 :
1004 : default:
1005 : break;
1006 : }
1007 : }
1008 : }
1009 :
1010 : // now to flat map the specified_bounds into the raw specified predicates
1011 57021 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
1012 113606 : for (auto it = predicates.begin (); it != predicates.end (); it++)
1013 : {
1014 113173 : for (const auto &predicate : it->second)
1015 : {
1016 56588 : specified_bounds.push_back (predicate);
1017 : }
1018 : }
1019 :
1020 : // inherit them
1021 57021 : pty->inherit_bounds (specified_bounds);
1022 57021 : }
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 131052 : ResolveWhereClauseItem::Resolve (HIR::WhereClause &clause,
1046 : TyTy::RegionConstraints ®ion_constraints)
1047 : {
1048 131052 : ResolveWhereClauseItem resolver (region_constraints);
1049 :
1050 131052 : 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 4517 : void visit (HIR::TypePath &path) override
1071 : {
1072 4517 : bool is_single = path.get_segments ().size () == 1;
1073 4517 : bool final_seg_is_reg
1074 4517 : = path.get_final_segment ().get_type () == HIR::TypePathSegment::REG;
1075 :
1076 4517 : matches = is_single && final_seg_is_reg;
1077 4517 : }
1078 : };
1079 :
1080 131052 : resolver.defer_bindings = true;
1081 135571 : for (auto &item : clause.get_items ())
1082 4519 : if (item->get_item_type () == HIR::WhereClauseItem::TYPE_BOUND)
1083 : {
1084 4517 : auto &bound = static_cast<HIR::TypeBoundWhereClauseItem &> (*item);
1085 4517 : PlainTypePath plain;
1086 4517 : bound.get_bound_type ().accept_vis (plain);
1087 4517 : if (plain.matches)
1088 4383 : resolver.visit (bound);
1089 : }
1090 :
1091 131052 : resolver.defer_bindings = false;
1092 131052 : resolver.complete_bindings = true;
1093 135571 : for (auto &item : clause.get_items ())
1094 : {
1095 4519 : if (item->get_item_type () == HIR::WhereClauseItem::TYPE_BOUND)
1096 4517 : resolver.visit (static_cast<HIR::TypeBoundWhereClauseItem &> (*item));
1097 : else
1098 2 : Resolve (*item, region_constraints);
1099 : }
1100 131052 : }
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 8900 : ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
1124 : {
1125 8900 : auto binder_pin = context->push_lifetime_binder ();
1126 8900 : 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 8900 : auto &binding_type_path = item.get_bound_type ();
1135 8900 : TyTy::BaseType *binding
1136 8900 : = TypeCheckType::Resolve (binding_type_path,
1137 : TypeCheckType::ResolutionMode::CANONICAL);
1138 :
1139 8900 : 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 8899 : std::vector<TyTy::TypeBoundPredicate> specified_bounds;
1145 18288 : for (auto &bound : item.get_type_param_bounds ())
1146 : {
1147 9389 : switch (bound->get_bound_type ())
1148 : {
1149 9381 : case HIR::TypeParamBound::BoundType::TRAITBOUND:
1150 9381 : {
1151 9381 : auto *b = static_cast<HIR::TraitBound *> (bound.get ());
1152 :
1153 9381 : TyTy::TypeBoundPredicate predicate
1154 9381 : = get_predicate_from_bound (b->get_path (), binding_type_path,
1155 : BoundPolarity::RegularBound, false,
1156 9381 : false, defer_bindings);
1157 9381 : if (!predicate.is_error ())
1158 9381 : specified_bounds.push_back (std::move (predicate));
1159 9381 : }
1160 9381 : 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 18280 : for (const auto &predicate : specified_bounds)
1186 : {
1187 9381 : bool replaced = false;
1188 9381 : if (complete_bindings)
1189 : {
1190 11790 : for (auto &bound : binding->get_specified_bounds ())
1191 : {
1192 21290 : if (bound.get_id () == predicate.get_id ()
1193 4686 : && bound.get_locus () == predicate.get_locus ())
1194 : {
1195 3613 : bound = predicate;
1196 3613 : replaced = true;
1197 3613 : break;
1198 : }
1199 : }
1200 : }
1201 :
1202 3613 : if (!replaced)
1203 5768 : binding->inherit_bound (predicate);
1204 : }
1205 8900 : }
1206 :
1207 : } // namespace Resolver
1208 : } // namespace Rust
|