|
1 | 1 | use std::ops::ControlFlow;
|
2 | 2 |
|
3 |
| -use rustc_data_structures::fx::FxIndexSet; |
4 |
| -use rustc_type_ir::fold::TypeFoldable; |
5 | 3 | pub use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
6 | 4 |
|
7 | 5 | use crate::ty::{self, Binder, Ty, TyCtxt, TypeFlags};
|
@@ -102,114 +100,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
102 | 100 |
|
103 | 101 | value.visit_with(&mut RegionVisitor { outer_index: ty::INNERMOST, callback }).is_break()
|
104 | 102 | }
|
105 |
| - |
106 |
| - /// Returns a set of all late-bound regions that are constrained |
107 |
| - /// by `value`, meaning that if we instantiate those LBR with |
108 |
| - /// variables and equate `value` with something else, those |
109 |
| - /// variables will also be equated. |
110 |
| - pub fn collect_constrained_late_bound_regions<T>( |
111 |
| - self, |
112 |
| - value: Binder<'tcx, T>, |
113 |
| - ) -> FxIndexSet<ty::BoundRegionKind> |
114 |
| - where |
115 |
| - T: TypeFoldable<TyCtxt<'tcx>>, |
116 |
| - { |
117 |
| - self.collect_late_bound_regions(value, true) |
118 |
| - } |
119 |
| - |
120 |
| - /// Returns a set of all late-bound regions that appear in `value` anywhere. |
121 |
| - pub fn collect_referenced_late_bound_regions<T>( |
122 |
| - self, |
123 |
| - value: Binder<'tcx, T>, |
124 |
| - ) -> FxIndexSet<ty::BoundRegionKind> |
125 |
| - where |
126 |
| - T: TypeFoldable<TyCtxt<'tcx>>, |
127 |
| - { |
128 |
| - self.collect_late_bound_regions(value, false) |
129 |
| - } |
130 |
| - |
131 |
| - fn collect_late_bound_regions<T>( |
132 |
| - self, |
133 |
| - value: Binder<'tcx, T>, |
134 |
| - just_constrained: bool, |
135 |
| - ) -> FxIndexSet<ty::BoundRegionKind> |
136 |
| - where |
137 |
| - T: TypeFoldable<TyCtxt<'tcx>>, |
138 |
| - { |
139 |
| - let mut collector = LateBoundRegionsCollector::new(just_constrained); |
140 |
| - let value = value.skip_binder(); |
141 |
| - let value = if just_constrained { self.expand_weak_alias_tys(value) } else { value }; |
142 |
| - value.visit_with(&mut collector); |
143 |
| - collector.regions |
144 |
| - } |
145 |
| -} |
146 |
| - |
147 |
| -/// Collects all the late-bound regions at the innermost binding level |
148 |
| -/// into a hash set. |
149 |
| -struct LateBoundRegionsCollector { |
150 |
| - current_index: ty::DebruijnIndex, |
151 |
| - regions: FxIndexSet<ty::BoundRegionKind>, |
152 |
| - |
153 |
| - /// `true` if we only want regions that are known to be |
154 |
| - /// "constrained" when you equate this type with another type. In |
155 |
| - /// particular, if you have e.g., `&'a u32` and `&'b u32`, equating |
156 |
| - /// them constraints `'a == 'b`. But if you have `<&'a u32 as |
157 |
| - /// Trait>::Foo` and `<&'b u32 as Trait>::Foo`, normalizing those |
158 |
| - /// types may mean that `'a` and `'b` don't appear in the results, |
159 |
| - /// so they are not considered *constrained*. |
160 |
| - just_constrained: bool, |
161 |
| -} |
162 |
| - |
163 |
| -impl LateBoundRegionsCollector { |
164 |
| - fn new(just_constrained: bool) -> Self { |
165 |
| - Self { current_index: ty::INNERMOST, regions: Default::default(), just_constrained } |
166 |
| - } |
167 |
| -} |
168 |
| - |
169 |
| -impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector { |
170 |
| - fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) { |
171 |
| - self.current_index.shift_in(1); |
172 |
| - t.super_visit_with(self); |
173 |
| - self.current_index.shift_out(1); |
174 |
| - } |
175 |
| - |
176 |
| - fn visit_ty(&mut self, t: Ty<'tcx>) { |
177 |
| - if self.just_constrained { |
178 |
| - match t.kind() { |
179 |
| - // If we are only looking for "constrained" regions, we have to ignore the |
180 |
| - // inputs to a projection as they may not appear in the normalized form. |
181 |
| - ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) => { |
182 |
| - return; |
183 |
| - } |
184 |
| - // All weak alias types should've been expanded beforehand. |
185 |
| - ty::Alias(ty::Weak, _) => bug!("unexpected weak alias type"), |
186 |
| - _ => {} |
187 |
| - } |
188 |
| - } |
189 |
| - |
190 |
| - t.super_visit_with(self) |
191 |
| - } |
192 |
| - |
193 |
| - fn visit_const(&mut self, c: ty::Const<'tcx>) { |
194 |
| - // if we are only looking for "constrained" region, we have to |
195 |
| - // ignore the inputs of an unevaluated const, as they may not appear |
196 |
| - // in the normalized form |
197 |
| - if self.just_constrained { |
198 |
| - if let ty::ConstKind::Unevaluated(..) = c.kind() { |
199 |
| - return; |
200 |
| - } |
201 |
| - } |
202 |
| - |
203 |
| - c.super_visit_with(self) |
204 |
| - } |
205 |
| - |
206 |
| - fn visit_region(&mut self, r: ty::Region<'tcx>) { |
207 |
| - if let ty::ReBound(debruijn, br) = *r { |
208 |
| - if debruijn == self.current_index { |
209 |
| - self.regions.insert(br.kind); |
210 |
| - } |
211 |
| - } |
212 |
| - } |
213 | 103 | }
|
214 | 104 |
|
215 | 105 | /// Finds the max universe present
|
|
0 commit comments