rust/src
Dylan DPC b4cf523cb5
Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors
Allow `impl Fn() -> impl Trait` in return position

_This was originally proposed as part of #93082 which was [closed](https://github.com/rust-lang/rust/pull/93082#issuecomment-1027225715) due to allowing `impl Fn() -> impl Trait` in argument position._

This allows writing the following function signatures:
```rust
fn f0() -> impl Fn() -> impl Trait;
fn f3() -> &'static dyn Fn() -> impl Trait;
```

These signatures were already allowed for common traits and associated types, there is no reason why `Fn*` traits should be special in this regard.

`impl Trait` in both `f0` and `f3` means "new existential type", just like with `-> impl Iterator<Item = impl Trait>` and such.

Arrow in `impl Fn() ->` is right-associative and binds from right to left, it's tested by [this test](a819fecb8d/src/test/ui/impl-trait/impl_fn_associativity.rs).

There even is a test that `f0` compiles:
2f004d2d40/src/test/ui/impl-trait/nested_impl_trait.rs (L25-L28)

But it was changed in [PR 48084 (lines)](https://github.com/rust-lang/rust/pull/48084/files#diff-ccecca938872d65ffe8cd1c3ef1956e309fac83bcda547d8b16b89257e53a437R37)  to test the opposite, probably unintentionally given [PR 48084 (lines)](https://github.com/rust-lang/rust/pull/48084/files#diff-5a02f1ed43debed1fd24f7aad72490064f795b9420f15d847bac822aa4621a1cR476-R477).

r? `@nikomatsakis`

----

This limitation is especially annoying with async code, since it forces one to write this:
```rust
trait AsyncFn3<A, B, C>: Fn(A, B, C) -> <Self as AsyncFn3<A, B, C>>::Future {
    type Future: Future<Output = Self::Out>;

    type Out;
}

impl<A, B, C, Fut, F> AsyncFn3<A, B, C> for F
where
    F: Fn(A, B, C) -> Fut,
    Fut: Future,
{
    type Future = Fut;

    type Out = Fut::Output;
}

fn async_closure() -> impl AsyncFn3<i32, i32, i32, Out = u32> {
    |a, b, c| async move { (a + b + c) as u32 }
}
```
Instead of:
```rust
fn async_closure() -> impl Fn(i32, i32, i32) -> impl Future<Output = u32> {
    |a, b, c| async move { (a + b + c) as u32 }
}
```
2022-10-30 11:50:26 +05:30
..
bootstrap Rollup merge of #102634 - andrewpollack:refactor-test-rustcflags, r=Mark-Simulacrum 2022-10-29 14:18:01 +02:00
ci Drop miri cross-compile check for Windows 2022-10-29 14:24:44 -04:00
doc Rollup merge of #103543 - ehuss:update-books, r=ehuss 2022-10-26 17:32:55 +05:30
etc Rollup merge of #102092 - kxxt:patch-1, r=joshtriplett 2022-10-14 23:43:42 +02:00
librustdoc Rollup merge of #103737 - notriddle:notriddle/margin, r=GuillaumeGomez 2022-10-30 00:09:27 +02:00
llvm-project@4b85255772 Update LLVM submodule 2022-10-23 13:48:03 +02:00
rustdoc-json-types rustdoc-json-types: Improve ItemSummary::path docs 2022-10-28 10:25:48 +01:00
test Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors 2022-10-30 11:50:26 +05:30
tools Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
README.md Remove miri from the submodule list and require it for CI to pass 2022-09-21 15:35:53 +00:00
stage0.json bump stage0 2022-09-26 10:13:46 +02:00
version Bump to 1.67.0 2022-10-29 10:28:52 -04:00

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like cargo, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.