Is there any way to achieve undefined behavior in Rust without using unsafe
?
Of course, such behavior can be wrapped by a third-party library in a "safe" function so let's assume we're using only the standard one.
Unsafe Superpowers Those superpowers include the ability to: Dereference a raw pointer. Call an unsafe function or method. Access or modify a mutable static variable.
The safety guarantee is one of the most important aspects of Rust; Rust is memory-safe, null-safe, type-safe, and thread-safe by design. If the compiler detects unsafe code, it will refuse to compile that code by default.
Absolutely, but any such case is a bug with Rust or the standard libary.
My favorite example is LLVM loop optimization can make safe programs crash, which actually occurs due to a poor interaction of Rust and LLVM semantics:
pub fn oops() {
(|| loop {
drop(42)
})()
}
Compiled with optimizations on Rust 1.49.0, this produces the assembly:
playground::oops:
ud2
such behavior can be wrapped by a third-party library in a "safe" function so let's assume we're using only the standard one
The standard library is a "third-party library", so I don't get the distinction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With