diff options
| -rw-r--r-- | src/rustc/middle/typeck/infer.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-infer-call-3.rs | 14 | ||||
| -rw-r--r-- | src/test/run-pass/regions-infer-call-2.rs | 13 | ||||
| -rw-r--r-- | src/test/run-pass/regions-infer-call.rs | 9 |
4 files changed, 38 insertions, 2 deletions
diff --git a/src/rustc/middle/typeck/infer.rs b/src/rustc/middle/typeck/infer.rs index 2bc01839563..79df5975307 100644 --- a/src/rustc/middle/typeck/infer.rs +++ b/src/rustc/middle/typeck/infer.rs @@ -2371,7 +2371,8 @@ impl of combine for glb { } } - (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 @@ impl of combine for glb { // 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(_)) | diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs new file mode 100644 index 00000000000..4a2be378d42 --- /dev/null +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -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() { +} \ No newline at end of file diff --git a/src/test/run-pass/regions-infer-call-2.rs b/src/test/run-pass/regions-infer-call-2.rs new file mode 100644 index 00000000000..9e4000f0599 --- /dev/null +++ b/src/test/run-pass/regions-infer-call-2.rs @@ -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; +} \ No newline at end of file diff --git a/src/test/run-pass/regions-infer-call.rs b/src/test/run-pass/regions-infer-call.rs new file mode 100644 index 00000000000..f3f14d0250c --- /dev/null +++ b/src/test/run-pass/regions-infer-call.rs @@ -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; +} \ No newline at end of file |
