Skip to content

Regression in new inference scheme #16870

@bkoropoff

Description

@bkoropoff

I was having a great deal of difficulty getting my library (https://github.com/bkoropoff/rust-jlens) to build on newer versions of rustc, even after updating it to deal with generalized lifetime bounds. Reverting to a rustc prior to the new inference scheme resolved the issue. I came up with the following reduced test case:

struct Chain<'a:'b,'b> {
    x: &'a int,
    y: Option<&'b Chain<'a,'b>>
}

impl<'a,'b> Chain<'a,'b> {
    fn leaf(x: &'a int) -> Chain<'a,'b> { Chain { x: x, y: None } }
}

fn callme<'a,'b> (y: Chain<'a,'b>, x: &'a int, f: <'c>|Chain<'a,'c>|) {
    f(Chain { x: x, y: Some(&y) })
}

fn main() {
    let x = 5i;
    let y = Chain::leaf(&x);
    callme(y, &x, |_| {});
}

This seems to build fine prior to the new inference scheme landing and gives the following error after:

test.rs:12:30: 12:31 error: `y` does not live long enough
test.rs:12     f(Chain { x: x, y: Some(&y) })
                                        ^
test.rs:11:71: 13:2 note: reference must be valid for the lifetime 'b as defined on the block at 11:70...
test.rs:11 fn callme<'a,'b> (y: Chain<'a,'b>, x: &'a int, f: <'c>|Chain<'a,'c>|) {
test.rs:12     f(Chain { x: x, y: Some(&y) })
test.rs:13 }
test.rs:11:71: 13:2 note: ...but borrowed value is only valid for the block at 11:70
test.rs:11 fn callme<'a,'b> (y: Chain<'a,'b>, x: &'a int, f: <'c>|Chain<'a,'c>|) {
test.rs:12     f(Chain { x: x, y: Some(&y) })
test.rs:13 }

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions