-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
fn_addr_eq docs suggest incorrect reasoning #160202
Copy link
Copy link
Open
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.I-libs-nominatedNominated for discussion during a libs team meeting.Nominated for discussion during a libs team meeting.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem teamRelevant to the opsem team
Description
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.I-libs-nominatedNominated for discussion during a libs team meeting.Nominated for discussion during a libs team meeting.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem teamRelevant to the opsem team
The docs for
fn_addr_eqsayThis is not correct, I think.
Consider this example:
The compiler may now do the following:
gptrpoints tog, and use that to inline the call tog.thenbranch tostd::hint::assert_unchecked(false), and then replace it by arbitrary code (e.g. a trap).fandginto one function since they compile to the same assembly.Now if we run this program we hit the trap, i.e., we have exhibited UB.
(See rust-lang/unsafe-code-guidelines#589 for a wider discussion of the problem. When discussing this we were not aware that our libs docs actually make any claims in this regard.)
Cc @rust-lang/opsem @rust-lang/libs-api