Skip to content
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 that unsafe code must not rely on our safe traits #115607

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 6, 2023

This adds a disclaimer to PartialEq, Eq, PartialOrd, Ord, Hash, Deref, DerefMut.

We already have a similar disclaimer in ExactSizeIterator (worded a bit differently):

/// Note that this trait is a safe trait and as such does *not* and *cannot*
/// guarantee that the returned length is correct. This means that `unsafe`
/// code **must not** rely on the correctness of [`Iterator::size_hint`]. The
/// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives
/// this additional guarantee.

If there are any other traits that should carry such a disclaimer, please let me know.

Fixes #73682

@RalfJung RalfJung added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 6, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2023

r? @joshtriplett

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 6, 2023
@RalfJung
Copy link
Member Author

r? libs-api

@rustbot rustbot assigned dtolnay and unassigned joshtriplett Sep 14, 2023
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dtolnay
Copy link
Member

dtolnay commented Sep 15, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 15, 2023

📌 Commit 6211114 has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 16, 2023
…iaskrgr

Rollup of 2 pull requests

Successful merges:

 - rust-lang#115607 (clarify that unsafe code must not rely on our safe traits)
 - rust-lang#115866 (make interpreter and TyAndLayout type Debug impl independent of Ty debug impl)

Failed merges:

 - rust-lang#115873 (Make `TyKind::Adt`'s `Debug` impl be more pretty)
 - rust-lang#115884 (make ty::Const debug printing less verbose)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c2f228f into rust-lang:master Sep 16, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 16, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 16, 2023
Rollup merge of rust-lang#115607 - RalfJung:safe-traits-unsafe-code, r=dtolnay

clarify that unsafe code must not rely on our safe traits

This adds a disclaimer to PartialEq, Eq, PartialOrd, Ord, Hash, Deref, DerefMut.

We already have a similar disclaimer in ExactSizeIterator (worded a bit differently):
```
/// Note that this trait is a safe trait and as such does *not* and *cannot*
/// guarantee that the returned length is correct. This means that `unsafe`
/// code **must not** rely on the correctness of [`Iterator::size_hint`]. The
/// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives
/// this additional guarantee.
```
If there are any other traits that should carry such a disclaimer, please let me know.

Fixes rust-lang#73682
@RalfJung RalfJung deleted the safe-traits-unsafe-code branch September 16, 2023 20:38
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-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify documentation of traits with behavioral contracts (PartialOrd etc.)
5 participants