|
5 | 5 |
|
6 | 6 | use hir::def_id::{DefId, LocalDefId};
|
7 | 7 | use rustc_hir as hir;
|
8 |
| -use rustc_hir::itemlikevisit::ItemLikeVisitor; |
| 8 | +use rustc_hir::def::DefKind; |
9 | 9 | use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
10 | 10 | use rustc_middle::ty::{self, Ty, TyCtxt};
|
11 | 11 |
|
@@ -62,61 +62,71 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
|
62 | 62 | constraints: Vec::new(),
|
63 | 63 | };
|
64 | 64 |
|
65 |
| - tcx.hir().visit_all_item_likes(&mut constraint_cx); |
| 65 | + let crate_items = tcx.hir_crate_items(()); |
| 66 | + |
| 67 | + for id in crate_items.items() { |
| 68 | + constraint_cx.check_item(id); |
| 69 | + } |
| 70 | + |
| 71 | + for id in crate_items.trait_items() { |
| 72 | + if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { |
| 73 | + constraint_cx.check_node_helper(id.hir_id()); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + for id in crate_items.impl_items() { |
| 78 | + if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { |
| 79 | + constraint_cx.check_node_helper(id.hir_id()); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + for id in crate_items.foreign_items() { |
| 84 | + if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { |
| 85 | + constraint_cx.check_node_helper(id.hir_id()); |
| 86 | + } |
| 87 | + } |
66 | 88 |
|
67 | 89 | constraint_cx
|
68 | 90 | }
|
69 | 91 |
|
70 |
| -impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { |
71 |
| - fn visit_item(&mut self, item: &hir::Item<'_>) { |
72 |
| - match item.kind { |
73 |
| - hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { |
74 |
| - self.visit_node_helper(item.hir_id()); |
75 |
| - |
76 |
| - if let hir::VariantData::Tuple(..) = *struct_def { |
77 |
| - self.visit_node_helper(struct_def.ctor_hir_id().unwrap()); |
| 92 | +impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { |
| 93 | + fn check_item(&mut self, id: hir::ItemId) { |
| 94 | + let def_kind = self.tcx().hir().def_kind(id.def_id); |
| 95 | + match def_kind { |
| 96 | + DefKind::Struct | DefKind::Union => { |
| 97 | + let item = self.tcx().hir().item(id); |
| 98 | + |
| 99 | + if let hir::ItemKind::Struct(ref struct_def, _) |
| 100 | + | hir::ItemKind::Union(ref struct_def, _) = item.kind |
| 101 | + { |
| 102 | + self.check_node_helper(item.hir_id()); |
| 103 | + |
| 104 | + if let hir::VariantData::Tuple(..) = *struct_def { |
| 105 | + self.check_node_helper(struct_def.ctor_hir_id().unwrap()); |
| 106 | + } |
78 | 107 | }
|
79 | 108 | }
|
| 109 | + DefKind::Enum => { |
| 110 | + let item = self.tcx().hir().item(id); |
80 | 111 |
|
81 |
| - hir::ItemKind::Enum(ref enum_def, _) => { |
82 |
| - self.visit_node_helper(item.hir_id()); |
| 112 | + if let hir::ItemKind::Enum(ref enum_def, _) = item.kind { |
| 113 | + self.check_node_helper(item.hir_id()); |
83 | 114 |
|
84 |
| - for variant in enum_def.variants { |
85 |
| - if let hir::VariantData::Tuple(..) = variant.data { |
86 |
| - self.visit_node_helper(variant.data.ctor_hir_id().unwrap()); |
| 115 | + for variant in enum_def.variants { |
| 116 | + if let hir::VariantData::Tuple(..) = variant.data { |
| 117 | + self.check_node_helper(variant.data.ctor_hir_id().unwrap()); |
| 118 | + } |
87 | 119 | }
|
88 | 120 | }
|
89 | 121 | }
|
90 |
| - |
91 |
| - hir::ItemKind::Fn(..) => { |
92 |
| - self.visit_node_helper(item.hir_id()); |
| 122 | + DefKind::Fn => { |
| 123 | + self.check_node_helper(id.hir_id()); |
93 | 124 | }
|
94 |
| - |
95 | 125 | _ => {}
|
96 | 126 | }
|
97 | 127 | }
|
98 | 128 |
|
99 |
| - fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { |
100 |
| - if let hir::TraitItemKind::Fn(..) = trait_item.kind { |
101 |
| - self.visit_node_helper(trait_item.hir_id()); |
102 |
| - } |
103 |
| - } |
104 |
| - |
105 |
| - fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { |
106 |
| - if let hir::ImplItemKind::Fn(..) = impl_item.kind { |
107 |
| - self.visit_node_helper(impl_item.hir_id()); |
108 |
| - } |
109 |
| - } |
110 |
| - |
111 |
| - fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { |
112 |
| - if let hir::ForeignItemKind::Fn(..) = foreign_item.kind { |
113 |
| - self.visit_node_helper(foreign_item.hir_id()); |
114 |
| - } |
115 |
| - } |
116 |
| -} |
117 |
| - |
118 |
| -impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { |
119 |
| - fn visit_node_helper(&mut self, id: hir::HirId) { |
| 129 | + fn check_node_helper(&mut self, id: hir::HirId) { |
120 | 130 | let tcx = self.terms_cx.tcx;
|
121 | 131 | let def_id = tcx.hir().local_def_id(id);
|
122 | 132 | self.build_constraints_for_item(def_id);
|
|
0 commit comments