-
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
Compiler crashes on impl trait for async fn with unstable feature enabled #112347
Comments
In the playground, |
Not related to #![feature(unboxed_closures)]
use std::future::Future;
use async_trait::async_trait;
#[async_trait]
trait Trait<Arg0>
where
Arg0: ?Sized,
{
type Return;
async fn func(&mut self, arg0: &Arg0) -> Self::Return;
}
#[async_trait]
impl<AsyncFn, Arg0, Return> Trait<Arg0> for AsyncFn
where
for<'a> AsyncFn: Fn<(&'a Arg0,)> + Send + Sync,
for<'a> <AsyncFn as FnOnce<(&'a Arg0,)>>::Output: Future<Output = Return> + Send + 'a,
Arg0: ?Sized + Sync,
{
type Return = Return;
async fn func(&mut self, arg0: &Arg0) -> Self::Return {
self(arg0).await
}
}
async fn strlen(x: &str) -> usize {
x.len()
}
#[tokio::main]
async fn main() {
assert_eq!(strlen.func("hello world").await, 11);
} Could be further minimized, I think. |
Thanks for the improvement. I did a small experiment. I found that |
@rustbot claim |
Can be further minimized to: #![feature(unboxed_closures)]
use std::future::Future;
trait Trait {
fn func(&self, _: &str);
}
impl<T> Trait for T
where
for<'a> T: Fn<(&'a str,)> + Send + Sync,
for<'a> <T as FnOnce<(&'a str,)>>::Output: Future<Output = usize> + Send,
{
fn func(&self, _: &str) {
println!("hello!");
}
}
async fn strlen(x: &str) -> usize {
x.len()
}
fn main() {
strlen.func("hi");
} The problem is because |
Here's an even more minimal example, that only relies on #![feature(type_alias_impl_trait)]
use std::future::Future;
type Fut<'a> = impl Future<Output = ()> + 'a;
fn foo<'a>(_: &()) -> Fut<'_> {
async {}
}
trait Test {
fn hello();
}
impl Test for ()
where
for<'a> Fut<'a>: Future<Output = ()>,
{
fn hello() {}
}
fn main() {
<()>::hello();
} |
Add test for futures with HRTB Part of rust-lang#112347 This PR adds test for ice when resolving for `Futures` with HRTB.
@compiler-errors Your minimisation doesn't work on latest nightly (2023-07-12), but @dswij's still works |
…r=<try> Eagerly instantiate closure/coroutine-like bounds with placeholders to deal with binders correctly A follow-up to rust-lang#119849, however it aims to fix a different set of issues. Currently, we have trouble confirming goals where built-in closure/fnptr/coroutine signatures are compared against higher-ranked goals. Currently, we don't support goals like `for<'a> fn(&'a ()): Fn(&'a ())` because we don't expect the self type of goal to reference any bound regions from the goal, because we don't really know how to deal with the double binder of predicate + self type. However, this definitely can be reached (rust-lang#121653) -- and in fact, it results in post-mono errors in the case of rust-lang#112347 where the builtin type (e.g. a coroutine) is hidden behind a TAIT. The proper fix here is to instantiate the goal before trying to extract the signature from the self type. See final two commits. r? lcnr
…r=lcnr Eagerly instantiate closure/coroutine-like bounds with placeholders to deal with binders correctly A follow-up to rust-lang#119849, however it aims to fix a different set of issues. Currently, we have trouble confirming goals where built-in closure/fnptr/coroutine signatures are compared against higher-ranked goals. Currently, we don't support goals like `for<'a> fn(&'a ()): Fn(&'a ())` because we don't expect the self type of goal to reference any bound regions from the goal, because we don't really know how to deal with the double binder of predicate + self type. However, this definitely can be reached (rust-lang#121653) -- and in fact, it results in post-mono errors in the case of rust-lang#112347 where the builtin type (e.g. a coroutine) is hidden behind a TAIT. The proper fix here is to instantiate the goal before trying to extract the signature from the self type. See final two commits. r? lcnr
The bug arose when I was implementing a trait for async functions. I tested this code in the playground, and the compiler also crashed.
Code
Playground link
Meta
rustc --version --verbose
:Error output
Backtrace
RUST_BACKTRACE=1 cargo build
The text was updated successfully, but these errors were encountered: