mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Fix intersection of two region params in infer, cc #2962
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user