-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
ICE when using async with references with named lifetimes as arguments #53174
Comments
It would appear one can workaround this by using async blocks manually:
I still need to test this does what I expect. |
@jkozlowski pub fn hello_world<'a>(hello: &'a String, world: &'a String) -> impl Future<Output=Result<(), Error>> + 'a {
(async move || {
may_fail(hello, world)?;
Ok(())
})()
} |
@panicbit why do you need the immediately invoked closure there, it works fine with an async block pub fn hello_world<'a>(hello: &'a String, world: &'a String) -> impl Future<Output=Result<(), Error>> + 'a {
async move {
may_fail(hello, world)?;
Ok(())
}
} |
@Nemo157 Yeah, just noticed. I think I also had some other issue / ICE, but I don't remember exactly what it was. Gonna have to check it again. Also, I don't think I knew that |
I didn't quite understand why I needed the move. I am trying to fix the original ICE, I think I got some time today tomorrow, hopefully, will make some progress. But compiler newbie, so might not work out. |
@jkozlowski You need to move to avoid the closure borrowing the references locally. It's the same situation as with this non-async example @Nemo157 I just removed all immeditaly invoked functions from eval 😉 |
I am playing around with similar types of borrowing patterns, namely using StreamObj to carry a stream around inside of a struct. I can't seem to use the posted work-arounds: I am taking this working code and I'm refactoring it. Starts as:
this works, compiles and runs. Then I try my hand at refactoring to move the stream out of the same scope as the await code pulling out values. Now I can get the same ICE as this ticket:
ICE:
full backtrace: https://gist.github.com/xrl/4057ad3e0b345807280741f646fdf010 Then I try some of your posted workarounds and they don't do the trick, here's my best try:
but this fails to compile due to an ownership issue I can't figure out:
|
@xrl your final borrow error is because Fahrenheit requires futures run on it to have a |
Allow named lifetimes in async functions. - Fixes rust-lang#53174 Code by @eddyb; @cramertj suggested I lift it off another change so we can fix rust-lang#53174. r? @cramertj
Status
@cramertj suggested this is because when we lower the async function, we add
impl Future<Output=something> + 'a
, but'a
is lowered and parented as a child ofreturn_impl_trait_id
(the argument tolower_async_fn_ret_ty
), whereas it should be parented as something outside of the impl trait context (as that is how such an expression would be parented, if it actually existing in the AST).Description
I have a bit of code where I'd like to use a reference with a lifetime in an "async" function, which panics the compiler.
I tried this code: https://play.rust-lang.org/?gist=dbca2de61c4a02f0ac4a6cf0023ce7b6&version=nightly&mode=debug&edition=2018
I expected to see this happen: My understanding was that async functions are allowed to take references as parameters. @Nemo157 helped to debug this a little bit and there is a suspicion that named lifetimes are somehow not properly propagated. I stumbled into this because I wanted to have 2 args with references, but if the lifetimes are elided the compiler asks for them to be added. Adding them ICEs the compiler.
Instead, this happened: I got a compiler panic.
Meta
Backtrace:
The text was updated successfully, but these errors were encountered: