Skip to content

Commit ffe336d

Browse files
committed
Fixes #53119.
1 parent 39e9516 commit ffe336d

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -661,28 +661,33 @@ impl<'tcx> RegionInferenceContext<'tcx> {
661661
test: _,
662662
} = type_test;
663663

664+
664665
let generic_ty = generic_kind.to_ty(tcx);
665666
let subject = match self.try_promote_type_test_subject(infcx, generic_ty) {
666667
Some(s) => s,
667668
None => return false,
668669
};
669670

670-
// Find some bounding subject-region R+ that is a super-region
671-
// of the existing subject-region R. This should be a non-local, universal
672-
// region, which ensures it can be encoded in a `ClosureOutlivesRequirement`.
673-
let lower_bound_plus = self.non_local_universal_upper_bound(*lower_bound);
674-
assert!(self.universal_regions.is_universal_region(lower_bound_plus));
675-
assert!(
676-
!self
671+
// For each region outlived by lower_bound find a non-local,
672+
// universal region (it may be the same region) and add it to
673+
// `ClosureOutlivesRequirement`.
674+
let r_scc = self.constraint_sccs.scc(*lower_bound);
675+
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
676+
let non_local_ub = self.universal_region_relations.non_local_upper_bound(ur);
677+
678+
assert!(self.universal_regions.is_universal_region(non_local_ub));
679+
assert!(
680+
!self
677681
.universal_regions
678-
.is_local_free_region(lower_bound_plus)
679-
);
682+
.is_local_free_region(non_local_ub)
683+
);
680684

681-
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
682-
subject,
683-
outlived_free_region: lower_bound_plus,
684-
blame_span: locations.span(mir),
685-
});
685+
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
686+
subject,
687+
outlived_free_region: non_local_ub,
688+
blame_span: locations.span(mir),
689+
});
690+
}
686691
true
687692
}
688693

src/test/ui/nll/issue-53119.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
13+
#![feature(nll)]
14+
15+
use std::ops::Deref;
16+
17+
pub struct TypeFieldIterator<'a, T: 'a> {
18+
_t: &'a T,
19+
}
20+
21+
pub struct Type<Id, T> {
22+
_types: Vec<(Id, T)>,
23+
}
24+
25+
impl<'a, Id: 'a, T> Iterator for TypeFieldIterator<'a, T>
26+
where T: Deref<Target = Type<Id, T>> {
27+
type Item = &'a (Id, T);
28+
29+
fn next(&mut self) -> Option<&'a (Id, T)> {
30+
|| self.next();
31+
None
32+
}
33+
}
34+
35+
fn main() { }

0 commit comments

Comments
 (0)