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 : #ifndef RUST_HIR_TYPE_CHECK_IMPLITEM_H
20 : #define RUST_HIR_TYPE_CHECK_IMPLITEM_H
21 :
22 : #include "rust-hir-type-check-base.h"
23 : #include "rust-hir-visitor.h"
24 :
25 : namespace Rust {
26 : namespace Resolver {
27 :
28 2689 : class TypeCheckTopLevelExternItem : public TypeCheckBase,
29 : public HIR::HIRExternalItemVisitor
30 : {
31 : public:
32 : static TyTy::BaseType *Resolve (HIR::ExternalItem &item,
33 : const HIR::ExternBlock &parent);
34 :
35 : void visit (HIR::ExternalStaticItem &item) override;
36 : void visit (HIR::ExternalFunctionItem &function) override;
37 : void visit (HIR::ExternalTypeItem &type) override;
38 :
39 : private:
40 : TypeCheckTopLevelExternItem (const HIR::ExternBlock &parent);
41 :
42 : const HIR::ExternBlock &parent;
43 : TyTy::BaseType *resolved;
44 : };
45 :
46 11408 : class TypeCheckImplItem : public TypeCheckBase, public HIR::HIRImplVisitor
47 : {
48 : public:
49 : static TyTy::BaseType *
50 : Resolve (HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self,
51 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
52 :
53 : static TyTy::FnType *ResolveFunctionSignature (
54 : HIR::ImplBlock &parent, HIR::Function &function, TyTy::BaseType *self,
55 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
56 :
57 : void visit (HIR::Function &function) override;
58 : void visit (HIR::ConstantItem &const_item) override;
59 : void visit (HIR::TypeAlias &type_alias) override;
60 :
61 : protected:
62 : TypeCheckImplItem (HIR::ImplBlock &parent, TyTy::BaseType *self,
63 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
64 :
65 : TyTy::FnType *resolve_function_signature (HIR::Function &function);
66 :
67 : HIR::ImplBlock &parent;
68 : TyTy::BaseType *self;
69 : std::vector<TyTy::SubstitutionParamMapping> substitutions;
70 :
71 : TyTy::BaseType *result = nullptr;
72 : };
73 :
74 : class TypeCheckImplItemWithTrait : public TypeCheckBase,
75 : public HIR::HIRImplVisitor
76 : {
77 : public:
78 : static TyTy::TypeBoundPredicateItem
79 : Resolve (HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self,
80 : TyTy::TypeBoundPredicate &trait_reference,
81 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
82 :
83 : void visit (HIR::ConstantItem &constant) override;
84 : void visit (HIR::TypeAlias &type) override;
85 : void visit (HIR::Function &function) override;
86 :
87 : protected:
88 : // this allows us to inherit the must_use specified on a trait definition onto
89 : // its implementation
90 : void merge_attributes (AST::AttrVec &impl_item_attrs,
91 : const HIR::TraitItem &trait_item);
92 :
93 : private:
94 : TypeCheckImplItemWithTrait (
95 : HIR::ImplBlock &parent, TyTy::BaseType *self,
96 : TyTy::TypeBoundPredicate &trait_reference,
97 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
98 :
99 : bool is_trait_impl_block () const;
100 :
101 : TyTy::TypeBoundPredicate &trait_reference;
102 : TyTy::TypeBoundPredicateItem resolved_trait_item;
103 :
104 : HIR::ImplBlock &parent;
105 : TyTy::BaseType *self;
106 : std::vector<TyTy::SubstitutionParamMapping> substitutions;
107 : TyTy::RegionConstraints region_constraints;
108 : };
109 :
110 : } // namespace Resolver
111 : } // namespace Rust
112 :
113 : #endif // RUST_HIR_TYPE_CHECK_IMPLITEM_H
|