Unsafe Rust and Miri by Ralf Jung - Rust Zürisee June 2023

Discover how Miri detects and prevents undefined behavior in Rust code, including unsafe code, and learn how it improves the compiler's ability to ensure Rust code is safe and reliable.

Key takeaways
  • Miri can detect and prevent undefined behavior (UB) in Rust code, including unsafe code, by simulating the behavior of the code on different platforms.
  • Miri is particularly useful for detecting UB in code that uses unsafe code, as it can detect and prevent UB in a deterministic way.
  • The Rust compiler does not have to worry about UB, as Miri can take care of it.
  • In Rust, unsafe code is a necessary evil, as it allows for low-level memory manipulation, but it requires careful consideration and testing to avoid UB.
  • Miri can be used to check for UB in code, but it’s not a replacement for proper testing and debugging.
  • Even with Miri, Rust code can still have UB if it uses unsafe code, as Miri only detects UB and does not prevent it.
  • The Rust compiler authors strive to prevent UB in compiler-generated code, and Miri helps achieve this goal.
  • Miri is a valuable tool for detecting UB in Rust code, and it’s complementary to the Rust compiler.
  • The Rust team is working on improving Miri and making it more usable for detecting UB in Rust code.