-
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
async fn with elided lifetime causes rustc panic #62517
Comments
This situation also reproduces: async fn foo<'a>(x: &'a str) -> impl Stream<Item = Box<Any>> {} |
I wasn't able to reproduce this on master. @hackerer1c can you check your original example with the latest nightly to see if it works properly? |
@cramertj it seems to fail on the playground:
|
Oh, literally with that code and using futures 0.1 |
Minimized: #![feature(async_await)]
trait FirstTrait {}
trait SecondTrait {
type Item;
}
async fn foo(x: &str) -> impl SecondTrait<Item = dyn FirstTrait> {} |
Reduced further: #![feature(async_await)]
trait Object {}
trait Alpha<Param> {}
async fn foo<'a>(_: &'a ()) -> impl Alpha<dyn Object> {} |
I tried researching this a bit, with a locally built rustc:
For case 2: It checks the opaque type, and then rechecks the return value, which needs to the the opaque type again:
For case 3: It reports loops on this debug logging:
|
I've been digging into this. I don't quite know what the problem is yet but I see the "clues", so to speak, so I thought I'd jot down some notes while I wait for a build. I am working with @Aaron1011's minimization. First off, the core of the problem is the When lowering the |
OK I'm starting to see what's going wrong. This is interacting with a bug in the handling of impl trait. It's something like this: First off, in HIR lowering, we see the Somehow, when this is mixed with async fn, we wind up creating a late-bound lifetime. I'm not yet 100% sure how that comes to be. I think the proper fix, well, the proper fix is to remove the But I think that for the time being what should be happening is that object lifetime defaults should be translated somewhat differently. e.g., instead of transforming them to a normal elided lifetime, maybe we should make a "object lifetime default elided", so that other parts of the system can know to ignore them. But I'd like to better understand just where the ICE arises. Note that this is a bug in impl trait as well, though I've not been able to create an ICE there. For example, [this code is rejected]https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ad989b84fb4d9e48c0243fd4ac7a13cc), but I don't believe it should be. |
I have a fix coming. I think I see the problem, though I've not traced every single step. (Also I've not had time to run a full The core problem is that My fix is to distinguish implicit trait object lifetime bounds from other implicit lifetimes, so that when we generate the opaque type we don't create lifetime parameters for them. This also fixes the interaction with |
use different lifetime name for object-lifetime-default elision Introduce a distinct value for `LifetimeName` to use when this is a object-lifetime-default elision. This allows us to avoid creating incorrect lifetime parameters for the opaque types that result. We really need to overhaul this setup at some point! It's getting increasingly byzantine. But this seems like a relatively... surgical fix. r? @cramertj Fixes #62517
…amertj Stabilize `async_await` in Rust 1.39.0 Here we stabilize: - free and inherent `async fn`s, - the `<expr>.await` expression form, - and the `async move? { ... }` block form. Closes rust-lang#62149. Closes rust-lang#50547. All the blockers are now closed. <details> - [x] FCP in rust-lang#62149 - [x] rust-lang#61949; PR in rust-lang#62849. - [x] rust-lang#62517; PR in rust-lang#63376. - [x] rust-lang#63225; PR in rust-lang#63501 - [x] rust-lang#63388; PR in rust-lang#63499 - [x] rust-lang#63500; PR in rust-lang#63501 - [x] rust-lang#62121 (comment) - [x] Some tests for control flow (PR rust-lang#63387): - `?` - `return` in `async` blocks - `break` - [x] rust-lang#61775 (comment), i.e. tests for rust-lang#60944 with `async fn`s instead). PR in rust-lang#63383 </details> r? @cramertj
Code to reproduce:
and then run
cargo check
... (with full backtrace)This also reproduces when
&str
is replaced with&_
(where_
is any type), but does't reproduce with&'static _
.The text was updated successfully, but these errors were encountered: