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

Traits other than NoCell permit UnsafeCells #682

Merged
merged 1 commit into from
Dec 8, 2023
Merged

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Dec 6, 2023

Previously, FromZeros, FromBytes, and AsBytes could not be
implemented for types containing UnsafeCells. This is a soundness
precondition for some types of reference transmutations (notably
transmuting either direction between &[u8] and &T). However, some of
our machinery operates only on values (e.g. transmute!), and that
machinery should in principle be able to support types which contain
UnsafeCells.

In this commit, we remove the "no UnsafeCell" restriction from
FromZeros, FromBytes, and AsBytes. We use the recently-added
NoCell trait as a bound on individual functions and methods where
UnsafeCells would be unsound. This permits some APIs to support
UnsafeCells which could not previously support them.

Closes #251

@joshlf joshlf changed the title Traits other than NoCell permit UnsafeCells Traits other than NoCell permit UnsafeCells Dec 6, 2023
@joshlf joshlf changed the title Traits other than NoCell permit UnsafeCells Traits other than NoCell permit UnsafeCells Dec 6, 2023
@joshlf joshlf force-pushed the split-traits-and-no-cell branch 2 times, most recently from 4452fcf to 76f7644 Compare December 7, 2023 00:03
src/lib.rs Show resolved Hide resolved
@joshlf joshlf force-pushed the split-traits-and-no-cell branch 3 times, most recently from dd73d95 to c56101f Compare December 7, 2023 22:44
@joshlf joshlf marked this pull request as ready for review December 7, 2023 22:45
@joshlf joshlf force-pushed the split-traits-and-no-cell branch 2 times, most recently from 7b6b5b5 to 68bbac7 Compare December 7, 2023 22:53
@joshlf joshlf requested a review from jswrenn December 7, 2023 22:53
src/lib.rs Outdated Show resolved Hide resolved
Previously, `FromZeros`, `FromBytes`, and `AsBytes` could not be
implemented for types containing `UnsafeCell`s. This is a soundness
precondition for some types of reference transmutations (notably
transmuting either direction between `&[u8]` and `&T`). However, some of
our machinery operates only on values (e.g. `transmute!`), and that
machinery should in principle be able to support types which contain
`UnsafeCell`s.

In this commit, we remove the "no `UnsafeCell`" restriction from
`FromZeros`, `FromBytes`, and `AsBytes`. We use the recently-added
`NoCell` trait as a bound on individual functions and methods where
`UnsafeCell`s would be unsound. This permits some APIs to support
`UnsafeCell`s which could not previously support them.

Closes #251
@joshlf joshlf added this pull request to the merge queue Dec 8, 2023
Merged via the queue into main with commit a8572da Dec 8, 2023
126 checks passed
@joshlf joshlf deleted the split-traits-and-no-cell branch December 8, 2023 17:43
joshlf added a commit that referenced this pull request Dec 8, 2023
Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid
transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]`
is a valid transformation. This slightly changes the meaning of
`AsBytes` and makes `ToBytes` a more appropriate name since it only
permits value rather than reference transmutations. This also brings the
pair of `FromBytes` and `ToBytes` in line with the standard library
`From` and `Into` traits from a naming perspective.

Closes #695
joshlf added a commit that referenced this pull request Dec 11, 2023
Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid
transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]`
is a valid transformation. This slightly changes the meaning of
`AsBytes` and makes `IntoBytes` a more appropriate name since it only
permits value rather than reference transmutations. This also brings the
pair of `FromBytes` and `IntoBytes` in line with the standard library
`From` and `Into` traits from a naming perspective.

Closes #695
joshlf added a commit that referenced this pull request Dec 11, 2023
Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid
transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]`
is a valid transformation. This slightly changes the meaning of
`AsBytes` and makes `IntoBytes` a more appropriate name since it only
permits value rather than reference transmutations. This also brings the
pair of `FromBytes` and `IntoBytes` in line with the standard library
`From` and `Into` traits from a naming perspective.

Closes #695
joshlf added a commit that referenced this pull request Dec 11, 2023
Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid
transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]`
is a valid transformation. This slightly changes the meaning of
`AsBytes` and makes `IntoBytes` a more appropriate name since it only
permits value rather than reference transmutations. This also brings the
pair of `FromBytes` and `IntoBytes` in line with the standard library
`From` and `Into` traits from a naming perspective.

Closes #695
joshlf added a commit that referenced this pull request Dec 11, 2023
Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid
transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]`
is a valid transformation. This slightly changes the meaning of
`AsBytes` and makes `IntoBytes` a more appropriate name since it only
permits value rather than reference transmutations. This also brings the
pair of `FromBytes` and `IntoBytes` in line with the standard library
`From` and `Into` traits from a naming perspective.

Closes #695
github-merge-queue bot pushed a commit that referenced this pull request Dec 14, 2023
Previously, `T: AsBytes` indicated that `&T -> &[u8]` was a valid
transformation. As of #682, `T: AsBytes` only indicates that `T -> [u8]`
is a valid transformation. This slightly changes the meaning of
`AsBytes` and makes `IntoBytes` a more appropriate name since it only
permits value rather than reference transmutations. This also brings the
pair of `FromBytes` and `IntoBytes` in line with the standard library
`From` and `Into` traits from a naming perspective.

Closes #695
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants