mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-04 11:17:04 +00:00

The previous `likely!`/`unlikely!` macros were unsound because it permits the caller's expr to contain arbitrary unsafe code. pub fn huh() -> bool { likely!(std::ptr::read(&() as *const () as *const bool)) } Before: compiles cleanly. After: error[E0133]: call to unsafe function is unsafe and requires unsafe function or block | 70 | likely!(std::ptr::read(&() as *const () as *const bool)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior