I have run into a bit of an annoying lifetime issue last night that I still haven’t really been able to figure out. Basically, I’m trying to diagnose the following error message:
error: `content` does not live long enough
--> src/parse/repeat.rs:144:5
|
131 | let _ = { drop(::apply(&content, ::Options::default(), parser)) };
| ------- borrow occurs here
...
144 | }
| ^ `content` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to previous error
My issue here stems from the fact that I don’t know what keeps the borrow alive, and why. It is an error that only comes up when certain conditions are met, making it hard to reduce.
I have been wondering: rustc
already has that information, since it used it to decide that the above is not safe. Would it be possible to add that information to the error message? I was thinking something along the lines of:
note: Value 'content' is still borrowed by [the return value, the argument X, etc] type SomeType<'somelifetime> due to [constraint X on parameter Y, etc]"