Skip to content

Commit f676547

Browse files
committed
Fix intersection of two region params in infer, cc #2962
1 parent 978ca03 commit f676547

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/rustc/middle/typeck/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,8 @@ impl of combine for glb {
23712371
}
23722372
}
23732373

2374-
(ty::re_scope(a_id), ty::re_scope(b_id)) {
2374+
(ty::re_scope(a_id), ty::re_scope(b_id)) |
2375+
(ty::re_free(a_id, _), ty::re_free(b_id, _)) {
23752376
// We want to generate a region that is contained by both of
23762377
// these: so, if one of these scopes is a subscope of the
23772378
// other, return it. Otherwise fail.
@@ -2385,7 +2386,6 @@ impl of combine for glb {
23852386

23862387
// For these types, we cannot define any additional
23872388
// relationship:
2388-
(ty::re_free(_, _), ty::re_free(_, _)) |
23892389
(ty::re_bound(_), ty::re_bound(_)) |
23902390
(ty::re_bound(_), ty::re_free(_, _)) |
23912391
(ty::re_bound(_), ty::re_scope(_)) |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn select(x: &int, y: &int) -> &int { x }
2+
3+
fn with<T>(f: fn(x: &int) -> T) -> T {
4+
f(&20)
5+
}
6+
7+
fn manip(x: &a/int) -> int {
8+
let z = do with |y| { select(x, y) };
9+
//~^ ERROR reference is not valid outside of its lifetime
10+
*z
11+
}
12+
13+
fn main() {
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn takes_two(x: &int, y: &int) -> int { *x + *y }
2+
3+
fn with<T>(f: fn(x: &int) -> T) -> T {
4+
f(&20)
5+
}
6+
7+
fn has_one(x: &a/int) -> int {
8+
do with |y| { takes_two(x, y) }
9+
}
10+
11+
fn main() {
12+
assert has_one(&2) == 22;
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn takes_two(x: &int, y: &int) -> int { *x + *y }
2+
3+
fn has_two(x: &a/int, y: &b/int) -> int {
4+
takes_two(x, y)
5+
}
6+
7+
fn main() {
8+
assert has_two(&20, &2) == 22;
9+
}

0 commit comments

Comments
 (0)