-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fn trait doesn't allow impl returns (impl Fn() -> impl Trait), which is inconsistent with all other traits #101968
Comments
Note that writing |
Just a quick note: compilation still fails for some code using the latest nightly builds (though it used to compile fine with older ones, such as nightly-2022-06-29). For example:
Compilation output:
|
@jpalaciosdev: That regressed in #96727 cc @oli-obk Seems to be a problem with RPIT inference in borrowck |
A bit of an update: #![feature(impl_trait_in_fn_trait_return)]
use core::future::Future;
fn future_closure() -> impl Fn() -> impl Future<Output = bool> {
let f = || async { true };
f
} Can this be closed then? As a side note in argument position it still doesn't work (because we may want to special case fn trait syntax to work better with lifetimes...), however it's easy to transform APIT into a generic: fn future_closure_arg(arg: impl Fn() -> impl Future<Output = bool>) {}
// =>
fn future_closure_arg<Fut: Future<Output = bool>>(arg: impl Fn() -> Fut) {} |
I've been working on a functional interface for a library which relies on code generation, so I have functions returning functions, however I've hit a roadblock with functions returning closures which return traits (without resorting to dynamic dispatch).
The compiler doesn't allow
impl Fn() -> impl Trait
while allowingimpl Trait<T = impl Trait>
which seems inconsistent.Here is my minimal reproduction code:
However, seems like wrapping the Fn in another trait fixes the error, so this doesn't appear to be a functionality limitation but more of an oversight:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: