@@ -31,6 +31,13 @@ maybe_get_vis_item (std::unique_ptr<HIR::Item> &item)
31
31
return static_cast <HIR::VisItem *> (item.get ());
32
32
}
33
33
34
+ ReachLevel
35
+ ReachabilityVisitor::get_reachability_level (
36
+ const HIR::Visibility &item_visibility)
37
+ {
38
+ return item_visibility.is_public () ? current_level : ReachLevel::Unreachable;
39
+ }
40
+
34
41
void
35
42
ReachabilityVisitor::visit_generic_predicates (
36
43
const std::vector<std::unique_ptr<HIR::GenericParam>> &generics,
@@ -39,25 +46,21 @@ ReachabilityVisitor::visit_generic_predicates (
39
46
if (item_reach == ReachLevel::Unreachable)
40
47
return ;
41
48
42
- for (auto &generic : generics)
49
+ for (const auto &generic : generics)
43
50
{
44
51
if (generic->get_kind () == HIR::GenericParam::TYPE)
45
52
{
46
53
TyTy::BaseType *generic_ty = nullptr ;
47
- rust_assert (
48
- ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
49
- &generic_ty));
54
+ auto ok = ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
55
+ &generic_ty);
56
+ rust_assert (ok);
57
+ rust_assert (generic_ty->get_kind () == TyTy::PARAM);
50
58
51
- // FIXME: Can we really get anything else than a TyTy::PARAM here?
52
- // Should we change this to an assertion instead?
53
- if (generic_ty->get_kind () == TyTy::PARAM)
59
+ auto generic_param = static_cast <TyTy::ParamType *> (generic_ty);
60
+ for (const auto &bound : generic_param->get_specified_bounds ())
54
61
{
55
- auto generic_param = static_cast <TyTy::ParamType *> (generic_ty);
56
- for (const auto &bound : generic_param->get_specified_bounds ())
57
- {
58
- const auto trait = bound.get ()->get_hir_trait_ref ();
59
- ctx.update_reachability (trait->get_mappings (), item_reach);
60
- }
62
+ const auto trait = bound.get ()->get_hir_trait_ref ();
63
+ ctx.update_reachability (trait->get_mappings (), item_reach);
61
64
}
62
65
}
63
66
}
@@ -88,18 +91,25 @@ ReachabilityVisitor::visit (HIR::UseDeclaration &use_decl)
88
91
89
92
void
90
93
ReachabilityVisitor::visit (HIR::Function &func)
91
- {}
94
+ {
95
+ auto fn_reach = get_reachability_level (func.get_visibility ());
96
+
97
+ fn_reach = ctx.update_reachability (func.get_mappings (), fn_reach);
98
+ visit_generic_predicates (func.get_generic_params (), fn_reach);
99
+ }
92
100
93
101
void
94
102
ReachabilityVisitor::visit (HIR::TypeAlias &type_alias)
95
- {}
103
+ {
104
+ auto type_reach = get_reachability_level (type_alias.get_visibility ());
105
+
106
+ visit_generic_predicates (type_alias.get_generic_params (), type_reach);
107
+ }
96
108
97
109
void
98
110
ReachabilityVisitor::visit (HIR::StructStruct &struct_item)
99
111
{
100
- auto struct_reach = ReachLevel::Unreachable;
101
- if (struct_item.get_visibility ().is_public ())
102
- struct_reach = current_level;
112
+ auto struct_reach = get_reachability_level (struct_item.get_visibility ());
103
113
104
114
struct_reach
105
115
= ctx.update_reachability (struct_item.get_mappings (), struct_reach);
@@ -126,11 +136,22 @@ ReachabilityVisitor::visit (HIR::TupleStruct &tuple_struct)
126
136
127
137
void
128
138
ReachabilityVisitor::visit (HIR::Enum &enum_item)
129
- {}
139
+ {
140
+ auto enum_reach = get_reachability_level (enum_item.get_visibility ());
141
+
142
+ enum_reach = ctx.update_reachability (enum_item.get_mappings (), enum_reach);
143
+ visit_generic_predicates (enum_item.get_generic_params (), enum_reach);
144
+ }
130
145
131
146
void
132
147
ReachabilityVisitor::visit (HIR::Union &union_item)
133
- {}
148
+ {
149
+ auto union_reach = get_reachability_level (union_item.get_visibility ());
150
+
151
+ union_reach
152
+ = ctx.update_reachability (union_item.get_mappings (), union_reach);
153
+ visit_generic_predicates (union_item.get_generic_params (), union_reach);
154
+ }
134
155
135
156
void
136
157
ReachabilityVisitor::visit (HIR::ConstantItem &const_item)
@@ -142,11 +163,21 @@ ReachabilityVisitor::visit (HIR::StaticItem &static_item)
142
163
143
164
void
144
165
ReachabilityVisitor::visit (HIR::Trait &trait)
145
- {}
166
+ {
167
+ auto trait_reach = get_reachability_level (trait.get_visibility ());
168
+
169
+ trait_reach = ctx.update_reachability (trait.get_mappings (), trait_reach);
170
+ visit_generic_predicates (trait.get_generic_params (), trait_reach);
171
+ }
146
172
147
173
void
148
174
ReachabilityVisitor::visit (HIR::ImplBlock &impl)
149
- {}
175
+ {
176
+ auto impl_reach = get_reachability_level (impl.get_visibility ());
177
+
178
+ impl_reach = ctx.update_reachability (impl.get_mappings (), impl_reach);
179
+ visit_generic_predicates (impl.get_generic_params (), impl_reach);
180
+ }
150
181
151
182
void
152
183
ReachabilityVisitor::visit (HIR::ExternBlock &block)
0 commit comments