-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Error with nested async fn and anonymous lifetimes #63225
Comments
Reduced: #![feature(async_await)]
struct Foo<'a>(&'a ());
impl<'a> Foo<'a> {
fn test() {
async fn test() {}
}
} |
Forgot to mention in case this helps, giving the inner fn a matching lifetime avoids this issue for some reason: #![feature(async_await)]
struct Foo<'a>(&'a ());
impl<'a> Foo<'a> {
fn test() {
async fn test<'a>() {}
}
} |
The reason this is happening is that the desugared version of |
Hmm @cramertj wouldn't you expect the nested |
@nikomatsakis The function in the middle is actually a bit of a source of confusion here, although it does indicate that there's a second bug since we shouldn't be inheriting generics since the nested The bug I was focusing on is better illustrated by this example: #![feature(async_await)]
struct Foo<'a>(&'a u8);
impl Foo<'_> {
async fn bar() {}
} which produces this error:
This is because the code is transformed into impl Foo<'_> {
fn bar() -> OpaqueTy<'_> {}
} and in that case |
@cramertj I see. Indeed, I would expect that, internally, we'd have some way to refer back to the |
@nikomatsakis Yep, I would've expected so as well-- I'm not sure why that isn't working, I'd have to take a look. |
@cramertj I was looking and I think the bug lies here: rust/src/librustc/hir/lowering.rs Lines 2267 to 2272 in c01be67
Probably |
A closer reading suggests I was mistaken. The |
OK, no, I was correct. When processing impl items, we convert the EDIT: Er, I'm still not entirely sure. Reading more. =) |
OK, I have a fix for the |
I forked off #63500 for the method issue |
@cramertj I didn't prep a fix for this one yet. It seems obvious that some internal state is not being reset when we enter a new item. |
but if you have a chance to investigate, would be appreciated |
Presumably the problem is that rust/src/librustc/hir/lowering/item.rs Line 70 in c01be67
|
Indeed, in-band lifetimes are broken in the same way. This fails to compile (playground): #![feature(in_band_lifetimes)]
struct Foo<'a> {
x: &'a u32
}
impl Foo<'a> {
fn method(&self) {
fn blah(f: Foo<'a>) { }
}
} |
Working on a possible fix |
Yep, have a fix. |
Inband lifetimes looks similar to #52532 fwiw |
@Mark-Simulacrum thanks |
…-impl-lifetime, r=cramertj use `ParamName` to track in-scope lifetimes instead of Ident Also, clear in-scope lifetimes when visiting nested items. Fixes rust-lang#63500. Fixes rust-lang#63225. Fixes rust-lang#52532. r? @cramertj
…-impl-lifetime, r=cramertj use `ParamName` to track in-scope lifetimes instead of Ident Also, clear in-scope lifetimes when visiting nested items. Fixes rust-lang#63500. Fixes rust-lang#63225. Fixes rust-lang#52532. r? @cramertj
…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
The following breaks on nightly (see playground)
With:
CC: dtolnay/async-trait#18
The text was updated successfully, but these errors were encountered: