Skip to content

regionck fails to link lifetime of ref bindings in certain situations #16994

Closed
@nikomatsakis

Description

@nikomatsakis

The recent attempts to improve hashmap seem to have exposed a bug in regionck where it fails to link the lifetimes of ref bindings in some situations.

A mostly minimized test case is here:

fn cb<'a,T>(x: |(&'a uint, &'a (Vec<&'static uint>, bool))| -> T) -> T {fail!()}

fn main() {
    cb(|(k, &(ref v, b))| (*k, v.clone(), b));
}

This test fails to compile but (I believe) should succeed. The problem is that the lifetime of the ref v binding inside the callback from map is not "linked" (in regionck terminology) to the lifetime 'a, and hence region inference infers a lifetime for v that is too small. It was not immediately obvious what the best way is to fix this -- the code around handling ref bindings seems a bit ... off in regionck, so I need to think about it some.

Perturbing the code in various ways can workaround the issue, which is bad for making minimized test cases but good for landing the hasmap patch in the meantime!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions