-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Description
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 }
Metadata
Metadata
Assignees
Labels
No labels