5 ms·
This doesn't 'cast' anything. The compiler prevents this because it would allow references that outlive their owners. Freely 'casting' only works for data that
by selfmodruntime 10mo ago
This doesn't 'cast' anything. The compiler prevents this because it would allow references that outlive their owners. Freely 'casting' only works for data that is static in nature anyways, at which point a coercion is taking place. Any other way involves `std::mem::transmute` or `Box::leak` and the like.
- tick_tock_tick 10mo agoHere is a nice segfault in perfectly legal safe Rust https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b5ac5ef8f2928dcaab148fc911c12c5e https://play.rust-lang.org/?version=stable&mode=debug&editio... I'd call it casting thought technically maybe it's not you might want to call it something else? You don't need transmute or leak. The issue is only 10 years old now https://github.com/rust-lang/rust/issues/25860 https://github.com/rust-lang/rust/issues/25860
- dwattttt 10mo agoYes, that's an existing soundness hole in the compiler. You won't accidentally code it up yourself though. If the bar is "deliberately malicious code results in a segfault", get back to me when they fix memcpy(0x10000, 0x20000, 0x10); EDIT: and even that's being charitable; the Rust issue is viewed as a compiler bug which should be fixed.