Skip to content

Commit 2c84bdd

Browse files
committed
add tests
1 parent 88999e8 commit 2c84bdd

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/ui/nll/member-constraints/nested-impl-trait-pass.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ impl<T> Cap<'_> for T {}
88
// Assuming the hidden type is `[&'?15 u8; 1]`, we have two distinct member constraints:
99
// - '?15 member ['static, 'a, 'b] // from outer impl-trait
1010
// - '?15 member ['static, 'a] // from inner impl-trait
11-
// To satisfy both we can only choose 'a.
11+
// To satisfy both we can only choose 'a. Concretely, the applying the first member constraint
12+
// requires ?15 to outlive at least 'b while the second requires ?15 to outlive 'a. As
13+
// 'a outlives 'b we end up with 'a as the final member region.
1214
fn pass_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a>> + Cap<'b>
1315
where
1416
's: 'a,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ check-pass
2+
3+
// We've got `'0 member ['a, 'b, 'static]` and `'1 member ['a, 'b, 'static]`.
4+
//
5+
// As '0 gets outlived by 'a - its "upper bound" - the only applicable choice
6+
// region is 'a.
7+
//
8+
// '1 has to outlive 'b so the only applicabel choice regions are 'b and 'static.
9+
// Considering this member constraint by itself would choose 'b as it is the
10+
// smaller of the two regions.
11+
//
12+
// However, this is only the case when ignoring the member constraint on '0.
13+
// After applying this constraint and requiring '0 to outlive 'a. As '1 outlives
14+
// '0, the region 'b is no longer an applicable choice region for '1 as 'b does
15+
// does not outlive 'a. We would therefore choose 'static.
16+
//
17+
// This means applying member constraints is order dependent. We handle this by
18+
// first applying member constraints for regions 'x and then consider the resulting
19+
// constraints when applying member constraints for regions 'y with 'y: 'x.
20+
fn with_constraints<'r0, 'r1, 'a, 'b>() -> *mut (&'r0 (), &'r1 ())
21+
where
22+
'r1: 'r0,
23+
'a: 'r0,
24+
'r1: 'b,
25+
{
26+
loop {}
27+
}
28+
fn foo<'a, 'b>() -> impl Sized + use<'a, 'b> {
29+
with_constraints::<'_, '_, 'a, 'b>()
30+
}
31+
fn main() {}

0 commit comments

Comments
 (0)