UB in Rust vs C
UB in Rust vs C
Posted Aug 15, 2024 6:45 UTC (Thu) by ralfj (subscriber, #172874)In reply to: UB in Rust vs C by abatters
Parent article: Standards for use of unsafe Rust in the kernel
In Rust, we don't have such flags, since they lead to code that is UB or not depending on how you compile it, which we consider to be a bad idea. Instead, we offer non-UB versions of the relevant operations that programmers can use explicitly, such as raw pointers (to get around the aliasing requirements associated with references) and `wrapping_offset` vs `offset` on pointers and `wrapping_add/sub/mul/...` on integers (though of course even plain `+` is never UB in Rust, but it is considered a bug when `+` overflows and using `wrapping_add` is how you mark this as not-a-bug).
