-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add hint::assert_unchecked
#119133
Add hint::assert_unchecked
#119133
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
3965209
to
edc59fb
Compare
library/core/src/hint.rs
Outdated
#[unstable(feature = "hint_assert_unchecked", issue = "119131")] | ||
pub const unsafe fn assert_unchecked(cond: bool) { | ||
// SAFETY: The caller promised this is true. | ||
unsafe { crate::intrinsics::assume(cond) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to use assert_unsafe_precondition
here like in other unchecked fns like unreachable_unchecked
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I suppose it should. Done.
edc59fb
to
000d5bb
Compare
This could also point to |
000d5bb
to
7556d6f
Compare
@the8472 Sure (The reciprocal mention will have to wait for stabilization.) |
/// benefit to `let n = u32::count_ones(x); assert_unchecked(n <= u32::BITS);`. | ||
/// | ||
/// If ever you're tempted to write `assert_unchecked(false)`, then you're | ||
/// actually looking for [`unreachable_unchecked()`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth mentioning that this is logically entirely equivalent to if !cond { unreachable_unchecked(); }
?
☀️ Test successful - checks-actions |
Finished benchmarking commit (e1fadb2): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 670.004s -> 670.607s (0.09%) |
Libs-API expressed interest, modulo bikeshedding, in rust-lang/libs-team#315 (comment)
I think that means this is good for nightly, since we can always rename it before stabilization.
Tracking issue: #119131