clarify that unsafe code must not rely on our safe traits by RalfJung · Pull Request #115607 · rust-lang/rust

@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

@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

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