You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0499]: cannot borrow `*ctx` as mutable more than once at a time
--> src/lib.rs:12:28
|
8 | ctx: &'a mut Ctx<'a>,
| --- lifetime `'1` appears in the type of `ctx`
...
12 | await!(read_single(ctx))?;
| ------------^^^-
| | |
| | mutable borrow starts here in previous iteration of loop
| argument requires that `*ctx` is borrowed for `'1`
That seems very confusing (or wrong), given that the function doesn't return anything with a lifetime. It works without the loop. An additional scope doesn't help.
I tried to work around it by introducing another lifetime for ctx, but doesn't work, since async/await doesn't support it yet.
This signature is too strong -- it forces the compiler to assume that when you call read_single, it may continue using *ctx for the remainder of 'a. (This is because the 'a appears under the mut qualifier, making it invariant.) The signature that we need is really:
The following code (playground) produces a compiler error, even if there doesn't seem to be an obvious lifetime issue:
The error message is:
That seems very confusing (or wrong), given that the function doesn't return anything with a lifetime. It works without the loop. An additional scope doesn't help.
I tried to work around it by introducing another lifetime for
ctx
, but doesn't work, since async/await doesn't support it yet.I got another hint to write an explicit
impl Future
signature, which allows compiling this simplified example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f006c176dea64435e984cb46bcfef56dBut I feel the more basic variant should work too.
The text was updated successfully, but these errors were encountered: