Skip to content

black_box docs correctness claim incorrect #107957

@gonzalobg

Description

@gonzalobg

Location

https://doc.rust-lang.org/stable/std/hint/fn.black_box.html

Summary

The documentation of black_box states:

Programs cannot rely on black_box for correctness in any way.

but this is not accurate since programs can rely on it behaving like the identity function.
It would be better to reword this as

Programs cannot rely on black_box for correctness beyond it behaving as the identity function.

or similar, e.g.,

Programs cannot rely on the optimisation-inhibiting effects of black_box for correctness.

Activity

added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Feb 12, 2023
jyn514

jyn514 commented on Feb 15, 2023

@jyn514
Member

@gonzalobg are you interested in making a PR to fix this? :)

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Feb 15, 2023
gonzalobg

gonzalobg commented on Feb 15, 2023

@gonzalobg
Author

Can't, sorry.

callumio

callumio commented on Feb 15, 2023

@callumio
Contributor

@rustbot claim

added a commit that references this issue on Feb 15, 2023

Rollup merge of rust-lang#108088 - callumio:issue-107957, r=dtolnay

863cd15
gonzalobg

gonzalobg commented on Feb 16, 2023

@gonzalobg
Author

It seems that there are some other parts of the docs that are still incorrect. For example, in the How to use it section, the incorrect claim continues to be repeated:

First and foremost: black_box does not guarantee any exact behavior

I think the whole document needs a pass to fix this.

reopened this on Feb 16, 2023
pat-nel87

pat-nel87 commented on Feb 23, 2023

@pat-nel87
Contributor

@rustbot claim

8 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @callumio@jyn514@gonzalobg@pat-nel87

    Issue actions

      black_box docs correctness claim incorrect · Issue #107957 · rust-lang/rust