Skip to content

Commit b01d0ad

Browse files
committed
add another idea for how let ettc can look
1 parent c6a06d9 commit b01d0ad

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

text/0000-return-type-notation.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,20 @@ where
780780
): Send,
781781
```
782782

783-
Note that we had to supply a callable expression (even if it will never execute), so we can't directly talk about the types of the arguments provided to `H::check`, instead we have to use the `dummy` function to produce a fake value of the type we want.
783+
Alternatively, one could write something like this
784+
785+
```rust
786+
fn start_health_check<H>(health_check: H, server: Server)
787+
where
788+
H: HealthCheck + Send + 'static,
789+
typeof {
790+
let hc: &'a mut H;
791+
let s: Server;
792+
H::check(h, ds)
793+
}: Send,
794+
```
795+
796+
Note that we had to supply a callable expression (even if it will never execute), so we can't directly talk about the types of the arguments provided to `H::check`, instead we have to use the `dummy` function to produce a fake value of the type we want or introduce dummy let-bound variables.
784797

785798
Clearly, `typeof` on its own fails the "ergonomic enough to use for simple cases" threshold we were shooting for. But it's also a significantly more powerful feature that introduces a *lot* of complications. We were able to implement a minimal version of RTN in a few days, demonstrating that it fits relatively naturally into the compiler's architecture and existing trait system. In contrast, integrating `typeof` would be rather more complicated. To start, we would need to be running the type checker in new contexts (e.g., in a where clause) at large scale in order to normalize a type like `typeof H::check(x, y)` into the final type it represents.
786799

0 commit comments

Comments
 (0)