Skip to content

ICE with unsizing an extern type #79409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DutchGhost opened this issue Nov 25, 2020 · 3 comments · May be fixed by #137944
Open

ICE with unsizing an extern type #79409

DutchGhost opened this issue Nov 25, 2020 · 3 comments · May be fixed by #137944
Labels
C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` F-unsized_locals `#![feature(unsized_locals)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

Code

#![feature(extern_types)]
#![feature(unsized_locals)]

extern { 
    type Device;
}

unsafe fn make_device() -> Box<Device> {
    Box::from_raw(0 as *mut _)
}

fn main() {
    let d: Device = unsafe { *make_device() };
}

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (1c389ffef 2020-11-24)

Error output

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `false`,
 right: `true`', compiler/rustc_codegen_llvm/src/builder.rs:445:9
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/panicking.rs:92:14
   2: <rustc_codegen_llvm::builder::Builder as rustc_codegen_ssa::traits::builder::BuilderMethods>::load_operand
   3: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_consume
   4: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_operand
   5: rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_block
   6: rustc_codegen_ssa::mir::codegen_mir
   7: rustc_codegen_ssa::base::codegen_instance
   8: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
   9: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  11: rustc_codegen_llvm::base::compile_codegen_unit
  12: rustc_codegen_ssa::base::codegen_crate
  13: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  14: rustc_interface::queries::Queries::ongoing_codegen
  15: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  16: rustc_span::with_source_map
  17: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

@DutchGhost DutchGhost added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 25, 2020
@jonas-schievink jonas-schievink added F-extern_types `#![feature(extern_types)]` F-unsized_locals `#![feature(unsized_locals)]` requires-nightly This issue requires a nightly compiler in some way. labels Nov 25, 2020
@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Nov 25, 2020

It seems clear to me that this shouldn't compile: there's no way to determine, even at run time, how many bytes of storage d needs (short of looking at the external code to see the size of Device, or calling some function in the compiled extern code to ask what the size of Device is, neither of which can be done in general). So we just can't support an unsized local of an extern type.

But this presents a pretty big problem: unsized locals of ?Sized generic parameter types. This program can't be correct (and indeed it ICEs the same way as the original code), but which part of it is in error?

#![feature(extern_types)]
#![feature(unsized_locals)]

extern {
    type Foo;
}

fn mk_foo() -> Box<Foo> {
    unimplemented!()
}

fn unsized_local_generic_parameter<T: ?Sized>(x: Box<T>) {
    // `unsized_locals` allows you to create locals of generic `?Sized`
    // parameter types
    let _x = *x;
}

fn main() {
    // But `extern_types` allows you to create pointers to extern types, and
    // pass them to functions expecting a pointer to a `?Sized` parameter type
    unsized_local_generic_parameter(mk_foo());
}

It seems to me that these features can't coexist as they are currently - extern_types breaks unsized_locals's fundamental assumption that at runtime we can determine the size of any type, even ?Sized ones.

I think this needs discussion from the lang team.

@Enselic
Copy link
Member

Enselic commented Aug 29, 2023

Triage: Still reproduces in Playground on current nightly, now at compiler/rustc_codegen_llvm/src/builder.rs:491:9.

@matthiaskrgr
Copy link
Member

thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/builder.rs:493:17:
unsized locals must not be `extern` types
stack backtrace:
   0:     0x7f5a38b8c7e6 - std::backtrace_rs::backtrace::libunwind::trace::h92488e4bb2264071
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f5a38b8c7e6 - std::backtrace_rs::backtrace::trace_unsynchronized::h97e02be157039c96
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5a38b8c7e6 - std::sys_common::backtrace::_print_fmt::h89a2b01cb3c33339
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f5a38b8c7e6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha79772b33774e7af
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f5a38bdeed0 - core::fmt::rt::Argument::fmt::h6d2228239beb9437
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/core/src/fmt/rt.rs:142:9
   5:     0x7f5a38bdeed0 - core::fmt::write::h9bcb8c2e898ce4b2
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f5a38b801df - std::io::Write::write_fmt::he7ba80727a5f8d75
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/io/mod.rs:1810:15
   7:     0x7f5a38b8c5c4 - std::sys_common::backtrace::_print::h9bd2ce6833902b42
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f5a38b8c5c4 - std::sys_common::backtrace::print::h09be6e715f2e0cc6
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f5a38b8f357 - std::panicking::default_hook::{{closure}}::h81ac1ebc9ea0357f
  10:     0x7f5a38b8f0b9 - std::panicking::default_hook::hfc7d2f2254fbbaf6
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:292:9
  11:     0x7f5a3b94e03c - std[e13db6861558cd66]::panicking::update_hook::<alloc[74e4b4cff019550b]::boxed::Box<rustc_driver_impl[f3f951fd75793e59]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f5a38b8faa6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h864b8f962a42f35c
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/alloc/src/boxed.rs:2030:9
  13:     0x7f5a38b8faa6 - std::panicking::rust_panic_with_hook::he5915ec9da668475
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:783:13
  14:     0x7f5a38b8f7b9 - std::panicking::begin_panic_handler::{{closure}}::h8912c4af58ae3d2d
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:649:13
  15:     0x7f5a38b8cce6 - std::sys_common::backtrace::__rust_end_short_backtrace::hfbc35781d5527627
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f5a38b8f550 - rust_begin_unwind
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/panicking.rs:645:5
  17:     0x7f5a38bdb5d5 - core::panicking::panic_fmt::hc3a8fce14bfb5d21
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/core/src/panicking.rs:72:14
  18:     0x7f5a3ce77ab6 - <rustc_codegen_ssa[ab39db10c7744d49]::mir::FunctionCx<rustc_codegen_llvm[5233fca0b810d365]::builder::Builder>>::codegen_operand
  19:     0x7f5a3d48fb17 - <rustc_codegen_ssa[ab39db10c7744d49]::mir::FunctionCx<rustc_codegen_llvm[5233fca0b810d365]::builder::Builder>>::codegen_block
  20:     0x7f5a3d789783 - rustc_codegen_ssa[ab39db10c7744d49]::mir::codegen_mir::<rustc_codegen_llvm[5233fca0b810d365]::builder::Builder>
  21:     0x7f5a3d776f52 - rustc_codegen_llvm[5233fca0b810d365]::base::compile_codegen_unit::module_codegen
  22:     0x7f5a3db89cab - <rustc_codegen_llvm[5233fca0b810d365]::LlvmCodegenBackend as rustc_codegen_ssa[ab39db10c7744d49]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  23:     0x7f5a3dba85f9 - rustc_codegen_ssa[ab39db10c7744d49]::base::codegen_crate::<rustc_codegen_llvm[5233fca0b810d365]::LlvmCodegenBackend>
  24:     0x7f5a3dba7d35 - <rustc_codegen_llvm[5233fca0b810d365]::LlvmCodegenBackend as rustc_codegen_ssa[ab39db10c7744d49]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x7f5a3dba60f0 - rustc_interface[1dfaeeba2be2315d]::passes::start_codegen
  26:     0x7f5a3dba5826 - <rustc_interface[1dfaeeba2be2315d]::queries::Queries>::codegen_and_build_linker
  27:     0x7f5a3d9169de - rustc_interface[1dfaeeba2be2315d]::interface::run_compiler::<core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>, rustc_driver_impl[f3f951fd75793e59]::run_compiler::{closure#0}>::{closure#0}
  28:     0x7f5a3dbd04c6 - std[e13db6861558cd66]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_with_globals<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_pool_with_globals<rustc_interface[1dfaeeba2be2315d]::interface::run_compiler<core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>, rustc_driver_impl[f3f951fd75793e59]::run_compiler::{closure#0}>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>
  29:     0x7f5a3dbd02f3 - <<std[e13db6861558cd66]::thread::Builder>::spawn_unchecked_<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_with_globals<rustc_interface[1dfaeeba2be2315d]::util::run_in_thread_pool_with_globals<rustc_interface[1dfaeeba2be2315d]::interface::run_compiler<core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>, rustc_driver_impl[f3f951fd75793e59]::run_compiler::{closure#0}>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6f83431ac1278f74]::result::Result<(), rustc_span[b49aba93e0aaec5a]::ErrorGuaranteed>>::{closure#1} as core[6f83431ac1278f74]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7f5a38b999d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb53ed9031b4e247a
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/alloc/src/boxed.rs:2016:9
  31:     0x7f5a38b999d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfb9a49e9b795584d
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/alloc/src/boxed.rs:2016:9
  32:     0x7f5a38b999d5 - std::sys::unix::thread::Thread::new::thread_start::h4db5c6ec45610220
                               at /rustc/ca663b06c5492ac2dde5e53cd11579fa8e4d68bd/library/std/src/sys/unix/thread.rs:108:17
  33:     0x7f5a389859eb - <unknown>
  34:     0x7f5a38a097cc - <unknown>
  35:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please attach the file at `/tmp/ices/rustc-ice-2024-01-09T22_37_00-1727225.txt` to your bug report

query stack during panic:
end of query stack
warning: 2 warnings emitted

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
@davidtwco davidtwco linked a pull request Mar 3, 2025 that will close this issue
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 12, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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.

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 17, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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.

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 18, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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)

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 18, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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)

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 24, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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)

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 10, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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)

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 11, 2025
Sized Hierarchy

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`, and makes `MetaSized` and `Sized` into const traits (relying on unstable `feature(const_trait_impl)`). 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 migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- On the current edition, `Sized` is rewritten as `const Sized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const Sized` will be emitted.
  - On the next edition, non-const `Sized` will resume being the default bound.
- On the current edition, `?Sized` is rewritten as `const MetaSized`
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to rewrite the bound to `const MetaSized` will be emitted.
  - On the next edition, writing `?Sized` will be prohibited.
- On the current edition, `const MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
  - If the `sized_hierarchy` feature is enabled, then an edition migration lint to add an explicit `const MetaSized` supertrait will be emitted.
  - On the next edition, there is no default `const MetaSized` supertrait.

Each of these migrations is not conditional on whether the item being migrated *needs* the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `const 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). Only once `sized_hierarchy` is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than `?Sized`. 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 (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
- It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
  - I'd appreciate feedback on how best to go about this from those familiar with the type system.
- On my local machine, this passes all of the test suites, a stage two build and a tidy check.
- `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)

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 14, 2025
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)

Fixes rust-lang#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` F-unsized_locals `#![feature(unsized_locals)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants