-
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
[BUG] Stable (warning): Async traits Self return requires type specification #113538
Comments
This is in fact a bug. |
|
Update: This issue is still present, and has now sneaked into stable with the release of active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.75.0 (82e1608df 2023-12-21)
$ cargo check
warning: opaque type `impl Future<Output = Self>` does not satisfy its associated type bounds
--> src/main.rs:2:5
|
2 | async fn new() -> Self;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
::: /var/home/arthur/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:41:5
|
41 | type Output;
| ------------ this associated type bound is unsatisfied for `Self`
|
= note: `#[warn(opaque_hidden_inferred_bound)]` on by default
warning: `testing-async` (bin "testing-async") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.00s |
This is similar to the bug report issue-119893: calling async trait fn gives compiler error 'type annotations needed' when type annotation is already provided |
@BaxHugh: This isn't the same bug. This just has to do with a false warning of the |
👍 on this, also encountering this bug |
Also encountering with |
…lcnr Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT Conceptually, we should probably not fire `OPAQUE_HIDDEN_INFERRED_BOUND` for methods like: ``` trait Foo { async fn bar() -> Self; } ``` Even though we technically cannot prove that `Self: Sized`, which is one of the item bounds of the `Output` type in the `-> impl Future<Output = Sized>` from the async desugaring. This is somewhat justifiable along the same lines as how we allow regular methods to return `-> Self` even though `Self` isn't sized. Fixes rust-lang#113538 (side-note: some days i wonder if we should just remove the `OPAQUE_HIDDEN_INFERRED_BOUND` lint... it does make me sad that we have non-well-formed types in signatures, though.)
Rollup merge of rust-lang#120360 - compiler-errors:afit-sized-lol, r=lcnr Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT Conceptually, we should probably not fire `OPAQUE_HIDDEN_INFERRED_BOUND` for methods like: ``` trait Foo { async fn bar() -> Self; } ``` Even though we technically cannot prove that `Self: Sized`, which is one of the item bounds of the `Output` type in the `-> impl Future<Output = Sized>` from the async desugaring. This is somewhat justifiable along the same lines as how we allow regular methods to return `-> Self` even though `Self` isn't sized. Fixes rust-lang#113538 (side-note: some days i wonder if we should just remove the `OPAQUE_HIDDEN_INFERRED_BOUND` lint... it does make me sad that we have non-well-formed types in signatures, though.)
When using the
#![feature(async_fn_in_trait)]
flag, I stumbled upon a warning that I don't understand and assume to be a bug/missed implementation.If this is the intended behavior, could anyone please explain why?
This is simplified code that generates the warning:
But when adding a type restriction on self (in this case Sized) the warning does not appear anymore.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: