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