-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Clarify how to use black_box()
#133942
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
Clarify how to use black_box()
#133942
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
Could this go into a new section like I think it would also be better to move this new section to the end, the @saethlin I think you've reviewed these docs a couple of times |
I'm already subscribed to this issue :) |
No preference, I'm happy to but all yours if you want (same for Jubilee) |
@rustbot author I'll address the changes later today or sunday, thanks for looking this over! |
@rustbot review |
Ok, I tried my best to address the feedback! Thank you for reviewing :) |
There is one other trick I sometimes use to prevent the inlining of a function, not sure if it is worth illustrating in the docs but here is what it looks like: #[inline(always)]
fn noop() {}
pub fn bad() {
black_box(noop());
}
pub fn good() {
black_box(noop as fn())();
} |
Oh sweet that's a great example of when |
r? @saethlin :) |
Thanks! Squash this down to 1 commit (or I can do that for you), then I'll send this off to the queue. |
00c402c
to
da3fea1
Compare
Cool! Thanks for the fix, and thanks for taking the rest of the review, @saethlin! |
Closes #133923.
r? libs
^ (I think that's the right group, this is my first time!)
This PR adds further clarification on the
black_box()
documentation. Specifically, it teaches how to use it, instead of just when to use it.I tried my best to make it clear and accurate, but a lot of my information is sourced from rust-lang/rust-clippy#12707 and manually inspecting assembly. Please tell me if I got anything wrong!