rust/compiler/rustc_middle/src
bors 86d0aef804 Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk
Sized Hierarchy: Part I

This patch implements the non-const parts of rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`. See the RFC for the rationale behind these traits and to discuss whether this change makes sense in the abstract.

These traits are unstable (as is their constness), so users cannot refer to them without opting-in to `feature(sized_hierarchy)`. These traits are not behind `cfg`s as this would make implementation unfeasible, there would simply be too many `cfg`s required to add the necessary bounds everywhere. So, like `Sized`, these traits are automatically implemented by the compiler.

RFC 3729 describes changes which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- `?Sized` is rewritten as `MetaSized`
- `MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.

There are no edition migrations implemented in this,  as these are primarily required for the constness parts of the RFC and prior to stabilisation of this (and so will come in follow-up PRs alongside the const parts). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `MetaSized`) unless the `sized_hierarchy` feature is enabled.

Due to the use of unstable extern types in the standard library and rustc, some bounds in both projects have had to be relaxed already - this is unfortunate but unavoidable so that these extern types can continue to be used where they were before. Performing these relaxations in the standard library and rustc are desirable longer-term anyway, but some bounds are not as relaxed as they ideally would be due to the inability to relax `Deref::Target` (this will be investigated separately).

It is hoped that this is implemented such that it could be merged and these traits could exist "under the hood" without that being observable to the user (other than in any performance impact this has on the compiler, etc). Some details might leak through due to the standard library relaxations, but this has not been observed in test output.

**Notes:**

- Any commits starting with "upstream:" can be ignored, as these correspond to other upstream PRs that this is based on which have yet to be merged.
- This best reviewed commit-by-commit. I've attempted to make the implementation easy to follow and keep similar changes and test output updates together.
  - Each commit has a short description describing its purpose.
  - This patch is large but it's primarily in the test suite.
- I've worked on the performance of this patch and a few optimisations are implemented so that the performance impact is neutral-to-minor.
- `PointeeSized` is a different name from the RFC just to make it more obvious that it is different from `std::ptr::Pointee` but all the names are yet to be bikeshed anyway.
- `@nikomatsakis` has confirmed [that this can proceed as an experiment from the t-lang side](https://rust-lang.zulipchat.com/#narrow/channel/435869-project-goals/topic/SVE.20and.20SME.20on.20AArch64.20.28goals.23270.29/near/506196491)
- FCP in https://github.com/rust-lang/rust/pull/137944#issuecomment-2912207485

Fixes rust-lang/rust#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
2025-06-17 15:08:50 +00:00
..
dep_graph Ensure query keys are printed with reduced queries 2025-06-03 20:56:52 +00:00
hir collect delayed lints in hir_crate_items 2025-06-13 14:03:01 +02:00
hooks Move naked fn checks to hir_typeck 2025-05-30 16:08:44 +00:00
infer yeet CanonicalVarInfo 2025-05-23 12:10:53 +00:00
middle Tracking the old name of renamed unstable library attribute 2025-06-12 19:24:11 +08:00
mir Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
query Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
thir Improve some Visitor comments. 2025-06-04 16:40:00 +10:00
traits Don't fold ExternalConstraintsData when it's empty 2025-06-13 17:57:25 +00:00
ty trait_sel: extend fast path with sized hierarchy 2025-06-16 23:04:35 +00:00
util Remove attribute #[rustc_error] 2025-03-30 01:32:21 +03:00
arena.rs Initial support for dynamically linked crates 2025-05-04 22:03:15 +03:00
error.rs Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
lib.rs library/compiler: add PointeeSized bounds 2025-06-16 23:04:33 +00:00
lint.rs decouple "reporting in deps" from future incompatibility reason 2025-06-03 10:49:22 +02:00
macros.rs Fold visit into ty 2025-03-15 06:34:36 +00:00
metadata.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
tests.rs Give an item related to issue 27438 a more meaningful name 2024-04-30 22:27:19 +02:00
thir.rs Add useful comments on ExprKind::If variants. 2025-05-02 15:53:39 +10:00
values.rs Use search_for_cycle_permutation to look for variances_of 2025-04-27 09:38:18 +02:00