google / google/zerocopy

Make sure to be sound in the face of coinductive `unsafe trait` impls

Open
#3,380 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

Rust currently has a soundness hole where coinductive `unsafe trait` impls are unsound, [e.g.](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8a63018de780ddef46f4c1bacfb613d0):

```rust
struct NotSend(Rc<()>);

unsafe impl Send for NotSend
where
NotSend: Send
{}
```

Note that this *only* holds for auto traits. In particular, recursive impls for non-auto traits are [considered unsatisfied](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=bbdd48fcca1c9407b3f18d940c3c8ded):

```text
error[E0275]: overflow evaluating the requirement `NotSend: Foo`
--> src/lib.rs:11:5
|
11 | NotSend: Foo
| ^^^^^^^^^^^^
|
= help: see issue #48214
```

We need to figure out whether we're okay saying "we're unsound because Rust itself is unsound" or whether we want to try to forbid these somehow.

cc @lcnr

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.