Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

BD103
Copy link
Contributor

@BD103 BD103 commented Dec 5, 2024

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!

@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2024

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 5, 2024
@rust-log-analyzer

This comment has been minimized.

@tgross35
Copy link
Contributor

tgross35 commented Dec 6, 2024

Could this go into a new section like # Usage Guidelines? The docs for this method are getting pretty long.

I think it would also be better to move this new section to the end, the Note however, that black_box is only (and can only be) provided on a "best-effort" basis... section is important to have early.

@saethlin I think you've reviewed these docs a couple of times

@saethlin
Copy link
Member

saethlin commented Dec 6, 2024

I'm already subscribed to this issue :)
Do you want me to take the review?

@tgross35
Copy link
Contributor

tgross35 commented Dec 6, 2024

No preference, I'm happy to but all yours if you want (same for Jubilee)

@BD103
Copy link
Contributor Author

BD103 commented Dec 6, 2024

@rustbot author

I'll address the changes later today or sunday, thanks for looking this over!

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2024
@BD103
Copy link
Contributor Author

BD103 commented Dec 9, 2024

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 9, 2024
@BD103
Copy link
Contributor Author

BD103 commented Dec 9, 2024

Ok, I tried my best to address the feedback! Thank you for reviewing :)

@ryanavella
Copy link

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())();
}

@saethlin
Copy link
Member

saethlin commented Dec 9, 2024

Oh sweet that's a great example of when #[inline(always)] doesn't actually cause a function call to be inlined!

@tgross35
Copy link
Contributor

r? @saethlin :)

@rustbot rustbot assigned saethlin and unassigned tgross35 Dec 10, 2024
@saethlin
Copy link
Member

Thanks! Squash this down to 1 commit (or I can do that for you), then I'll send this off to the queue.

@bors bors merged commit 8abb823 into rust-lang:master Dec 14, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 14, 2024
@BD103 BD103 deleted the black-box-docs branch December 14, 2024 17:16
@workingjubilee
Copy link
Member

Cool! Thanks for the fix, and thanks for taking the rest of the review, @saethlin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify black_box() docs when passed a unit-returning function
8 participants