Matthias Krüger
c4ee2df539
Rollup merge of #120248 - WaffleLapkin:bonk-ptr-object-casts, r=compiler-errors,oli-obk,lnicola
...
Make casts of pointers to trait objects stricter
This is an attempt to `fix` https://github.com/rust-lang/rust/issues/120222 and https://github.com/rust-lang/rust/issues/120217 .
This is done by adding restrictions on casting pointers to trait objects.
Before this PR the rules were as follows:
> When casting `*const X<dyn A>` -> `*const Y<dyn B>`, principal traits in `A` and `B` must refer to the same trait definition (or no trait).
With this PR the rules are changed to
> When casting `*const X<dyn Src>` -> `*const Y<dyn Dst>`
> - if `Dst` has a principal trait `DstP`,
> - `Src` must have a principal trait `SrcP`
> - `dyn SrcP` and `dyn DstP` must be the same type (modulo the trait object lifetime, `dyn T+'a` -> `dyn T+'b` is allowed)
> - Auto traits in `Dst` must be a subset of auto traits in `Src`
> - Not adhering to this is currently a FCW (warn-by-default + `FutureReleaseErrorReportInDeps`), instead of an error
> - if `Src` has a principal trait `Dst` must as well
> - this restriction will be removed in a follow up PR
This ensures that
1. Principal trait's generic arguments match (no `*const dyn Tr<A>` -> `*const dyn Tr<B>` casts, which are a problem for [#120222 ](https://github.com/rust-lang/rust/issues/120222 ))
2. Principal trait's lifetime arguments match (no `*const dyn Tr<'a>` -> `*const dyn Tr<'b>` casts, which are a problem for [#120217 ](https://github.com/rust-lang/rust/issues/120217 ))
3. No auto traits can be _added_ (this is a problem for arbitrary self types, see [this comment](https://github.com/rust-lang/rust/pull/120248#discussion_r1463835350 ))
Some notes:
- We only care about the metadata/last field, so you can still cast `*const dyn T` to `*const WithHeader<dyn T>`, etc
- The lifetime of the trait object itself (`dyn A + 'lt`) is not checked, so you can still cast `*mut FnOnce() + '_` to `*mut FnOnce() + 'static`, etc
- This feels fishy, but I couldn't come up with a reason it must be checked
The diagnostics are currently not great, to say the least, but as far as I can tell this correctly fixes the issues.
cc `@oli-obk` `@compiler-errors` `@lcnr`
2024-07-08 16:28:15 +02:00
..
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-03-21 10:31:04 +09:00
2024-06-30 07:12:26 -04:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-21 19:00:18 -04:00
2024-02-01 03:31:03 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-14 20:15:13 +00:00
2024-02-16 20:02:50 +00:00
2024-03-03 18:53:35 +00:00
2023-01-11 09:32:08 +00:00
2024-02-14 20:15:13 +00:00
2024-04-11 16:41:41 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-07 10:42:01 +08:00
2024-02-16 20:02:50 +00:00
2024-03-08 09:34:38 -07:00
2024-03-08 09:34:38 -07:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-18 21:06:53 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-07 10:42:01 +08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-13 20:22:21 +00:00
2024-06-13 20:22:21 +00:00
2024-06-13 20:22:21 +00:00
2024-06-13 20:22:21 +00:00
2024-06-13 20:22:21 +00:00
2024-02-16 20:02:50 +00:00
2024-06-13 20:22:21 +00:00
2024-05-23 07:23:59 +05:30
2024-06-05 23:20:09 +08:00
2024-06-05 23:20:09 +08:00
2024-06-05 23:20:09 +08:00
2024-01-30 21:28:18 +00:00
2024-02-08 08:10:43 +00:00
2024-04-21 20:10:12 -04:00
2024-02-16 20:02:50 +00:00
2024-02-22 18:04:55 +00:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-02-16 20:02:50 +00:00
2024-02-22 18:05:27 +00:00
2024-02-22 18:05:27 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-27 15:19:08 -04:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-14 11:00:30 +00:00
2024-04-11 16:41:41 +00:00
2024-02-16 20:02:50 +00:00
2024-04-11 16:41:41 +00:00
2024-06-08 08:43:08 +05:30
2024-06-08 08:43:08 +05:30
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-08 08:10:43 +00:00
2024-02-08 08:10:43 +00:00
2024-02-08 08:10:43 +00:00
2024-02-08 08:10:43 +00:00
2024-02-16 20:02:50 +00:00
2024-03-07 14:26:31 +00:00
2024-02-16 20:02:50 +00:00
2024-02-08 08:10:43 +00:00
2024-03-27 14:02:15 +00:00
2024-04-23 00:15:10 +09:00
2024-04-23 00:15:10 +09:00
2024-04-23 00:15:10 +09:00
2024-02-22 18:05:27 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-12 12:34:47 +00:00
2024-02-04 11:34:10 +08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-09 20:47:50 -08:00
2024-03-03 18:53:35 +00:00
2024-04-06 16:23:10 +00:00
2024-04-06 16:23:10 +00:00
2024-06-20 04:25:17 +00:00
2024-02-16 20:02:50 +00:00
2024-06-12 12:34:47 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-15 17:20:44 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-24 08:05:29 +00:00
2024-04-24 08:05:29 +00:00
2024-05-30 22:52:33 +02:00
2024-05-30 22:52:33 +02:00
2024-02-01 03:31:03 +00:00
2024-02-01 03:30:26 +00:00
2024-03-20 17:29:58 +00:00
2024-03-20 17:29:58 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-01-24 02:53:15 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-27 10:54:31 +03:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-08 08:10:43 +00:00
2024-03-11 21:28:16 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-24 02:53:15 +00:00
2024-01-24 02:53:15 +00:00
2024-03-03 18:53:35 +00:00
2024-03-03 18:53:35 +00:00
2024-03-03 18:53:35 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-05 18:53:28 -08:00
2024-02-05 18:53:28 -08:00
2024-05-23 07:23:59 +05:30
2024-07-04 17:56:09 +02:00
2024-07-04 17:56:09 +02:00
2024-07-04 17:56:09 +02:00
2024-02-14 12:42:32 -08:00
2024-02-14 12:42:32 -08:00
2024-02-16 20:02:50 +00:00
2024-02-14 12:42:32 -08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-03-14 17:19:40 +01:00
2024-07-04 05:50:21 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-03-08 20:56:25 +00:00
2024-03-08 20:56:25 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-14 11:00:30 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-14 11:00:30 +00:00
2024-02-14 11:00:30 +00:00
2024-02-14 11:00:30 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-07 10:42:01 +08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-07 10:42:01 +08:00
2024-06-23 23:44:22 +08:00
2024-06-23 23:44:22 +08:00
2024-06-14 11:05:35 -04:00
2024-06-14 11:05:35 -04:00
2024-06-14 11:05:35 -04:00
2024-05-25 09:37:08 +02:00
2024-05-25 09:37:08 +02:00
2024-02-08 08:10:43 +00:00
2024-02-08 08:10:43 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-07 10:42:01 +08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-17 10:57:52 +00:00
2024-06-17 10:57:52 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-14 11:00:30 +00:00
2024-02-14 11:00:30 +00:00
2024-02-16 20:02:50 +00:00
2024-01-21 20:04:39 +04:00
2024-02-16 20:02:50 +00:00
2024-01-19 23:37:39 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-30 22:27:19 +02:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-29 19:07:36 +00:00
2024-02-16 20:02:50 +00:00
2024-04-24 22:21:16 +00:00
2024-04-24 22:21:16 +00:00
2024-04-24 22:21:16 +00:00
2024-04-24 22:21:16 +00:00
2024-06-05 23:20:09 +08:00
2024-06-05 23:20:09 +08:00
2024-06-05 23:20:09 +08:00
2024-04-07 01:16:45 +02:00
2024-04-07 01:16:45 +02:00
2024-07-04 06:06:33 +00:00
2024-01-30 21:28:18 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-07-04 05:50:21 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-05-14 23:07:40 +02:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-03-13 23:05:17 +00:00
2024-02-01 03:31:03 +00:00
2024-04-10 18:58:15 -04:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-05-30 21:39:41 -05:00
2024-03-03 18:53:35 +00:00
2024-03-03 18:53:35 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-24 02:53:15 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-14 18:54:07 +08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-03-07 14:26:31 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-26 20:47:19 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-22 18:04:55 +00:00
2024-02-22 18:05:28 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-30 21:28:18 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-06-12 20:57:23 -04:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-01-19 01:30:46 -08:00
2024-04-25 16:55:33 +00:00
2024-04-25 16:55:33 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-03-07 14:26:31 +00:00
2024-03-07 14:26:31 +00:00
2024-03-07 14:26:31 +00:00
2024-03-07 14:26:31 +00:00
2024-06-13 20:22:21 +00:00
2024-06-13 20:22:21 +00:00
2024-03-17 19:21:13 +09:00
2024-07-04 05:50:21 +00:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-05-20 19:55:59 -07:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-05-20 20:16:29 -04:00
2024-05-20 20:16:29 -04:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-05-30 22:52:33 +02:00
2024-05-30 22:52:33 +02:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-24 08:05:29 +00:00
2024-04-24 08:05:29 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-14 18:45:30 +02:00
2024-04-14 18:45:30 +02:00
2024-05-21 20:16:39 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-22 18:05:27 +00:00
2024-04-23 00:15:10 +09:00
2024-04-23 00:15:10 +09:00