-
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
Unexpected behaviour when calling associated async function of a trait with default implementations #107002
Comments
I can take a look into this |
Yea, it should be covered |
I've made an MVCE for essentially the same issue, if that can be helpful: https://github.com/fasterthanlime/gh-107528 |
For anyone hitting this: seems like this a decent workaround for the time being is to go through a freestanding function that takes an bearcove/loona@2cae637#diff-b543f39ca4defdc86457f06aaef64e5fdad5fda92c91b4a98f486e7ab7b3b052R81-R87 |
@compiler-errors #108203 didn't fully fix this. the bug still persists when using polymorphic indirection via specialization: #![feature(async_fn_in_trait)]
#![feature(min_specialization)]
struct MyStruct;
trait MyTrait<T> {
async fn foo(_: T);
}
impl<T> MyTrait<T> for MyStruct {
default async fn foo(_: T) {
println!("default");
}
}
impl MyTrait<i32> for MyStruct {
async fn foo(_: i32) {
println!("specialized");
}
}
#[tokio::main]
async fn main() {
MyStruct::foo(42).await;
indirection(42).await;
}
async fn indirection<T>(x: T) {
//explicit type coercion is currently necessary because of https://github.com/rust-lang/rust/issues/67918
<MyStruct as MyTrait<T>>::foo(x).await;
} (note that output is
should be
|
I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e1f645e0ffe95f137fc42c12e783488b
I expected to see this happen:
SyncType::call_default_impl
callsdefault_impl
fromimpl SyncTrait for SyncType
.My expectation was the same for
AsyncType::call_default_impl
of the same pattern.Instead, this happened:
AsyncType::call_default_impl
callsdefault_impl
from the trait's default implementation,instead of the one in
impl AsyncTrait for AsyncType
.So the code prints
A, B
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: