@@ -31,6 +31,38 @@ maybe_get_vis_item (std::unique_ptr<HIR::Item> &item)
31
31
return static_cast <HIR::VisItem *> (item.get ());
32
32
}
33
33
34
+ void
35
+ ReachabilityVisitor::visit_generic_predicates (
36
+ const std::vector<std::unique_ptr<HIR::GenericParam>> &generics,
37
+ ReachLevel item_reach)
38
+ {
39
+ if (item_reach == ReachLevel::Unreachable)
40
+ return ;
41
+
42
+ for (auto &generic : generics)
43
+ {
44
+ if (generic->get_kind () == HIR::GenericParam::TYPE)
45
+ {
46
+ TyTy::BaseType *generic_ty = nullptr ;
47
+ rust_assert (
48
+ ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
49
+ &generic_ty));
50
+
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)
54
+ {
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
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+
34
66
void
35
67
ReachabilityVisitor::visit (HIR::Module &mod)
36
68
{
@@ -75,41 +107,10 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item)
75
107
auto old_level = current_level;
76
108
current_level = struct_reach;
77
109
110
+ visit_generic_predicates (struct_item.get_generic_params (), struct_reach);
111
+
78
112
if (struct_reach != ReachLevel::Unreachable)
79
113
{
80
- for (auto &field : struct_item.get_fields ())
81
- if (field.get_visibility ().is_public ())
82
- ctx.update_reachability (field.get_mappings (), struct_reach);
83
-
84
- for (auto &generic : struct_item.get_generic_params ())
85
- {
86
- switch (generic->get_kind ())
87
- {
88
- case HIR::GenericParam::LIFETIME:
89
- break ;
90
- case HIR::GenericParam::TYPE:
91
- TyTy::BaseType *generic_ty = nullptr ;
92
- rust_assert (
93
- ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
94
- &generic_ty));
95
-
96
- if (generic_ty->get_kind () == TyTy::PARAM)
97
- {
98
- auto generic_param
99
- = static_cast <TyTy::ParamType *> (generic_ty);
100
- for (const auto &bound :
101
- generic_param->get_specified_bounds ())
102
- {
103
- const auto trait = bound.get ()->get_hir_trait_ref ();
104
- ctx.update_reachability (trait->get_mappings (),
105
- struct_reach);
106
- }
107
- }
108
-
109
- break ;
110
- }
111
- }
112
-
113
114
for (auto &field : struct_item.get_fields ())
114
115
if (field.get_visibility ().is_public ())
115
116
ctx.update_reachability (field.get_field_type ()->get_mappings (),
0 commit comments