rust/library/core/tests
Dylan DPC 5ccdf1f6f7
Rollup merge of #98839 - 5225225:assert_transmute_copy_size, r=thomcc
Add assertion that `transmute_copy`'s U is not larger than T

This is called out as a safety requirement in the docs, but because knowing this can be done at compile time and constant folded (just like the `align_of` branch is removed), we can just panic here.

I've looked at the asm (using `cargo-asm`) of a function that both is correct and incorrect, and the panic is completely removed, or is unconditional, without needing build-std.

I don't expect this to cause much breakage in the wild. I scanned through https://miri.saethlin.dev/ub for issues that would look like this (error: Undefined Behavior: memory access failed: alloc1768 has size 1, so pointer to 8 bytes starting at offset 0 is out-of-bounds), but couldn't find any.

That doesn't rule out it happening in crates tested that fail earlier for some other reason, though, but it indicates that doing this is rare, if it happens at all. A crater run for this would need to be build and test, since this is a runtime thing.

Also added a few more transmute_copy tests.
2022-07-18 21:14:42 +05:30
..
fmt
hash libcore tests: avoid int2ptr casts 2022-06-27 13:30:44 -04:00
iter Add Iterator::next_chunk 2022-06-21 08:57:02 +02:00
num Update int_roundings methods from feedback 2022-05-04 23:20:29 -04:00
ops
alloc.rs libcore tests: avoid int2ptr casts 2022-06-27 13:30:44 -04:00
any.rs Add some more tests 2022-06-06 12:10:14 +01:00
array.rs Stabilize core::array::from_fn 2022-05-20 11:04:13 -03:00
ascii.rs
asserting.rs [RFC 2011] Library code 2022-05-22 07:18:32 -03:00
atomic.rs Rename AtomicPtr::fetch_{add,sub}{,_bytes} 2022-07-01 06:21:19 -07:00
bool.rs
cell.rs Fix Display for cell::{Ref,RefMut} 2022-05-20 11:16:30 -07:00
char.rs
clone.rs Use Box::new() instead of box syntax in core tests 2022-05-29 01:44:11 +02:00
cmp.rs
const_ptr.rs
convert.rs
future.rs
intrinsics.rs
lazy.rs Move/rename lazy::{OnceCell, Lazy} to cell::{OnceCell, LazyCell} 2022-06-16 19:53:59 +04:00
lib.rs Stabilize future_poll_fn 2022-07-16 10:04:14 +09:00
macros.rs
manually_drop.rs
mem.rs Add size assert in transmute_copy 2022-07-03 10:46:20 +01:00
nonzero.rs
ops.rs
option.rs Use Box::new() instead of box syntax in core tests 2022-05-29 01:44:11 +02:00
pattern.rs
pin_macro.rs
pin.rs
ptr.rs Auto merge of #98866 - nagisa:nagisa/align-offset-wroom, r=Mark-Simulacrum 2022-07-16 23:28:28 +00:00
result.rs Use Box::new() instead of box syntax in core tests 2022-05-29 01:44:11 +02:00
simd.rs
slice.rs Stage-step cfgs 2022-05-18 12:29:35 -04:00
str_lossy.rs
str.rs
task.rs
time.rs
tuple.rs
unicode.rs revert changes to unicode stability 2022-07-08 21:18:15 +00:00
waker.rs libcore tests: avoid int2ptr casts 2022-06-27 13:30:44 -04:00