bors
f5079d00e6
Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk
...
(Re-)Implement `impl_trait_in_bindings`
This reimplements the `impl_trait_in_bindings` feature for local bindings.
"`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference):
```rust
let _: impl Fn(&u8) -> &u8 = |x| x;
```
They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes:
```rust
trait Static: 'static {}
impl<T> Static for T where T: 'static {}
let local = 1;
let x: impl Static = &local;
//~^ ERROR `local` does not live long enough
```
r? oli-obk
cc #63065
---
Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example:
```rust
type TAIT = impl Display;
let local = 0;
let x: TAIT = &local;
//~^ ERROR `local` does not live long enough
```
That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here.
---
I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
2024-12-14 10:22:43 +00:00
..
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-10-22 07:37:54 +01:00
2024-10-22 07:37:54 +01:00
2024-04-07 13:30:12 -04:00
2024-04-07 13:30:12 -04:00
2024-09-29 23:40:43 -05:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-12-11 11:59:12 +00:00
2024-12-13 16:45:43 +00:00
2024-12-13 16:45:43 +00:00
2024-12-13 16:45:43 +00:00
2024-12-11 11:59:12 +00:00
2024-11-24 21:42:22 +09:00
2024-11-24 21:42:22 +09:00
2024-11-24 15:24:01 +00:00
2024-11-24 15:24:01 +00:00
2024-12-10 16:52:20 +00:00
2024-12-10 16:52:20 +00:00
2024-12-13 00:04:56 +00:00
2024-12-13 00:04:56 +00:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-10-11 20:38:43 +02:00
2024-10-11 20:38:43 +02:00
2024-10-11 20:38:43 +02:00
2024-04-06 11:21:47 -04:00
2024-04-06 11:21:47 -04:00
2024-10-04 09:09:20 +02:00
2024-10-04 09:09:20 +02:00
2024-05-04 11:30:38 +02:00
2024-05-04 11:30:38 +02:00
2024-04-24 08:05:29 +00:00
2024-04-24 08:05:29 +00:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-11 06:17:11 -08:00
2024-08-10 14:32:55 +03:00
2024-11-22 11:12:15 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-12-09 21:55:13 +00:00
2024-12-09 21:55:13 +00:00
2024-03-20 22:30:27 +01:00
2024-03-20 22:30:27 +01:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-04-30 22:27:19 +02:00
2024-12-13 15:40:37 +00:00
2024-10-10 01:13:29 +02:00
2024-09-25 13:26:48 +02:00
2024-10-10 01:13:29 +02:00
2024-10-10 01:13:29 +02:00
2024-08-10 12:07:17 +02:00
2024-11-23 08:57:25 -07:00
2024-07-24 21:03:27 +00:00
2024-04-03 16:03:22 -04:00
2024-04-03 16:03:22 -04:00
2024-04-03 16:03:22 -04:00
2024-04-03 16:03:22 -04:00
2024-04-03 16:03:22 -04:00
2024-04-03 16:03:22 -04:00
2024-08-28 23:32:40 +01:00
2024-08-28 23:32:40 +01:00
2024-11-03 13:55:52 -08:00
2024-02-29 14:10:29 +00:00
2024-02-29 14:10:29 +00:00
2024-11-22 11:12:15 -08:00
2024-03-18 16:08:58 +00:00
2024-05-20 09:18:49 +02:00
2024-05-20 09:18:49 +02:00
2024-11-24 19:42:33 +01:00
2024-11-24 19:42:33 +01:00
2024-10-04 23:38:41 +00:00
2024-12-14 03:21:24 +00:00
2024-12-14 03:21:24 +00:00
2024-04-07 13:30:12 -04:00
2024-04-07 13:30:12 -04:00
2024-04-17 13:00:43 +02:00
2024-04-17 13:00:43 +02:00
2024-11-18 20:18:22 +08:00
2024-08-17 12:43:25 -04:00
2024-11-18 14:13:10 +11:00
2024-11-18 14:13:10 +11:00
2024-11-18 14:13:10 +11:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-06-13 22:12:26 -03:00
2024-06-13 22:12:26 -03:00
2024-11-19 05:07:43 +00:00
2024-11-19 05:07:43 +00:00
2024-07-26 16:35:05 +03:00
2024-07-26 16:35:05 +03:00
2024-03-27 11:20:28 -04:00
2024-03-27 11:20:28 -04:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-18 14:13:10 +11:00
2024-11-18 15:55:12 +11:00
2024-11-18 14:13:10 +11:00
2024-07-05 00:52:01 +00:00
2024-07-29 17:50:12 +01:00
2024-07-29 17:50:12 +01:00
2024-06-08 18:17:55 +02:00
2024-10-29 16:26:57 +00:00
2024-10-20 08:34:15 -06:00
2024-10-20 08:34:15 -06:00
2024-06-25 19:00:02 +02:00
2024-06-25 19:00:02 +02:00
2024-03-03 13:10:15 +01:00
2024-03-03 13:10:15 +01:00
2024-10-07 11:15:04 -07:00
2024-10-07 11:15:04 -07:00
2024-03-05 23:34:45 -05:00
2024-03-05 23:34:45 -05:00
2024-10-10 11:44:11 -07:00
2024-10-10 11:44:11 -07:00
2024-04-25 07:58:31 +02:00
2024-04-25 07:58:31 +02:00
2024-09-09 19:39:43 -07:00
2024-08-06 11:17:26 +02:00
2024-06-28 14:20:43 -04:00
2024-06-28 14:20:43 -04:00
2024-06-28 14:20:43 -04:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-09-22 10:00:24 +02:00
2024-09-22 10:00:24 +02:00
2024-10-30 12:27:48 -07:00
2024-10-30 12:27:48 -07:00
2024-08-02 02:29:15 +05:30
2024-08-02 02:29:15 +05:30
2024-06-18 04:14:43 +08:00
2024-06-18 04:14:43 +08:00
2024-09-09 19:39:43 -07:00
2024-11-26 02:50:48 +08:00
2024-11-26 02:50:48 +08:00
2024-06-24 16:08:51 +03:00
2024-04-11 16:39:06 +00:00
2024-04-22 16:28:20 +00:00
2024-10-21 15:22:17 +01:00
2024-10-21 15:22:17 +01:00
2024-11-03 13:55:52 -08:00
2024-10-29 16:26:57 +00:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-05-30 22:52:33 +02:00
2024-07-06 23:29:58 +08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-09-23 11:57:28 +02:00
2024-09-23 11:57:28 +02:00
2024-11-21 19:32:07 +01:00
2024-11-21 19:32:07 +01:00
2024-11-21 19:32:07 +01:00
2024-12-12 16:29:40 +00:00
2024-12-12 16:29:40 +00:00
2024-09-27 00:45:02 +00:00
2024-09-27 00:45:02 +00:00
2024-07-17 11:01:29 +01:00
2024-09-29 23:40:43 -05:00
2024-04-28 19:27:05 +01:00
2024-10-15 13:11:00 +02:00
2024-07-11 19:00:49 -07:00
2024-07-11 19:00:49 -07:00
2024-07-12 23:30:22 +05:30
2024-07-12 23:30:22 +05:30
2024-04-09 23:58:18 +02:00
2024-08-22 14:22:23 -04:00
2024-12-12 23:36:27 +00:00
2024-12-12 23:36:27 +00:00
2024-12-12 23:36:27 +00:00
2024-06-24 16:08:51 +03:00
2024-06-24 16:08:51 +03:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-11-03 13:55:52 -08:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-11-03 13:55:52 -08:00
2024-10-12 10:19:24 +02:00
2024-11-10 10:16:26 +01:00
2024-07-30 14:08:02 +00:00