rust-analyzer/crates
Matthias Krüger 4bd78b0a8d
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
..
base-db chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
cfg fix: Fix doc comment desugaring for proc-macros 2024-04-27 13:30:51 +02:00
flycheck fix: Fix flycheck panicking when cancelled 2024-06-20 10:21:58 +02:00
hir fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs 2024-06-21 21:05:14 +08:00
hir-def Simplify 2024-06-21 18:27:05 +02:00
hir-expand RFC 2383: Stabilize lint_reasons 🎉 2024-06-25 17:22:22 +02:00
hir-ty Prevent re-allocation in CallableSig::from_params_and_return 2024-06-21 19:26:08 +02:00
ide Auto merge of #17419 - ishanjain28:filter_builtin_macro_expansion, r=Veykril 2024-06-20 08:39:17 +00:00
ide-assists Add tactic for associated item constants 2024-06-18 22:08:44 +03:00
ide-completion fix(completion): complete async keyword 2024-06-19 11:12:24 -07:00
ide-db Remove the box_pointers lint. 2024-06-27 08:55:28 +10:00
ide-diagnostics fix: Only show unlinked-file diagnostic on first line during startup 2024-06-13 11:52:34 -07:00
ide-ssr Thread more HasSource::source calls through Semantics for caching 2024-06-10 10:33:07 +02:00
intern Fix new clippy lints 2024-04-01 17:55:56 +02:00
limit Simplify 2024-04-06 13:12:07 +02:00
load-cargo fix: ensure there are no cycles in the source_root_parent_map 2024-06-20 13:46:14 +08:00
mbe Auto merge of #17398 - Veykril:bogus-file, r=Veykril 2024-06-12 07:19:31 +00:00
parser fix: Fix pat fragment parsers choking on <eoi> 2024-06-17 19:42:56 +02:00
paths Apply requested changes round 2 2024-06-05 10:45:22 +02:00
proc-macro-api Register virtual workspace Cargo.toml files in the VFS 2024-06-09 12:54:50 +02:00
proc-macro-srv Auto merge of #16257 - lnicola:rustc-check-cfg, r=Veykril 2024-04-18 12:13:06 +00:00
proc-macro-srv-cli Auto merge of #16257 - lnicola:rustc-check-cfg, r=Veykril 2024-04-18 12:13:06 +00:00
profile Fix typos 2024-05-15 18:55:27 +02:00
project-model feature: add build system info; runnables to rust-project.json 2024-06-11 11:55:17 -04:00
rust-analyzer fix: ensure there are no cycles in the source_root_parent_map 2024-06-20 13:46:14 +08:00
salsa Improve dead code analysis 2024-07-04 22:05:00 +08:00
sourcegen Fix new clippy lints 2024-04-01 17:55:56 +02:00
span internal: Fix rustdoc warnings 2024-06-13 17:29:10 -07:00
stdx Delete CloneAny from rust-analyzer's fork of AnyMap 2024-07-04 17:57:31 +02:00
syntax Update lib.rs 2024-06-18 00:52:53 +01:00
test-fixture style: simplify string interpolation 2024-05-30 16:18:49 -07:00
test-utils internal: Fix rustdoc warnings 2024-06-13 17:29:10 -07:00
text-edit Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
toolchain internal: Fix rustdoc warnings 2024-06-13 17:29:10 -07:00
tt Cleanup some inert attribute stuff 2024-06-04 12:38:20 +02:00
vfs internal: Remove FileId::BOGUS 2024-06-12 08:16:07 +02:00
vfs-notify discard when the path is invalid utf8 symbol. 2024-04-30 15:39:05 +08:00