-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected "life is too short" error #16339
Comments
Adding @nikomatsakis, @zwarich, @pnkfelix, as per @cmr request. |
Minimal example: fn small(x: &mut ()) -> &mut () {
(|| &mut *x)()
}
fn main() { } (At the very least, expanding the macro will make handling this issue nicer.) |
I find it helpful to also make the lifetimes more explicit, where we can: fn small<'a>(x: &'a mut ()) -> &'a mut () {
let f = || &mut *x;
f()
}
fn main() { } since now at least one of the error messages are written in terms of |
I believe this error message is correct. The problem is that the closure has a lifetime tied to the stack frame where it was created -- it is not allowed to create mutable aliases of For the time being, you can work around this by using mutable options to move the value into the closure:
|
For extra information: this situation is specific to mutable references, because we must guarantee that the mutable reference is the only reference with access to its referent. This means that they must be moved from place to place -- or reborrowed, but if they are reborrowed, it must be for a shorter duration than they were originally intended (more or less). What happens here is that when the closure is desugared, the reference to |
Replace SourceRootCrates hashset output with slice for deterministic order We only iterate over the result, and its pretty small in general so no point for the `HashSet` (additionally this way we get a more defined iteration order).
The repro code:
Rust complains:
The text was updated successfully, but these errors were encountered: