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 2212 : 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 8079 : 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 : void visit (HIR::Function &function) override;
54 : void visit (HIR::ConstantItem &const_item) override;
55 : void visit (HIR::TypeAlias &type_alias) override;
56 :
57 : protected:
58 : TypeCheckImplItem (HIR::ImplBlock &parent, TyTy::BaseType *self,
59 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
60 :
61 : HIR::ImplBlock &parent;
62 : TyTy::BaseType *self;
63 : std::vector<TyTy::SubstitutionParamMapping> substitutions;
64 :
65 : TyTy::BaseType *result = nullptr;
66 : };
67 :
68 : class TypeCheckImplItemWithTrait : public TypeCheckBase,
69 : public HIR::HIRImplVisitor
70 : {
71 : public:
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);
76 :
77 : void visit (HIR::ConstantItem &constant) override;
78 : void visit (HIR::TypeAlias &type) override;
79 : void visit (HIR::Function &function) override;
80 :
81 : protected:
82 : // this allows us to inherit the must_use specified on a trait definition onto
83 : // its implementation
84 : void merge_attributes (AST::AttrVec &impl_item_attrs,
85 : const HIR::TraitItem &trait_item);
86 :
87 : private:
88 : TypeCheckImplItemWithTrait (
89 : HIR::ImplBlock &parent, TyTy::BaseType *self,
90 : TyTy::TypeBoundPredicate &trait_reference,
91 : std::vector<TyTy::SubstitutionParamMapping> substitutions);
92 :
93 : bool is_trait_impl_block () const;
94 :
95 : TyTy::TypeBoundPredicate &trait_reference;
96 : TyTy::TypeBoundPredicateItem resolved_trait_item;
97 :
98 : HIR::ImplBlock &parent;
99 : TyTy::BaseType *self;
100 : std::vector<TyTy::SubstitutionParamMapping> substitutions;
101 : TyTy::RegionConstraints region_constraints;
102 : };
103 :
104 : } // namespace Resolver
105 : } // namespace Rust
106 :
107 : #endif // RUST_HIR_TYPE_CHECK_IMPLITEM_H
|