Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move likely/unlikely argument outside of invisible unsafe block #79058

Merged
merged 1 commit into from
Nov 15, 2020

Commits on Nov 14, 2020

  1. Move likely/unlikely argument outside of invisible unsafe block

    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
    dtolnay committed Nov 14, 2020
    Configuration menu
    Copy the full SHA
    afb8170 View commit details
    Browse the repository at this point in the history