Skip to content

inference for regions fails to find GLB for two region parameters #2962

Closed
@nikomatsakis

Description

@nikomatsakis

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".

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions