-
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
Made std::hint::unreachable_unchecked
a const fn.
#70324
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
You probably also want to add a test that executes the intrinsic to initialize a |
Including a test case where we trigger UB would also be good I think. cc @rust-lang/wg-const-eval |
What's the use case for constifying this function? |
Yeah, and for that to work you'll need to actually implement the intrinsic as raising an unreachable error. Intrinsic implementations live in this file. Turns out we forgot about that in Miri. ;) |
I don't know how to write a test for an undefined behavior. Should function be called when initialising a const value, or at runtime? How should assertion or stderr output look like?
Sorry, but I don't know how to do that. |
const unsafe fn f_std_intrinsics_unreachable(x: u8) -> u8 { | ||
match x { | ||
17 => 22, | ||
_ => std::intrinsics::unreachable(), |
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.
std::hint::unreachable_unchecked
is a thing wrapper around the intrinsic, I do not see the point of also testing the intrinsic directly? I don't think we usually do that.
The test @Centril and me asked for was a case where unreachable_unchecked
is used incorrectly, where UB is triggered by actually reaching that function. Like, f_std_hint_unreachable(23)
.
You need to add a new arm in this match on |
I have added an arm to the match inside of
But I have doubts that it is a right way, because everything else in the file calls Also this change, didn't have any effect on output when running the UB test. When I tried to implement a test where function calls
Which references Clearly I can't make this PR, because I have no idea what kind of checks / code should be implemented for And I don't want to endlessly keep bothering people with questions, so I'm gonna close this PR. |
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
But you're almost there. ;)
Yeah that's okay. We have specific error constants for common errors, everything else uses the But your mistake is that you used If rust/src/librustc_span/symbol.rs Line 783 in 1add455
|
r? @oli-obk
tracking issue: #53188