Fix intersection of two region params in infer, cc #2962

This commit is contained in:
Niko Matsakis
2012-07-19 10:10:22 -07:00
parent 978ca03cb2
commit f676547c97
4 changed files with 38 additions and 2 deletions
+2 -2
View File
@@ -2371,7 +2371,8 @@ fn regions(a: ty::region, b: ty::region) -> cres<ty::region> {
}
}
(ty::re_scope(a_id), ty::re_scope(b_id)) {
(ty::re_scope(a_id), ty::re_scope(b_id)) |
(ty::re_free(a_id, _), ty::re_free(b_id, _)) {
// We want to generate a region that is contained by both of
// these: so, if one of these scopes is a subscope of the
// other, return it. Otherwise fail.
@@ -2385,7 +2386,6 @@ fn regions(a: ty::region, b: ty::region) -> cres<ty::region> {
// For these types, we cannot define any additional
// relationship:
(ty::re_free(_, _), ty::re_free(_, _)) |
(ty::re_bound(_), ty::re_bound(_)) |
(ty::re_bound(_), ty::re_free(_, _)) |
(ty::re_bound(_), ty::re_scope(_)) |
@@ -0,0 +1,14 @@
fn select(x: &int, y: &int) -> &int { x }
fn with<T>(f: fn(x: &int) -> T) -> T {
f(&20)
}
fn manip(x: &a/int) -> int {
let z = do with |y| { select(x, y) };
//~^ ERROR reference is not valid outside of its lifetime
*z
}
fn main() {
}
+13
View File
@@ -0,0 +1,13 @@
fn takes_two(x: &int, y: &int) -> int { *x + *y }
fn with<T>(f: fn(x: &int) -> T) -> T {
f(&20)
}
fn has_one(x: &a/int) -> int {
do with |y| { takes_two(x, y) }
}
fn main() {
assert has_one(&2) == 22;
}
+9
View File
@@ -0,0 +1,9 @@
fn takes_two(x: &int, y: &int) -> int { *x + *y }
fn has_two(x: &a/int, y: &b/int) -> int {
takes_two(x, y)
}
fn main() {
assert has_two(&20, &2) == 22;
}