rust/compiler
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
..
rustc
rustc_abi add extern "custom" functions 2025-06-12 20:27:10 +02:00
rustc_arena
rustc_ast Rollup merge of #134661 - dtolnay:prefixattr, r=fmease 2025-06-15 23:51:54 +02:00
rustc_ast_ir
rustc_ast_lowering Auto merge of #142455 - jdonszelmann:attempt-to-mitigate-delayed-lint-perf-problems, r=oli-obk 2025-06-15 16:52:31 +00:00
rustc_ast_passes Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr 2025-06-13 17:44:15 +00:00
rustc_ast_pretty Rollup merge of #142069 - nnethercote:Zmacro-stats, r=petrochenkov 2025-06-13 05:16:56 +02:00
rustc_attr_data_structures Rollup merge of #142498 - GrigorenkoPV:as-ptr-refactor, r=jdonszelmann 2025-06-16 19:54:34 +02:00
rustc_attr_parsing Port #[rustc_as_ptr] to the new attribute system 2025-06-16 18:13:27 +03:00
rustc_baked_icu_data
rustc_borrowck Auto merge of #142550 - fmease:rollup-fteyzcv, r=fmease 2025-06-16 00:39:47 +00:00
rustc_builtin_macros use if let guards where possible 2025-06-15 15:46:20 +08:00
rustc_codegen_cranelift Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_codegen_gcc Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_codegen_llvm Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +01:00
rustc_codegen_ssa Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +01:00
rustc_const_eval Rollup merge of #142405 - oli-obk:type-once, r=RalfJung 2025-06-13 20:59:17 -07:00
rustc_data_structures library/compiler: add PointeeSized bounds 2025-06-16 23:04:33 +00:00
rustc_driver
rustc_driver_impl Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_error_codes intrinsics: use const generic to set atomic ordering 2025-06-07 21:45:58 +02:00
rustc_error_messages Fix review comments 2025-06-06 14:20:48 +00:00
rustc_errors introduce new lint infra 2025-06-12 09:56:47 +02:00
rustc_expand Remove an njn: comment accidentaly left behind. 2025-06-16 15:18:48 +10:00
rustc_feature Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util
rustc_graphviz
rustc_hashes
rustc_hir trait_sel: {Meta,Pointee}Sized on Sized types 2025-06-16 15:00:22 +00:00
rustc_hir_analysis hir_analysis: add {Meta,Pointee}Sized bounds 2025-06-16 23:04:33 +00:00
rustc_hir_pretty Reduce precedence of expressions that have an outer attr 2025-06-13 18:09:13 -07:00
rustc_hir_typeck trait_sel: extend fast path with sized hierarchy 2025-06-16 23:04:35 +00:00
rustc_incremental
rustc_index index: add method for checking range on DenseBitSet 2025-06-04 00:47:12 +02:00
rustc_index_macros
rustc_infer Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU 2025-06-11 11:47:05 +00:00
rustc_interface Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_lexer rustc_lexer: typo fix + small cleanups 2025-06-06 13:08:16 +00:00
rustc_lint Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_lint_defs Rollup merge of #141937 - WaffleLapkin:never-report-in-deps, r=oli-obk,traviscross 2025-06-15 23:51:55 +02:00
rustc_llvm rustc_llvm: add Windows system libs only when cross-compiling from Windows 2025-05-31 15:47:14 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_metadata Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_middle Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_mir_build Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
rustc_mir_dataflow
rustc_mir_transform Rollup merge of #142347 - azhogin:azhogin/async-drop-storage-live-dead-fix, r=oli-obk 2025-06-15 23:51:56 +02:00
rustc_monomorphize Remove all support for wasm's legacy ABI 2025-06-14 09:57:06 +00:00
rustc_next_trait_solver trait_sel: skip elaboration of sizedness supertrait 2025-06-16 23:04:36 +00:00
rustc_parse Rollup merge of #142341 - xizheyin:142311, r=fee1-dead 2025-06-16 19:54:33 +02:00
rustc_parse_format Add ParseMode::Diagnostic unit tests 2025-06-09 16:28:58 +02:00
rustc_passes Port #[rustc_as_ptr] to the new attribute system 2025-06-16 18:13:27 +03:00
rustc_pattern_analysis Use builin_index instead of hand-rolling it 2025-05-28 10:03:01 +00:00
rustc_privacy Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
rustc_proc_macro Do not get proc_macro from the sysroot in rustc 2025-05-27 15:49:28 +00:00
rustc_query_impl
rustc_query_system Do not clone Arc when hashing span. 2025-06-11 23:44:22 +00:00
rustc_resolve Fix PathSource lifetimes. 2025-06-16 10:33:00 +10:00
rustc_sanitizers Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
rustc_serialize library/compiler: add PointeeSized bounds 2025-06-16 23:04:33 +00:00
rustc_session Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_smir Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_span trait_sel: {Meta,Pointee}Sized on Sized types 2025-06-16 15:00:22 +00:00
rustc_symbol_mangling Rename unpack to kind 2025-05-27 11:14:45 +00:00
rustc_target Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +01:00
rustc_trait_selection trait_sel: skip nominal_obligations for Sized 2025-06-16 23:04:36 +00:00
rustc_traits FIXME(-Znext-solver) triage 2025-06-03 14:23:56 +02:00
rustc_transmute transmutability: shift abstraction boundary 2025-06-09 14:08:12 +00:00
rustc_ty_utils hir_analysis: add {Meta,Pointee}Sized bounds 2025-06-16 23:04:33 +00:00
rustc_type_ir Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_type_ir_macros
stable_mir