Closed
Description
This example fails to compile:
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;
}
but it shouldn't. The problem is that has_two()
tries to intersect a
and b
and fails. What ought to happen however is that the GLB of two lifetime parameters ought to be the same as the method body itself.
There is a workaround, you can rewrite has_two()
to be:
fn has_two(x: &a/int, y: &b/int) -> int {
let x1: &blk/&int = x;
let x1: &blk/&int = x;
takes_two(x, y)
}
this basically specifies the GLB. Here blk
is a special region name for "the region of the innermost enclosing block".