Update documentation for cold_path, likely, and unlikely#151612
Merged
rust-bors[bot] merged 3 commits intorust-lang:mainfrom Jan 26, 2026
Merged
Update documentation for cold_path, likely, and unlikely#151612rust-bors[bot] merged 3 commits intorust-lang:mainfrom
cold_path, likely, and unlikely#151612rust-bors[bot] merged 3 commits intorust-lang:mainfrom
Conversation
Collaborator
Other hints have a note recommending benchmarks to ensure they actually do what is intended. This is also applicable for `cold_path`, so add a note here.
bea3ff7 to
bdf5790
Compare
cold_pathcold_path, likely, and unlikely
Member
|
@bors r+ rollup |
Contributor
traviscross
reviewed
Jan 24, 2026
Comment on lines
747
to
761
| /// #[inline(always)] | ||
| /// pub const fn likely(b: bool) -> bool { | ||
| /// if b { | ||
| /// true | ||
| /// } else { | ||
| /// cold_path(); | ||
| /// false | ||
| /// } | ||
| /// } | ||
| /// | ||
| /// #[inline(always)] | ||
| /// pub const fn unlikely(b: bool) -> bool { | ||
| /// if b { | ||
| /// cold_path(); | ||
| /// true | ||
| /// } else { | ||
| /// false | ||
| /// } | ||
| /// } |
Contributor
There was a problem hiding this comment.
Suggested change
| /// #[inline(always)] | |
| /// pub const fn likely(b: bool) -> bool { | |
| /// if b { | |
| /// true | |
| /// } else { | |
| /// cold_path(); | |
| /// false | |
| /// } | |
| /// } | |
| /// | |
| /// #[inline(always)] | |
| /// pub const fn unlikely(b: bool) -> bool { | |
| /// if b { | |
| /// cold_path(); | |
| /// true | |
| /// } else { | |
| /// false | |
| /// } | |
| /// } | |
| /// #[inline(always)] | |
| /// pub const fn likely(b: bool) -> bool { | |
| /// if !b { | |
| /// cold_path(); | |
| /// } | |
| /// b | |
| /// } | |
| /// | |
| /// #[inline(always)] | |
| /// pub const fn unlikely(b: bool) -> bool { | |
| /// if b { | |
| /// cold_path(); | |
| /// } | |
| /// b | |
| /// } |
Or is there a reason to prefer the less-tight factoring?
Contributor
Author
There was a problem hiding this comment.
Nope, this is just our implementation in intrinsics. I’ll apply this.
Contributor
Author
|
@bors r- For a chance to apply TC’s suggestion |
Contributor
|
Commit bdf5790 has been unapproved. |
51 tasks
These were split from the `cold_path` tracking issue.
bdf5790 to
6c0ae93
Compare
Member
Contributor
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Jan 26, 2026
Update documentation for `cold_path`, `likely`, and `unlikely` * Add a note recommending benchmarks to `cold_path`, as other hints have * Note that `cold_path` can be used to implement `likely` and `unlikely` * Update the tracking issue for the `likely_unlikely` feature Tracking issue: rust-lang#136873 Tracking issue: rust-lang#151619
rust-timer
added a commit
that referenced
this pull request
Jan 26, 2026
Rollup merge of #151612 - tgross35:cold-path-doc, r=scottmcm Update documentation for `cold_path`, `likely`, and `unlikely` * Add a note recommending benchmarks to `cold_path`, as other hints have * Note that `cold_path` can be used to implement `likely` and `unlikely` * Update the tracking issue for the `likely_unlikely` feature Tracking issue: #136873 Tracking issue: #151619
github-actions bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this pull request
Jan 29, 2026
Rollup of 2 pull requests Successful merges: - rust-lang/rust#151612 (Update documentation for `cold_path`, `likely`, and `unlikely`) - rust-lang/rust#151670 (compiletest: Parse aux `proc-macro` directive into struct)
This was referenced Feb 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cold_path, as other hints havecold_pathcan be used to implementlikelyandunlikelylikely_unlikelyfeatureTracking issue: #136873
Tracking issue: #151619