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
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
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/>.
22 #include "rust-hir-map.h"
23 #include "rust-common.h"
24 #include "rust-identifier.h"
26 #include "rust-tyty-bounds.h"
27 #include "rust-tyty-util.h"
28 #include "rust-tyty-subst.h"
29 #include "rust-tyty-region.h"
30 #include "rust-system.h"
38 class TraitItemReference
;
40 class AssociatedImplTrait
;
41 } // namespace Resolver
47 class CallableTypeInterface
;
49 // https://rustc-dev-guide.rust-lang.org/type-inference.html#inference-variables
50 // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variants
77 // there are more to add...
82 is_primitive_type_kind (TypeKind kind
);
87 static std::string
to_string (TypeKind kind
);
92 class BaseType
: public TypeBoundsMappings
97 HirId
get_ref () const;
98 void set_ref (HirId id
);
100 HirId
get_ty_ref () const;
101 void set_ty_ref (HirId id
);
103 HirId
get_orig_ref () const;
105 virtual void accept_vis (TyVisitor
&vis
) = 0;
106 virtual void accept_vis (TyConstVisitor
&vis
) const = 0;
108 virtual std::string
as_string () const = 0;
109 virtual std::string
get_name () const = 0;
111 // similar to unify but does not actually perform type unification but
112 // determines whether they are compatible. Consider the following
114 // fn foo<T>() -> T { ... }
115 // fn foo() -> i32 { ... }
117 // when the function has been substituted they can be considered equal.
119 // It can also be used to optional emit errors for trait item compatibility
121 virtual bool can_eq (const BaseType
*other
, bool emit_errors
) const = 0;
123 // Check value equality between two ty. Type inference rules are ignored. Two
124 // ty are considered equal if they're of the same kind, and
125 // 1. (For ADTs, arrays, tuples, refs) have the same underlying ty
126 // 2. (For functions) have the same signature
127 virtual bool is_equal (const BaseType
&other
) const;
129 bool satisfies_bound (const TypeBoundPredicate
&predicate
,
130 bool emit_error
) const;
132 bool bounds_compatible (const BaseType
&other
, location_t locus
,
133 bool emit_error
) const;
135 void inherit_bounds (const BaseType
&other
);
137 void inherit_bounds (
138 const std::vector
<TyTy::TypeBoundPredicate
> &specified_bounds
);
140 // contains_infer checks if there is an inference variable inside the type
141 const TyTy::BaseType
*contains_infer () const;
143 // is_unit returns whether this is just a unit-struct
144 bool is_unit () const;
146 // is_concrete returns true if the type is fully resolved to concrete
148 bool is_concrete () const;
150 // return the type-kind
151 TypeKind
get_kind () const;
153 // monomorphized clone is a clone which destructures the types to get rid of
155 BaseType
*monomorphized_clone () const;
157 // get_combined_refs returns the chain of node refs involved in unification
158 std::set
<HirId
> get_combined_refs () const;
160 void append_reference (HirId id
);
162 std::string
mappings_str () const;
164 std::string
debug_str () const;
168 // FIXME this will eventually go away
169 const BaseType
*get_root () const;
171 // This will get the monomorphized type from Params, Placeholders or
172 // Projections if available or error
173 BaseType
*destructure ();
174 const BaseType
*destructure () const;
176 const RustIdent
&get_ident () const;
177 location_t
get_locus () const;
179 bool has_substitutions_defined () const;
180 bool needs_generic_substitutions () const;
181 const SubstitutionArgumentMappings
&get_subst_argument_mappings () const;
183 std::string
mangle_string () const
185 return TypeKindFormat::to_string (get_kind ()) + ":" + as_string () + ":"
186 + mappings_str () + ":" + bounds_as_string ();
189 /* Returns a pointer to a clone of this. The caller is responsible for
190 * releasing the memory of the returned ty. */
191 virtual BaseType
*clone () const = 0;
193 // Check if TyTy::BaseType is of a specific type.
194 template <typename T
> WARN_UNUSED_RESULT
bool is () const
196 static_assert (std::is_base_of
<BaseType
, T
>::value
,
197 "Can only safely cast to TyTy types.");
198 return this->get_kind () == T::KIND
;
201 template <typename T
> T
*as () const
203 static_assert (std::is_base_of
<BaseType
, T
>::value
,
204 "Can only safely cast to TyTy types.");
205 rust_assert (this->is
<T
> ());
206 return static_cast<T
*> (this);
209 template <typename T
> T
*as ()
211 static_assert (std::is_base_of
<BaseType
, T
>::value
,
212 "Can only safely cast to TyTy types.");
213 rust_assert (this->is
<T
> ());
214 return static_cast<T
*> (this);
217 // Check if TyTy::BaseType is of a specific type and convert it to that type
219 // Returns nullptr otherwise. Works as a dynamic_cast, but without compiler
221 template <typename T
> T
*try_as () const
223 static_assert (std::is_base_of
<BaseType
, T
>::value
,
224 "Can only safely cast to TyTy types.");
228 return static_cast<T
*> (this);
232 template <typename T
> T
*try_as ()
234 static_assert (std::is_base_of
<BaseType
, T
>::value
,
235 "Can only safely cast to TyTy types.");
239 return static_cast<T
*> (this);
243 BaseType (HirId ref
, HirId ty_ref
, TypeKind kind
, RustIdent ident
,
244 std::set
<HirId
> refs
= std::set
<HirId
> ());
246 BaseType (HirId ref
, HirId ty_ref
, TypeKind kind
, RustIdent ident
,
247 std::vector
<TypeBoundPredicate
> specified_bounds
,
248 std::set
<HirId
> refs
= std::set
<HirId
> ());
253 const HirId orig_ref
;
254 std::set
<HirId
> combined
;
257 Analysis::Mappings
&mappings
;
260 /** Unified interface for all function-like types. */
261 class CallableTypeInterface
: public BaseType
264 explicit CallableTypeInterface (HirId ref
, HirId ty_ref
, TypeKind kind
,
266 std::set
<HirId
> refs
= std::set
<HirId
> ())
267 : BaseType (ref
, ty_ref
, kind
, ident
, refs
)
270 WARN_UNUSED_RESULT
virtual size_t get_num_params () const = 0;
271 WARN_UNUSED_RESULT
virtual BaseType
*
272 get_param_type_at (size_t index
) const = 0;
273 WARN_UNUSED_RESULT
virtual BaseType
*get_return_type () const = 0;
276 class InferType
: public BaseType
279 static constexpr auto KIND
= TypeKind::INFER
;
311 static TypeHint
Default ()
313 return TypeHint
{TypeKind::ERROR
, UNKNOWN
, SUNKNOWN
};
317 InferType (HirId ref
, InferTypeKind infer_kind
, TypeHint hint
,
318 location_t locus
, std::set
<HirId
> refs
= std::set
<HirId
> ());
320 InferType (HirId ref
, HirId ty_ref
, InferTypeKind infer_kind
, TypeHint hint
,
321 location_t locus
, std::set
<HirId
> refs
= std::set
<HirId
> ());
323 void accept_vis (TyVisitor
&vis
) override
;
325 void accept_vis (TyConstVisitor
&vis
) const override
;
327 std::string
as_string () const override
;
329 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
331 BaseType
*clone () const final override
;
333 InferTypeKind
get_infer_kind () const;
335 std::string
get_name () const override final
;
337 bool default_type (BaseType
**type
) const;
339 void apply_primitive_type_hint (const TyTy::BaseType
&hint
);
342 InferTypeKind infer_kind
;
343 TypeHint default_hint
;
346 class ErrorType
: public BaseType
349 static constexpr auto KIND
= TypeKind::ERROR
;
351 ErrorType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
353 ErrorType (HirId ref
, HirId ty_ref
,
354 std::set
<HirId
> refs
= std::set
<HirId
> ());
356 void accept_vis (TyVisitor
&vis
) override
;
357 void accept_vis (TyConstVisitor
&vis
) const override
;
359 std::string
as_string () const override
;
361 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
363 BaseType
*clone () const final override
;
365 std::string
get_name () const override final
;
368 class ParamType
: public BaseType
371 static constexpr auto KIND
= TypeKind::PARAM
;
373 ParamType (std::string symbol
, location_t locus
, HirId ref
,
374 HIR::GenericParam
¶m
,
375 std::vector
<TypeBoundPredicate
> specified_bounds
,
376 std::set
<HirId
> refs
= std::set
<HirId
> ());
378 ParamType (bool is_trait_self
, std::string symbol
, location_t locus
,
379 HirId ref
, HirId ty_ref
, HIR::GenericParam
¶m
,
380 std::vector
<TypeBoundPredicate
> specified_bounds
,
381 std::set
<HirId
> refs
= std::set
<HirId
> ());
383 void accept_vis (TyVisitor
&vis
) override
;
384 void accept_vis (TyConstVisitor
&vis
) const override
;
386 std::string
as_string () const override
;
388 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
390 BaseType
*clone () const final override
;
392 std::string
get_symbol () const;
394 HIR::GenericParam
&get_generic_param ();
396 bool can_resolve () const;
398 BaseType
*resolve () const;
400 std::string
get_name () const override final
;
402 bool is_equal (const BaseType
&other
) const override
;
404 ParamType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
406 void set_implicit_self_trait ();
407 bool is_implicit_self_trait () const;
412 HIR::GenericParam
¶m
;
415 class OpaqueType
: public BaseType
418 static constexpr auto KIND
= TypeKind::OPAQUE
;
420 OpaqueType (location_t locus
, HirId ref
,
421 std::vector
<TypeBoundPredicate
> specified_bounds
,
422 std::set
<HirId
> refs
= std::set
<HirId
> ());
424 OpaqueType (location_t locus
, HirId ref
, HirId ty_ref
,
425 std::vector
<TypeBoundPredicate
> specified_bounds
,
426 std::set
<HirId
> refs
= std::set
<HirId
> ());
428 void accept_vis (TyVisitor
&vis
) override
;
429 void accept_vis (TyConstVisitor
&vis
) const override
;
431 std::string
as_string () const override
;
433 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
435 BaseType
*clone () const final override
;
437 bool can_resolve () const;
439 BaseType
*resolve () const;
441 std::string
get_name () const override final
;
443 bool is_equal (const BaseType
&other
) const override
;
445 OpaqueType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
448 class StructFieldType
451 StructFieldType (HirId ref
, std::string name
, BaseType
*ty
, location_t locus
);
453 HirId
get_ref () const;
455 bool is_equal (const StructFieldType
&other
) const;
457 std::string
get_name () const;
459 BaseType
*get_field_type () const;
460 void set_field_type (BaseType
*fty
);
462 StructFieldType
*clone () const;
463 StructFieldType
*monomorphized_clone () const;
466 location_t
get_locus () const;
467 std::string
as_string () const;
476 class TupleType
: public BaseType
479 static constexpr auto KIND
= TypeKind::TUPLE
;
481 TupleType (HirId ref
, location_t locus
,
482 std::vector
<TyVar
> fields
= std::vector
<TyVar
> (),
483 std::set
<HirId
> refs
= std::set
<HirId
> ());
485 TupleType (HirId ref
, HirId ty_ref
, location_t locus
,
486 std::vector
<TyVar
> fields
= std::vector
<TyVar
> (),
487 std::set
<HirId
> refs
= std::set
<HirId
> ());
489 static TupleType
*get_unit_type ();
491 void accept_vis (TyVisitor
&vis
) override
;
492 void accept_vis (TyConstVisitor
&vis
) const override
;
494 std::string
as_string () const override
;
496 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
498 bool is_equal (const BaseType
&other
) const override
;
500 size_t num_fields () const;
502 BaseType
*get_field (size_t index
) const;
504 BaseType
*clone () const final override
;
506 const std::vector
<TyVar
> &get_fields () const;
508 std::string
get_name () const override final
;
510 TupleType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
513 std::vector
<TyVar
> fields
;
516 class TypeBoundPredicate
: public SubstitutionRef
519 TypeBoundPredicate (const Resolver::TraitReference
&trait_reference
,
520 BoundPolarity polarity
, location_t locus
);
522 TypeBoundPredicate (DefId reference
,
523 std::vector
<SubstitutionParamMapping
> substitutions
,
524 BoundPolarity polarity
, location_t locus
);
526 TypeBoundPredicate (const TypeBoundPredicate
&other
);
528 virtual ~TypeBoundPredicate (){};
530 TypeBoundPredicate
&operator= (const TypeBoundPredicate
&other
);
532 static TypeBoundPredicate
error ();
534 std::string
as_string () const;
536 std::string
as_name () const;
538 const Resolver::TraitReference
*get () const;
540 location_t
get_locus () const { return locus
; }
542 std::string
get_name () const;
544 // check that this predicate is object-safe see:
545 // https://doc.rust-lang.org/reference/items/traits.html#object-safety
546 bool is_object_safe (bool emit_error
, location_t locus
) const;
548 void apply_generic_arguments (HIR::GenericArgs
*generic_args
,
549 bool has_associated_self
);
551 void apply_argument_mappings (SubstitutionArgumentMappings
&arguments
);
553 bool contains_item (const std::string
&search
) const;
555 TypeBoundPredicateItem
556 lookup_associated_item (const std::string
&search
) const;
558 TypeBoundPredicateItem
559 lookup_associated_item (const Resolver::TraitItemReference
*ref
) const;
561 // WARNING THIS WILL ALWAYS RETURN NULLPTR
563 handle_substitions (SubstitutionArgumentMappings
&mappings
) override final
;
565 bool is_error () const;
567 bool requires_generic_args () const;
569 bool contains_associated_types () const;
571 DefId
get_id () const { return reference
; }
573 BoundPolarity
get_polarity () const { return polarity
; }
575 std::vector
<TypeBoundPredicateItem
> get_associated_type_items ();
577 size_t get_num_associated_bindings () const override final
;
579 TypeBoundPredicateItem
580 lookup_associated_type (const std::string
&search
) override final
;
582 bool is_equal (const TypeBoundPredicate
&other
) const;
584 bool validate_type_implements_super_traits (TyTy::BaseType
&self
,
585 HIR::Type
&impl_type
,
586 HIR::Type
&trait
) const;
588 bool validate_type_implements_this (TyTy::BaseType
&self
,
589 HIR::Type
&impl_type
,
590 HIR::Type
&trait
) const;
597 TypeBoundPredicate (mark_is_error
);
602 BoundPolarity polarity
;
603 std::vector
<TyTy::TypeBoundPredicate
> super_traits
;
606 class TypeBoundPredicateItem
609 TypeBoundPredicateItem (const TypeBoundPredicate parent
,
610 const Resolver::TraitItemReference
*trait_item_ref
);
612 TypeBoundPredicateItem (const TypeBoundPredicateItem
&other
);
614 TypeBoundPredicateItem
&operator= (const TypeBoundPredicateItem
&other
);
616 static TypeBoundPredicateItem
error ();
618 bool is_error () const;
620 BaseType
*get_tyty_for_receiver (const TyTy::BaseType
*receiver
);
622 const Resolver::TraitItemReference
*get_raw_item () const;
624 bool needs_implementation () const;
626 const TypeBoundPredicate
*get_parent () const;
628 location_t
get_locus () const;
631 TypeBoundPredicate parent
;
632 const Resolver::TraitItemReference
*trait_item_ref
;
635 // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.VariantDef.html
646 static std::string
variant_type_string (VariantType type
);
648 VariantDef (HirId id
, DefId defid
, std::string identifier
, RustIdent ident
,
649 tl::optional
<std::unique_ptr
<HIR::Expr
>> &&discriminant
);
651 VariantDef (HirId id
, DefId defid
, std::string identifier
, RustIdent ident
,
653 tl::optional
<std::unique_ptr
<HIR::Expr
>> &&discriminant
,
654 std::vector
<StructFieldType
*> fields
);
656 static VariantDef
&get_error_node ();
657 bool is_error () const;
659 HirId
get_id () const;
660 DefId
get_defid () const;
662 VariantType
get_variant_type () const;
663 bool is_data_variant () const;
664 bool is_dataless_variant () const;
666 std::string
get_identifier () const;
668 size_t num_fields () const;
669 StructFieldType
*get_field_at_index (size_t index
);
671 std::vector
<StructFieldType
*> &get_fields ();
673 bool lookup_field (const std::string
&lookup
, StructFieldType
**field_lookup
,
674 size_t *index
) const;
676 bool has_discriminant () const;
678 HIR::Expr
&get_discriminant ();
679 const HIR::Expr
&get_discriminant () const;
681 std::string
as_string () const;
683 bool is_equal (const VariantDef
&other
) const;
685 VariantDef
*clone () const;
687 VariantDef
*monomorphized_clone () const;
689 const RustIdent
&get_ident () const;
694 std::string identifier
;
698 // can either be a structure or a discriminant value
699 tl::optional
<std::unique_ptr
<HIR::Expr
>> discriminant
;
701 std::vector
<StructFieldType
*> fields
;
704 class ADTType
: public BaseType
, public SubstitutionRef
707 static constexpr auto KIND
= TypeKind::ADT
;
729 // Representation options, specified via attributes e.g. #[repr(packed)]
732 ReprKind repr_kind
= ReprKind::RUST
;
734 // For align and pack: 0 = unspecified. Nonzero = byte alignment.
735 // It is an error for both to be nonzero, this should be caught when
736 // parsing the #[repr] attribute.
737 unsigned char align
= 0;
738 unsigned char pack
= 0;
739 BaseType
*repr
= nullptr;
742 ADTType (DefId id
, HirId ref
, std::string identifier
, RustIdent ident
,
743 ADTKind adt_kind
, std::vector
<VariantDef
*> variants
,
744 std::vector
<SubstitutionParamMapping
> subst_refs
,
745 SubstitutionArgumentMappings generic_arguments
746 = SubstitutionArgumentMappings::error (),
747 RegionConstraints region_constraints
= RegionConstraints
{},
748 std::set
<HirId
> refs
= std::set
<HirId
> ());
750 ADTType (DefId id
, HirId ref
, HirId ty_ref
, std::string identifier
,
751 RustIdent ident
, ADTKind adt_kind
,
752 std::vector
<VariantDef
*> variants
,
753 std::vector
<SubstitutionParamMapping
> subst_refs
,
754 SubstitutionArgumentMappings generic_arguments
755 = SubstitutionArgumentMappings::error (),
756 RegionConstraints region_constraints
= RegionConstraints
{},
757 std::set
<HirId
> refs
= std::set
<HirId
> ());
759 ADTType (DefId id
, HirId ref
, HirId ty_ref
, std::string identifier
,
760 RustIdent ident
, ADTKind adt_kind
,
761 std::vector
<VariantDef
*> variants
,
762 std::vector
<SubstitutionParamMapping
> subst_refs
, ReprOptions repr
,
763 SubstitutionArgumentMappings generic_arguments
764 = SubstitutionArgumentMappings::error (),
765 RegionConstraints region_constraints
= RegionConstraints
{},
766 std::set
<HirId
> refs
= std::set
<HirId
> ());
768 ADTKind
get_adt_kind () const { return adt_kind
; }
770 ReprOptions
get_repr_options () const { return repr
; }
772 bool is_struct_struct () const { return adt_kind
== STRUCT_STRUCT
; }
774 bool is_tuple_struct () const { return adt_kind
== TUPLE_STRUCT
; }
776 bool is_union () const { return adt_kind
== UNION
; }
778 bool is_enum () const { return adt_kind
== ENUM
; }
780 void accept_vis (TyVisitor
&vis
) override
;
782 void accept_vis (TyConstVisitor
&vis
) const override
;
784 std::string
as_string () const override
;
786 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
788 bool is_equal (const BaseType
&other
) const override
;
790 std::string
get_identifier () const { return identifier
; }
792 std::string
get_name () const override final
794 return identifier
+ subst_as_string ();
797 DefId
get_id () const;
799 BaseType
*clone () const final override
;
801 size_t number_of_variants () const { return variants
.size (); }
803 std::vector
<VariantDef
*> &get_variants () { return variants
; }
805 const std::vector
<VariantDef
*> &get_variants () const { return variants
; }
807 bool lookup_variant (const std::string
&lookup
,
808 VariantDef
**found_variant
) const
810 for (auto &variant
: variants
)
812 if (variant
->get_identifier ().compare (lookup
) == 0)
814 *found_variant
= variant
;
821 bool lookup_variant_by_id (HirId id
, VariantDef
**found_variant
,
822 int *index
= nullptr) const
825 for (auto &variant
: variants
)
827 if (variant
->get_id () == id
)
829 if (index
!= nullptr)
832 *found_variant
= variant
;
841 handle_substitions (SubstitutionArgumentMappings
&mappings
) override final
;
845 std::string identifier
;
846 std::vector
<VariantDef
*> variants
;
847 ADTType::ADTKind adt_kind
;
854 FnParam (std::unique_ptr
<HIR::Pattern
> pattern
, BaseType
*type
)
855 : pattern (std::move (pattern
)), type (type
)
858 FnParam (const FnParam
&) = delete;
859 FnParam (FnParam
&&) = default;
860 FnParam
&operator= (FnParam
&&) = default;
862 HIR::Pattern
&get_pattern () { return *pattern
; }
863 const HIR::Pattern
&get_pattern () const { return *pattern
; }
865 bool has_pattern () { return pattern
!= nullptr; }
866 BaseType
*get_type () const { return type
; }
867 void set_type (BaseType
*new_type
) { type
= new_type
; }
869 FnParam
clone () const
871 return FnParam (pattern
->clone_pattern (), type
->clone ());
874 FnParam
monomorphized_clone () const
876 return FnParam (pattern
->clone_pattern (), type
->monomorphized_clone ());
880 std::unique_ptr
<HIR::Pattern
> pattern
;
884 class FnType
: public CallableTypeInterface
, public SubstitutionRef
887 static constexpr auto KIND
= TypeKind::FNDEF
;
889 static const uint8_t FNTYPE_DEFAULT_FLAGS
= 0x00;
890 static const uint8_t FNTYPE_IS_METHOD_FLAG
= 0x01;
891 static const uint8_t FNTYPE_IS_EXTERN_FLAG
= 0x02;
892 static const uint8_t FNTYPE_IS_VARADIC_FLAG
= 0X04;
894 FnType (HirId ref
, DefId id
, std::string identifier
, RustIdent ident
,
895 uint8_t flags
, ABI abi
, std::vector
<FnParam
> params
, BaseType
*type
,
896 std::vector
<SubstitutionParamMapping
> subst_refs
,
897 SubstitutionArgumentMappings substitution_argument_mappings
,
898 RegionConstraints region_constraints
,
899 std::set
<HirId
> refs
= std::set
<HirId
> ())
900 : CallableTypeInterface (ref
, ref
, TypeKind::FNDEF
, ident
, refs
),
901 SubstitutionRef (std::move (subst_refs
), substitution_argument_mappings
,
903 params (std::move (params
)), type (type
), flags (flags
),
904 identifier (identifier
), id (id
), abi (abi
)
906 LocalDefId local_def_id
= id
.localDefId
;
907 rust_assert (local_def_id
!= UNKNOWN_LOCAL_DEFID
);
910 FnType (HirId ref
, HirId ty_ref
, DefId id
, std::string identifier
,
911 RustIdent ident
, uint8_t flags
, ABI abi
, std::vector
<FnParam
> params
,
912 BaseType
*type
, std::vector
<SubstitutionParamMapping
> subst_refs
,
913 SubstitutionArgumentMappings substitution_argument_mappings
,
914 RegionConstraints region_constraints
,
915 std::set
<HirId
> refs
= std::set
<HirId
> ())
916 : CallableTypeInterface (ref
, ty_ref
, TypeKind::FNDEF
, ident
, refs
),
917 SubstitutionRef (std::move (subst_refs
), substitution_argument_mappings
,
919 params (std::move (params
)), type (type
), flags (flags
),
920 identifier (identifier
), id (id
), abi (abi
)
922 LocalDefId local_def_id
= id
.localDefId
;
923 rust_assert (local_def_id
!= UNKNOWN_LOCAL_DEFID
);
926 FnType (const FnType
&) = delete;
927 FnType (FnType
&&) = default;
929 void accept_vis (TyVisitor
&vis
) override
;
930 void accept_vis (TyConstVisitor
&vis
) const override
;
932 std::string
as_string () const override
;
934 std::string
get_name () const override final
{ return as_string (); }
936 std::string
get_identifier () const { return identifier
; }
938 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
940 bool is_equal (const BaseType
&other
) const override
;
942 size_t num_params () const { return params
.size (); }
944 bool is_method () const
946 if (num_params () == 0)
949 return (flags
& FNTYPE_IS_METHOD_FLAG
) != 0;
952 bool is_extern () const { return (flags
& FNTYPE_IS_EXTERN_FLAG
) != 0; }
954 bool is_variadic () const { return (flags
& FNTYPE_IS_VARADIC_FLAG
) != 0; }
956 DefId
get_id () const { return id
; }
958 // get the Self type for the method
959 BaseType
*get_self_type () const
961 rust_assert (is_method ());
962 return param_at (0).get_type ();
965 std::vector
<FnParam
> &get_params () { return params
; }
967 const std::vector
<FnParam
> &get_params () const { return params
; }
969 FnParam
¶m_at (size_t idx
) { return params
.at (idx
); }
971 const FnParam
¶m_at (size_t idx
) const { return params
.at (idx
); }
973 BaseType
*clone () const final override
;
976 handle_substitions (SubstitutionArgumentMappings
&mappings
) override final
;
978 ABI
get_abi () const { return abi
; }
979 uint8_t get_flags () const { return flags
; }
981 WARN_UNUSED_RESULT
size_t get_num_params () const override
983 return params
.size ();
986 WARN_UNUSED_RESULT BaseType
*get_param_type_at (size_t index
) const override
988 return param_at (index
).get_type ();
991 WARN_UNUSED_RESULT BaseType
*get_return_type () const override
997 std::vector
<FnParam
> params
;
1000 std::string identifier
;
1005 class FnPtr
: public CallableTypeInterface
1008 static constexpr auto KIND
= TypeKind::FNPTR
;
1010 FnPtr (HirId ref
, location_t locus
, std::vector
<TyVar
> params
,
1011 TyVar result_type
, std::set
<HirId
> refs
= std::set
<HirId
> ())
1012 : CallableTypeInterface (ref
, ref
, TypeKind::FNPTR
,
1013 {Resolver::CanonicalPath::create_empty (), locus
},
1015 params (std::move (params
)), result_type (result_type
)
1018 FnPtr (HirId ref
, HirId ty_ref
, location_t locus
, std::vector
<TyVar
> params
,
1019 TyVar result_type
, std::set
<HirId
> refs
= std::set
<HirId
> ())
1020 : CallableTypeInterface (ref
, ty_ref
, TypeKind::FNPTR
,
1021 {Resolver::CanonicalPath::create_empty (), locus
},
1023 params (params
), result_type (result_type
)
1026 std::string
get_name () const override final
{ return as_string (); }
1028 WARN_UNUSED_RESULT
size_t get_num_params () const override
1030 return params
.size ();
1033 WARN_UNUSED_RESULT BaseType
*get_param_type_at (size_t index
) const override
1035 return params
.at (index
).get_tyty ();
1038 WARN_UNUSED_RESULT BaseType
*get_return_type () const override
1040 return result_type
.get_tyty ();
1043 const TyVar
&get_var_return_type () const { return result_type
; }
1045 size_t num_params () const { return params
.size (); }
1047 void accept_vis (TyVisitor
&vis
) override
;
1048 void accept_vis (TyConstVisitor
&vis
) const override
;
1050 std::string
as_string () const override
;
1052 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1054 bool is_equal (const BaseType
&other
) const override
;
1056 BaseType
*clone () const final override
;
1058 std::vector
<TyVar
> &get_params () { return params
; }
1059 const std::vector
<TyVar
> &get_params () const { return params
; }
1062 std::vector
<TyVar
> params
;
1066 class ClosureType
: public CallableTypeInterface
, public SubstitutionRef
1069 static constexpr auto KIND
= TypeKind::CLOSURE
;
1071 ClosureType (HirId ref
, DefId id
, RustIdent ident
, TupleType
*parameters
,
1073 std::vector
<SubstitutionParamMapping
> subst_refs
,
1074 std::set
<NodeId
> captures
,
1075 std::set
<HirId
> refs
= std::set
<HirId
> (),
1076 std::vector
<TypeBoundPredicate
> specified_bounds
1077 = std::vector
<TypeBoundPredicate
> ())
1078 : CallableTypeInterface (ref
, ref
, TypeKind::CLOSURE
, ident
, refs
),
1079 SubstitutionRef (std::move (subst_refs
),
1080 SubstitutionArgumentMappings::error (),
1081 {}), // TODO: check region constraints
1082 parameters (parameters
), result_type (std::move (result_type
)), id (id
),
1085 LocalDefId local_def_id
= id
.localDefId
;
1086 rust_assert (local_def_id
!= UNKNOWN_LOCAL_DEFID
);
1087 inherit_bounds (specified_bounds
);
1090 ClosureType (HirId ref
, HirId ty_ref
, RustIdent ident
, DefId id
,
1091 TupleType
*parameters
, TyVar result_type
,
1092 std::vector
<SubstitutionParamMapping
> subst_refs
,
1093 std::set
<NodeId
> captures
,
1094 std::set
<HirId
> refs
= std::set
<HirId
> (),
1095 std::vector
<TypeBoundPredicate
> specified_bounds
1096 = std::vector
<TypeBoundPredicate
> ())
1097 : CallableTypeInterface (ref
, ty_ref
, TypeKind::CLOSURE
, ident
, refs
),
1098 SubstitutionRef (std::move (subst_refs
),
1099 SubstitutionArgumentMappings::error (), {}), // TODO
1100 parameters (parameters
), result_type (std::move (result_type
)), id (id
),
1103 LocalDefId local_def_id
= id
.localDefId
;
1104 rust_assert (local_def_id
!= UNKNOWN_LOCAL_DEFID
);
1105 inherit_bounds (specified_bounds
);
1108 void accept_vis (TyVisitor
&vis
) override
;
1109 void accept_vis (TyConstVisitor
&vis
) const override
;
1111 WARN_UNUSED_RESULT
size_t get_num_params () const override
1113 return parameters
->num_fields ();
1116 WARN_UNUSED_RESULT BaseType
*get_param_type_at (size_t index
) const override
1118 return parameters
->get_field (index
);
1121 WARN_UNUSED_RESULT BaseType
*get_return_type () const override
1123 return result_type
.get_tyty ();
1126 std::string
as_string () const override
;
1127 std::string
get_name () const override final
{ return as_string (); }
1129 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1131 bool is_equal (const BaseType
&other
) const override
;
1133 BaseType
*clone () const final override
;
1136 handle_substitions (SubstitutionArgumentMappings
&mappings
) override final
;
1138 TyTy::TupleType
&get_parameters () const { return *parameters
; }
1139 TyTy::BaseType
&get_result_type () const { return *result_type
.get_tyty (); }
1141 DefId
get_def_id () const { return id
; }
1143 void setup_fn_once_output () const;
1145 const std::set
<NodeId
> &get_captures () const { return captures
; }
1148 TyTy::TupleType
*parameters
;
1151 std::set
<NodeId
> captures
;
1154 class ArrayType
: public BaseType
1157 static constexpr auto KIND
= TypeKind::ARRAY
;
1159 ArrayType (HirId ref
, location_t locus
, HIR::Expr
&capacity_expr
, TyVar base
,
1160 std::set
<HirId
> refs
= std::set
<HirId
> ())
1161 : BaseType (ref
, ref
, TypeKind::ARRAY
,
1162 {Resolver::CanonicalPath::create_empty (), locus
}, refs
),
1163 element_type (base
), capacity_expr (capacity_expr
)
1166 ArrayType (HirId ref
, HirId ty_ref
, location_t locus
,
1167 HIR::Expr
&capacity_expr
, TyVar base
,
1168 std::set
<HirId
> refs
= std::set
<HirId
> ())
1169 : BaseType (ref
, ty_ref
, TypeKind::ARRAY
,
1170 {Resolver::CanonicalPath::create_empty (), locus
}, refs
),
1171 element_type (base
), capacity_expr (capacity_expr
)
1174 void accept_vis (TyVisitor
&vis
) override
;
1175 void accept_vis (TyConstVisitor
&vis
) const override
;
1177 std::string
as_string () const override
;
1179 std::string
get_name () const override final
{ return as_string (); }
1181 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1183 bool is_equal (const BaseType
&other
) const override
;
1185 BaseType
*get_element_type () const;
1186 const TyVar
&get_var_element_type () const;
1188 BaseType
*clone () const final override
;
1190 HIR::Expr
&get_capacity_expr () const { return capacity_expr
; }
1192 ArrayType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
1196 // FIXME: I dont think this should be in tyty - tyty should already be const
1198 HIR::Expr
&capacity_expr
;
1201 class SliceType
: public BaseType
1204 static constexpr auto KIND
= TypeKind::SLICE
;
1206 SliceType (HirId ref
, location_t locus
, TyVar base
,
1207 std::set
<HirId
> refs
= std::set
<HirId
> ())
1208 : BaseType (ref
, ref
, TypeKind::SLICE
,
1209 {Resolver::CanonicalPath::create_empty (), locus
}, refs
),
1213 SliceType (HirId ref
, HirId ty_ref
, location_t locus
, TyVar base
,
1214 std::set
<HirId
> refs
= std::set
<HirId
> ())
1215 : BaseType (ref
, ty_ref
, TypeKind::SLICE
,
1216 {Resolver::CanonicalPath::create_empty (), locus
}, refs
),
1220 void accept_vis (TyVisitor
&vis
) override
;
1221 void accept_vis (TyConstVisitor
&vis
) const override
;
1223 std::string
as_string () const override
;
1225 std::string
get_name () const override final
{ return as_string (); }
1227 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1229 bool is_equal (const BaseType
&other
) const override
;
1231 BaseType
*get_element_type () const;
1232 const TyVar
&get_var_element_type () const;
1234 BaseType
*clone () const final override
;
1236 SliceType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
1242 class BoolType
: public BaseType
1245 static constexpr auto KIND
= TypeKind::BOOL
;
1247 BoolType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1248 BoolType (HirId ref
, HirId ty_ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1250 void accept_vis (TyVisitor
&vis
) override
;
1251 void accept_vis (TyConstVisitor
&vis
) const override
;
1253 std::string
as_string () const override
;
1255 std::string
get_name () const override final
;
1257 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1259 BaseType
*clone () const final override
;
1262 class IntType
: public BaseType
1274 static constexpr auto KIND
= TypeKind::INT
;
1276 IntType (HirId ref
, IntKind kind
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1277 IntType (HirId ref
, HirId ty_ref
, IntKind kind
,
1278 std::set
<HirId
> refs
= std::set
<HirId
> ());
1280 void accept_vis (TyVisitor
&vis
) override
;
1281 void accept_vis (TyConstVisitor
&vis
) const override
;
1283 std::string
as_string () const override
;
1285 std::string
get_name () const override final
;
1287 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1289 IntKind
get_int_kind () const;
1291 BaseType
*clone () const final override
;
1293 bool is_equal (const BaseType
&other
) const override
;
1299 class UintType
: public BaseType
1302 static constexpr auto KIND
= TypeKind::UINT
;
1313 UintType (HirId ref
, UintKind kind
,
1314 std::set
<HirId
> refs
= std::set
<HirId
> ());
1315 UintType (HirId ref
, HirId ty_ref
, UintKind kind
,
1316 std::set
<HirId
> refs
= std::set
<HirId
> ());
1318 void accept_vis (TyVisitor
&vis
) override
;
1319 void accept_vis (TyConstVisitor
&vis
) const override
;
1321 std::string
as_string () const override
;
1323 std::string
get_name () const override final
;
1325 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1327 UintKind
get_uint_kind () const;
1329 BaseType
*clone () const final override
;
1331 bool is_equal (const BaseType
&other
) const override
;
1337 class FloatType
: public BaseType
1340 static constexpr auto KIND
= TypeKind::FLOAT
;
1348 FloatType (HirId ref
, FloatKind kind
,
1349 std::set
<HirId
> refs
= std::set
<HirId
> ());
1350 FloatType (HirId ref
, HirId ty_ref
, FloatKind kind
,
1351 std::set
<HirId
> refs
= std::set
<HirId
> ());
1353 void accept_vis (TyVisitor
&vis
) override
;
1354 void accept_vis (TyConstVisitor
&vis
) const override
;
1356 std::string
as_string () const override
;
1357 std::string
get_name () const override final
;
1359 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1361 FloatKind
get_float_kind () const;
1363 BaseType
*clone () const final override
;
1365 bool is_equal (const BaseType
&other
) const override
;
1368 FloatKind float_kind
;
1371 class USizeType
: public BaseType
1374 static constexpr auto KIND
= TypeKind::USIZE
;
1376 USizeType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1377 USizeType (HirId ref
, HirId ty_ref
,
1378 std::set
<HirId
> refs
= std::set
<HirId
> ());
1380 void accept_vis (TyVisitor
&vis
) override
;
1381 void accept_vis (TyConstVisitor
&vis
) const override
;
1383 std::string
as_string () const override
;
1384 std::string
get_name () const override final
;
1386 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1388 BaseType
*clone () const final override
;
1391 class ISizeType
: public BaseType
1394 static constexpr auto KIND
= TypeKind::ISIZE
;
1396 ISizeType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1397 ISizeType (HirId ref
, HirId ty_ref
,
1398 std::set
<HirId
> refs
= std::set
<HirId
> ());
1400 void accept_vis (TyVisitor
&vis
) override
;
1401 void accept_vis (TyConstVisitor
&vis
) const override
;
1403 std::string
as_string () const override
;
1404 std::string
get_name () const override final
;
1406 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1408 BaseType
*clone () const final override
;
1411 class CharType
: public BaseType
1414 static constexpr auto KIND
= TypeKind::CHAR
;
1416 CharType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1417 CharType (HirId ref
, HirId ty_ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1419 void accept_vis (TyVisitor
&vis
) override
;
1420 void accept_vis (TyConstVisitor
&vis
) const override
;
1422 std::string
as_string () const override
;
1423 std::string
get_name () const override final
;
1425 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1427 BaseType
*clone () const final override
;
1430 class StrType
: public BaseType
1433 static constexpr auto KIND
= TypeKind::STR
;
1435 StrType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1436 StrType (HirId ref
, HirId ty_ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1438 std::string
get_name () const override final
;
1440 void accept_vis (TyVisitor
&vis
) override
;
1441 void accept_vis (TyConstVisitor
&vis
) const override
;
1443 std::string
as_string () const override
;
1445 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1447 bool is_equal (const BaseType
&other
) const override
;
1449 BaseType
*clone () const final override
;
1452 class DynamicObjectType
: public BaseType
1455 static constexpr auto KIND
= TypeKind::DYNAMIC
;
1457 DynamicObjectType (HirId ref
, RustIdent ident
,
1458 std::vector
<TypeBoundPredicate
> specified_bounds
,
1459 std::set
<HirId
> refs
= std::set
<HirId
> ());
1461 DynamicObjectType (HirId ref
, HirId ty_ref
, RustIdent ident
,
1462 std::vector
<TypeBoundPredicate
> specified_bounds
,
1463 std::set
<HirId
> refs
= std::set
<HirId
> ());
1465 void accept_vis (TyVisitor
&vis
) override
;
1466 void accept_vis (TyConstVisitor
&vis
) const override
;
1468 std::string
as_string () const override
;
1470 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1472 bool is_equal (const BaseType
&other
) const override
;
1474 BaseType
*clone () const final override
;
1476 std::string
get_name () const override final
;
1478 // this returns a flat list of items including super trait bounds
1480 std::pair
<const Resolver::TraitItemReference
*, const TypeBoundPredicate
*>>
1481 get_object_items () const;
1484 class ReferenceType
: public BaseType
1487 static constexpr auto KIND
= REF
;
1489 ReferenceType (HirId ref
, TyVar base
, Mutability mut
,
1490 Region region
= Region::make_anonymous (),
1491 std::set
<HirId
> refs
= std::set
<HirId
> ());
1492 ReferenceType (HirId ref
, HirId ty_ref
, TyVar base
, Mutability mut
,
1493 Region region
= Region::make_anonymous (),
1494 std::set
<HirId
> refs
= std::set
<HirId
> ());
1496 BaseType
*get_base () const;
1497 const TyVar
&get_var_element_type () const;
1499 void accept_vis (TyVisitor
&vis
) override
;
1500 void accept_vis (TyConstVisitor
&vis
) const override
;
1502 std::string
as_string () const override
;
1504 std::string
get_name () const override final
;
1506 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1508 bool is_equal (const BaseType
&other
) const override
;
1510 BaseType
*clone () const final override
;
1512 ReferenceType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
1514 Mutability
mutability () const;
1515 bool is_mutable () const;
1517 WARN_UNUSED_RESULT Region
get_region () const;
1518 void set_region (Region region
);
1520 bool is_dyn_object () const;
1521 bool is_dyn_slice_type (const TyTy::SliceType
**slice
= nullptr) const;
1522 bool is_dyn_str_type (const TyTy::StrType
**str
= nullptr) const;
1523 bool is_dyn_obj_type (const TyTy::DynamicObjectType
**dyn
= nullptr) const;
1531 class PointerType
: public BaseType
1534 static constexpr auto KIND
= TypeKind::POINTER
;
1536 PointerType (HirId ref
, TyVar base
, Mutability mut
,
1537 std::set
<HirId
> refs
= std::set
<HirId
> ());
1538 PointerType (HirId ref
, HirId ty_ref
, TyVar base
, Mutability mut
,
1539 std::set
<HirId
> refs
= std::set
<HirId
> ());
1541 BaseType
*get_base () const;
1542 const TyVar
&get_var_element_type () const;
1544 void accept_vis (TyVisitor
&vis
) override
;
1545 void accept_vis (TyConstVisitor
&vis
) const override
;
1547 std::string
as_string () const override
;
1548 std::string
get_name () const override final
;
1550 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1552 bool is_equal (const BaseType
&other
) const override
;
1554 BaseType
*clone () const final override
;
1556 PointerType
*handle_substitions (SubstitutionArgumentMappings
&mappings
);
1558 Mutability
mutability () const;
1559 bool is_mutable () const;
1560 bool is_const () const;
1561 bool is_dyn_object () const;
1562 bool is_dyn_slice_type (const TyTy::SliceType
**slice
= nullptr) const;
1563 bool is_dyn_str_type (const TyTy::StrType
**str
= nullptr) const;
1564 bool is_dyn_obj_type (const TyTy::DynamicObjectType
**dyn
= nullptr) const;
1571 // https://doc.rust-lang.org/std/primitive.never.html
1573 // Since the `!` type is really complicated and it is even still unstable
1574 // in rustc, only fairly limited support for this type is introduced here.
1575 // Unification between `!` and ANY other type (including `<T?>`) is simply
1576 // not allowed. If it is needed, it should be handled manually. For example,
1577 // unifying `!` with other types is very necessary when resolving types of
1578 // `if/else` expressions.
1580 // See related discussion at https://github.com/Rust-GCC/gccrs/pull/364
1581 class NeverType
: public BaseType
1584 static constexpr auto KIND
= TypeKind::NEVER
;
1586 NeverType (HirId ref
, std::set
<HirId
> refs
= std::set
<HirId
> ());
1588 NeverType (HirId ref
, HirId ty_ref
,
1589 std::set
<HirId
> refs
= std::set
<HirId
> ());
1591 void accept_vis (TyVisitor
&vis
) override
;
1593 void accept_vis (TyConstVisitor
&vis
) const override
;
1595 std::string
as_string () const override
;
1597 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1599 BaseType
*clone () const final override
;
1601 std::string
get_name () const override final
;
1604 // used at the type in associated types in traits
1605 // see: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
1606 class PlaceholderType
: public BaseType
1609 static constexpr auto KIND
= TypeKind::PLACEHOLDER
;
1611 PlaceholderType (std::string symbol
, DefId id
, HirId ref
,
1612 std::set
<HirId
> refs
= std::set
<HirId
> ());
1613 PlaceholderType (std::string symbol
, DefId id
, HirId ref
, HirId ty_ref
,
1614 std::set
<HirId
> refs
= std::set
<HirId
> ());
1616 void accept_vis (TyVisitor
&vis
) override
;
1617 void accept_vis (TyConstVisitor
&vis
) const override
;
1619 std::string
as_string () const override
;
1621 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1623 BaseType
*clone () const final override
;
1625 std::string
get_name () const override final
;
1627 std::string
get_symbol () const;
1629 void set_associated_type (HirId ref
);
1631 void clear_associated_type ();
1633 bool can_resolve () const;
1635 BaseType
*resolve () const;
1637 bool is_equal (const BaseType
&other
) const override
;
1639 DefId
get_def_id () const;
1646 class ProjectionType
: public BaseType
, public SubstitutionRef
1649 static constexpr auto KIND
= TypeKind::PROJECTION
;
1651 ProjectionType (HirId ref
, BaseType
*base
,
1652 const Resolver::TraitReference
*trait
, DefId item
,
1653 std::vector
<SubstitutionParamMapping
> subst_refs
,
1654 SubstitutionArgumentMappings generic_arguments
1655 = SubstitutionArgumentMappings::error (),
1656 RegionConstraints region_constraints
= {},
1657 std::set
<HirId
> refs
= std::set
<HirId
> ());
1659 ProjectionType (HirId ref
, HirId ty_ref
, BaseType
*base
,
1660 const Resolver::TraitReference
*trait
, DefId item
,
1661 std::vector
<SubstitutionParamMapping
> subst_refs
,
1662 SubstitutionArgumentMappings generic_arguments
1663 = SubstitutionArgumentMappings::error (),
1664 RegionConstraints region_constraints
= {},
1665 std::set
<HirId
> refs
= std::set
<HirId
> ());
1667 void accept_vis (TyVisitor
&vis
) override
;
1668 void accept_vis (TyConstVisitor
&vis
) const override
;
1670 std::string
as_string () const override
;
1672 bool can_eq (const BaseType
*other
, bool emit_errors
) const override final
;
1674 BaseType
*clone () const final override
;
1676 std::string
get_name () const override final
;
1678 const BaseType
*get () const;
1682 handle_substitions (SubstitutionArgumentMappings
&mappings
) override final
;
1686 const Resolver::TraitReference
*trait
;
1691 WARN_UNUSED_RESULT
inline bool
1692 BaseType::is
<CallableTypeInterface
> () const
1694 auto kind
= this->get_kind ();
1695 return kind
== FNPTR
|| kind
== FNDEF
|| kind
== CLOSURE
;
1699 WARN_UNUSED_RESULT
inline bool
1700 BaseType::is
<const CallableTypeInterface
> () const
1702 return this->is
<CallableTypeInterface
> ();
1706 WARN_UNUSED_RESULT
inline bool
1707 BaseType::is
<SubstitutionRef
> () const
1709 auto kind
= this->get_kind ();
1710 return kind
== FNPTR
|| kind
== FNDEF
|| kind
== CLOSURE
|| kind
== ADT
1711 || kind
== PROJECTION
;
1715 WARN_UNUSED_RESULT
inline bool
1716 BaseType::is
<const SubstitutionRef
> () const
1718 return this->is
<SubstitutionRef
> ();
1722 WARN_UNUSED_RESULT
inline SubstitutionRef
*
1723 BaseType::as
<SubstitutionRef
> ()
1725 auto kind
= this->get_kind ();
1729 return static_cast<FnType
*> (this);
1731 return static_cast<ClosureType
*> (this);
1733 return static_cast<ADTType
*> (this);
1735 return static_cast<ProjectionType
*> (this);
1737 rust_unreachable ();
1742 WARN_UNUSED_RESULT
inline const SubstitutionRef
*
1743 BaseType::as
<const SubstitutionRef
> () const
1745 auto kind
= this->get_kind ();
1749 return static_cast<const FnType
*> (this);
1751 return static_cast<const ClosureType
*> (this);
1753 return static_cast<const ADTType
*> (this);
1755 return static_cast<const ProjectionType
*> (this);
1757 rust_unreachable ();
1762 WARN_UNUSED_RESULT
inline SubstitutionRef
*
1763 BaseType::try_as
<SubstitutionRef
> ()
1765 if (this->is
<SubstitutionRef
> ())
1767 return this->as
<SubstitutionRef
> ();
1773 WARN_UNUSED_RESULT
inline const SubstitutionRef
*
1774 BaseType::try_as
<const SubstitutionRef
> () const
1776 if (this->is
<const SubstitutionRef
> ())
1778 return this->as
<const SubstitutionRef
> ();