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/>.
19 #ifndef RUST_HIR_TYPE_CHECK_IMPLITEM_H
20 #define RUST_HIR_TYPE_CHECK_IMPLITEM_H
22 #include "rust-hir-type-check-base.h"
23 #include "rust-hir-visitor.h"
28 class TypeCheckTopLevelExternItem
: public TypeCheckBase
,
29 public HIR::HIRExternalItemVisitor
32 static TyTy::BaseType
*Resolve (HIR::ExternalItem
*item
,
33 const HIR::ExternBlock
&parent
);
35 void visit (HIR::ExternalStaticItem
&item
) override
;
36 void visit (HIR::ExternalFunctionItem
&function
) override
;
37 void visit (HIR::ExternalTypeItem
&type
) override
;
40 TypeCheckTopLevelExternItem (const HIR::ExternBlock
&parent
);
42 const HIR::ExternBlock
&parent
;
43 TyTy::BaseType
*resolved
;
46 class TypeCheckImplItem
: public TypeCheckBase
, public HIR::HIRImplVisitor
49 static TyTy::BaseType
*
50 Resolve (HIR::ImplBlock
*parent
, HIR::ImplItem
*item
, TyTy::BaseType
*self
,
51 std::vector
<TyTy::SubstitutionParamMapping
> substitutions
);
53 void visit (HIR::Function
&function
) override
;
54 void visit (HIR::ConstantItem
&const_item
) override
;
55 void visit (HIR::TypeAlias
&type_alias
) override
;
58 TypeCheckImplItem (HIR::ImplBlock
*parent
, TyTy::BaseType
*self
,
59 std::vector
<TyTy::SubstitutionParamMapping
> substitutions
);
61 HIR::ImplBlock
*parent
;
63 std::vector
<TyTy::SubstitutionParamMapping
> substitutions
;
65 TyTy::BaseType
*result
= nullptr;
68 class TypeCheckImplItemWithTrait
: public TypeCheckBase
,
69 public HIR::HIRImplVisitor
72 static TyTy::TypeBoundPredicateItem
73 Resolve (HIR::ImplBlock
*parent
, HIR::ImplItem
*item
, TyTy::BaseType
*self
,
74 TyTy::TypeBoundPredicate
&trait_reference
,
75 std::vector
<TyTy::SubstitutionParamMapping
> substitutions
);
77 void visit (HIR::ConstantItem
&constant
) override
;
78 void visit (HIR::TypeAlias
&type
) override
;
79 void visit (HIR::Function
&function
) override
;
82 // this allows us to inherit the must_use specified on a trait definition onto
84 void merge_attributes (AST::AttrVec
&impl_item_attrs
,
85 const HIR::TraitItem
&trait_item
);
88 TypeCheckImplItemWithTrait (
89 HIR::ImplBlock
*parent
, TyTy::BaseType
*self
,
90 TyTy::TypeBoundPredicate
&trait_reference
,
91 std::vector
<TyTy::SubstitutionParamMapping
> substitutions
);
93 bool is_trait_impl_block () const;
95 TyTy::TypeBoundPredicate
&trait_reference
;
96 TyTy::TypeBoundPredicateItem resolved_trait_item
;
98 HIR::ImplBlock
*parent
;
100 std::vector
<TyTy::SubstitutionParamMapping
> substitutions
;
101 TyTy::RegionConstraints region_constraints
;
104 } // namespace Resolver
107 #endif // RUST_HIR_TYPE_CHECK_IMPLITEM_H