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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Quiet
Tech stack
rust
Domain
security

Research direction

Start with the two Rust Playground examples in the issue and compare the behavior of recursive auto-trait and non-auto-trait impls. The issue does not name repository files or tests; done requires a maintainer decision on whether to accept the unsoundness or define and implement a restriction.

Written by the indexing model from the issue text.

Description

Rust currently has a soundness hole where coinductive unsafe trait impls are unsound, e.g.:

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:

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

Dominant language
Rust
Stars
2.6k
Forks
194
Avg merge
18h 15m
Merged PRs (30d)
14

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/zerocopy

All issues in google/zerocopy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.