I’m having trouble with lifetimes again…
Over at https://github.com/neon64/opal/blob/master/opal_driver_gl/src/device.rs I have a struct called
Device<'r> that has a lifetime parameter. I think that
'r should last for the same length as the struct itself, so I can call a method that takes
&'r self, however the compiler keeps saying that I needs to last for the ‘block suffix’ of whatever the line of code previous to when I call
Device::from_gl() (that’s the function that returns a new
In an extreme example, I managed to comment out all the dependencies of
Device::from_gl() so that it took zero arguments, and
rustc still complained that the references needs to be valid for the block suffix following some completely unrelated piece of code.
src/main.rs:229:1: 229:7 error: `device` does not live long enough src/main.rs:229 device.test(); ^~~~~~ src/main.rs:207:9: 381:2 note: reference must be valid for the block suffix following statement 3 at 207:8... src/main.rs:207 })); src/main.rs:208 src/main.rs:209 /*let limits = Limits::from_context(&gl); src/main.rs:210 let global_state = GlobalState::from_context(&limits, &gl); src/main.rs:211 let default_state = DefaultState::from_context(&limits, &gl);*/ // these aren't even used anymore src/main.rs:212 ... src/main.rs:213:38: 381:2 note: ...but borrowed value is only valid for the block suffix following statement 4 at 213:37 src/main.rs:213 let device = GlDevice::from_gl(); // look no dependencies
I’ve tried to make a smaller example of this issue on the Rust playground and it works absolutely fine which is strange.
This time I have given up on trying to produce an isolated example as they never seem to work. Instead I’ve just put my entire repository up on GitHub in the hope that someone might see where I’ve made a mistake.
If anybody could see sense in this issue then that would be fantastic, as I feel that I’m so close and yet so far from actually being able to wrangle lifetimes instead of just being directed by the all-powerful compiler.