Files
rust/library/coretests
Jonathan Brouwer cef63f3327 Rollup merge of #155989 - scottmcm:unsized-transmute-copy, r=Mark-Simulacrum
Update `transmute_copy` to ub_checks and `?Sized`

The `assert!` in `transmute_copy` is from rust-lang/rust#98839.  However, it was controversial at the time because it's possible to write `transmute_copy`s that were UB by the description but didn't pass the documented conditions.  It's also sub-optimal to have possible `panic`s in unsafe code where the panic can actually make things worse by dropping things in the middle of what the programmer expected to be panic-free.  Now that we have the `UbChecks` possibility, though, we can do this better: this PR makes it a *non-unwinding* panic when not meeting the documented condition when UB checks are enabled, but which very clearly emphasizes that said check isn't a documented behaviour of the function.

Also, I was staring at the signature and couldn't figure out why it needs `Src: Sized`.  Since it *always* takes a reference, there seems to be no downside to accepting `Src: ?Sized`.  That would also give it more of a reason to exist even if <https://doc.rust-lang.org/nightly/std/mem/fn.transmute_prefix.html> exists (as `transmute_prefix(x)` existing will no longer need the `transmute_copy(&ManuallyDrop::new(x))` polyfill, cc https://github.com/rust-lang/rfcs/pull/3844).  That definitely needs an FCP, though.

(The change to `assert_unsafe_precondition` here doesn't technically need libs-api assent, but I'd still like to hear your thoughts since it's different from the "promise the assert" that IIRC you were also asked to consider elsewhere.)

A partial replacement for rust-lang/rust#154665
2026-07-05 14:12:02 +02:00
..
…