|
2 | 2 |
|
3 | 3 | use crate::infer::region_constraints::Constraint;
|
4 | 4 | use crate::infer::region_constraints::GenericKind;
|
5 |
| -use crate::infer::region_constraints::MemberConstraint; |
6 | 5 | use crate::infer::region_constraints::RegionConstraintData;
|
7 | 6 | use crate::infer::region_constraints::VarInfos;
|
8 | 7 | use crate::infer::region_constraints::VerifyBound;
|
@@ -150,12 +149,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
150 | 149 |
|
151 | 150 | let graph = self.construct_graph();
|
152 | 151 | self.expand_givens(&graph);
|
153 |
| - loop { |
154 |
| - self.expansion(&mut var_data); |
155 |
| - if !self.enforce_member_constraints(&graph, &mut var_data) { |
156 |
| - break; |
157 |
| - } |
158 |
| - } |
| 152 | + self.expansion(&mut var_data); |
159 | 153 | self.collect_errors(&mut var_data, errors);
|
160 | 154 | self.collect_var_errors(&var_data, &graph, errors);
|
161 | 155 | var_data
|
@@ -233,133 +227,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
233 | 227 | }
|
234 | 228 | }
|
235 | 229 |
|
236 |
| - /// Enforce all member constraints and return true if anything |
237 |
| - /// changed. See `enforce_member_constraint` for more details. |
238 |
| - fn enforce_member_constraints( |
239 |
| - &self, |
240 |
| - graph: &RegionGraph<'tcx>, |
241 |
| - var_values: &mut LexicalRegionResolutions<'tcx>, |
242 |
| - ) -> bool { |
243 |
| - // Note: we don't use the `any` combinator because we don't |
244 |
| - // want to stop at the first constraint that makes a change. |
245 |
| - let mut any_changed = false; |
246 |
| - for member_constraint in &self.data.member_constraints { |
247 |
| - any_changed |= self.enforce_member_constraint(graph, member_constraint, var_values); |
248 |
| - } |
249 |
| - any_changed |
250 |
| - } |
251 |
| - |
252 |
| - /// Enforce a constraint like |
253 |
| - /// |
254 |
| - /// ``` |
255 |
| - /// 'r member of ['c...] |
256 |
| - /// ``` |
257 |
| - /// |
258 |
| - /// We look for all choice regions from the list `'c...` that: |
259 |
| - /// |
260 |
| - /// (a) are greater than the current value of `'r` (which is a lower bound) |
261 |
| - /// |
262 |
| - /// and |
263 |
| - /// |
264 |
| - /// (b) are compatible with the upper bounds of `'r` that we can |
265 |
| - /// find by traversing the graph. |
266 |
| - /// |
267 |
| - /// From that list, we look for a *minimal* option `'c_min`. If we |
268 |
| - /// find one, then we can enforce that `'r: 'c_min`. |
269 |
| - #[instrument(level = "debug", skip(self, graph, member_constraint, var_values))] |
270 |
| - fn enforce_member_constraint( |
271 |
| - &self, |
272 |
| - graph: &RegionGraph<'tcx>, |
273 |
| - member_constraint: &MemberConstraint<'tcx>, |
274 |
| - var_values: &mut LexicalRegionResolutions<'tcx>, |
275 |
| - ) -> bool { |
276 |
| - debug!("member_constraint={:#?}", member_constraint); |
277 |
| - |
278 |
| - // The constraint is some inference variable (`vid`) which |
279 |
| - // must be equal to one of the options. |
280 |
| - let member_vid = match member_constraint.member_region { |
281 |
| - ty::ReVar(vid) => *vid, |
282 |
| - _ => return false, |
283 |
| - }; |
284 |
| - |
285 |
| - // The current value of `vid` is a lower bound LB -- i.e., we |
286 |
| - // know that `LB <= vid` must be true. |
287 |
| - let member_lower_bound: ty::Region<'tcx> = match var_values.value(member_vid) { |
288 |
| - VarValue::ErrorValue => return false, |
289 |
| - VarValue::Value(r) => r, |
290 |
| - }; |
291 |
| - |
292 |
| - // Find all the "upper bounds" -- that is, each region `b` such that |
293 |
| - // `r0 <= b` must hold. |
294 |
| - let (member_upper_bounds, ..) = |
295 |
| - self.collect_bounding_regions(graph, member_vid, OUTGOING, None); |
296 |
| - |
297 |
| - // Get an iterator over the *available choice* -- that is, |
298 |
| - // each choice region `c` where `lb <= c` and `c <= ub` for all the |
299 |
| - // upper bounds `ub`. |
300 |
| - debug!("upper_bounds={:#?}", member_upper_bounds); |
301 |
| - let mut options = member_constraint |
302 |
| - .choice_regions |
303 |
| - .iter() |
304 |
| - // If any of the regions are inference vars, resolve them, as far |
305 |
| - // as possible. |
306 |
| - .filter_map(|option| match option { |
307 |
| - ty::ReVar(vid) => match var_values.value(*vid) { |
308 |
| - VarValue::ErrorValue => None, |
309 |
| - VarValue::Value(r) => Some(r), |
310 |
| - }, |
311 |
| - r => Some(r), |
312 |
| - }) |
313 |
| - .filter(|option| { |
314 |
| - self.sub_concrete_regions(member_lower_bound, option) |
315 |
| - && member_upper_bounds |
316 |
| - .iter() |
317 |
| - .all(|upper_bound| self.sub_concrete_regions(option, upper_bound.region)) |
318 |
| - }); |
319 |
| - |
320 |
| - // If there is more than one option, we only make a choice if |
321 |
| - // there is a single *least* choice -- i.e., some available |
322 |
| - // region that is `<=` all the others. |
323 |
| - let mut least_choice: ty::Region<'tcx> = match options.next() { |
324 |
| - Some(&r) => r, |
325 |
| - None => return false, |
326 |
| - }; |
327 |
| - debug!(?least_choice); |
328 |
| - for &option in options { |
329 |
| - debug!(?option); |
330 |
| - if !self.sub_concrete_regions(least_choice, option) { |
331 |
| - if self.sub_concrete_regions(option, least_choice) { |
332 |
| - debug!("new least choice"); |
333 |
| - least_choice = option; |
334 |
| - } else { |
335 |
| - debug!("no least choice"); |
336 |
| - return false; |
337 |
| - } |
338 |
| - } |
339 |
| - } |
340 |
| - |
341 |
| - // (#72087) Different `ty::Regions` can be known to be equal, for |
342 |
| - // example, we know that `'a` and `'static` are equal in a function |
343 |
| - // with a parameter of type `&'static &'a ()`. |
344 |
| - // |
345 |
| - // When we have two equal regions like this `expansion` will use |
346 |
| - // `lub_concrete_regions` to pick a canonical representative. The same |
347 |
| - // choice is needed here so that we don't end up in a cycle of |
348 |
| - // `expansion` changing the region one way and the code here changing |
349 |
| - // it back. |
350 |
| - let lub = self.lub_concrete_regions(least_choice, member_lower_bound); |
351 |
| - debug!( |
352 |
| - "enforce_member_constraint: final least choice = {:?}\nlub = {:?}", |
353 |
| - least_choice, lub |
354 |
| - ); |
355 |
| - if lub != member_lower_bound { |
356 |
| - *var_values.value_mut(member_vid) = VarValue::Value(least_choice); |
357 |
| - true |
358 |
| - } else { |
359 |
| - false |
360 |
| - } |
361 |
| - } |
362 |
| - |
363 | 230 | fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
|
364 | 231 | let mut constraints = IndexVec::from_elem_n(Vec::new(), var_values.values.len());
|
365 | 232 | let mut changes = Vec::new();
|
@@ -632,34 +499,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
632 | 499 | }
|
633 | 500 | }
|
634 | 501 |
|
635 |
| - // Check that all member constraints are satisfied. |
636 |
| - for member_constraint in &self.data.member_constraints { |
637 |
| - let member_region = var_data.normalize(self.tcx(), member_constraint.member_region); |
638 |
| - let choice_regions = member_constraint |
639 |
| - .choice_regions |
640 |
| - .iter() |
641 |
| - .map(|&choice_region| var_data.normalize(self.tcx(), choice_region)); |
642 |
| - let fr = &self.region_rels.free_regions; |
643 |
| - let sub = |a, b| { |
644 |
| - fr.is_free_or_static(a) |
645 |
| - && fr.is_free_or_static(b) |
646 |
| - && fr.sub_free_regions(self.tcx(), a, b) |
647 |
| - }; |
648 |
| - if !choice_regions.clone().any(|choice_region| { |
649 |
| - // This is really checking if the regions are equal. After member constraint |
650 |
| - // resolution, one region must be equal, or a lifetime has been leaked into |
651 |
| - // the hidden type, but does not appear in the corresponding impl trait. |
652 |
| - sub(member_region, choice_region) && sub(choice_region, member_region) |
653 |
| - }) { |
654 |
| - let span = self.tcx().def_span(member_constraint.opaque_type_def_id); |
655 |
| - errors.push(RegionResolutionError::MemberConstraintFailure { |
656 |
| - span, |
657 |
| - hidden_ty: member_constraint.hidden_ty, |
658 |
| - member_region, |
659 |
| - }); |
660 |
| - } |
661 |
| - } |
662 |
| - |
663 | 502 | for verify in &self.data.verifys {
|
664 | 503 | debug!("collect_errors: verify={:?}", verify);
|
665 | 504 | let sub = var_data.normalize(self.tcx(), verify.region);
|
|
0 commit comments