rust-lang / rust-lang/rust

You can implement `UnsafeUnpinned` yourself

Open
#161,630 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-unsafe_pinned requires-nightly T-compiler T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(unsafe_unpin)]

struct Foo(std::marker::PhantomPinned);

unsafe impl std::marker::UnsafeUnpin for Foo {}

I expected to see this happen: the code does not compile. The impl is unsafe and unsound, but for Freeze we don't accept any user-defined impl, and it makes sense. Those traits are used for compiler-internal tracking; even if we decide to stabilize them, user code shouldn't be allowed to mess with them.

Note that on Freeze we also disallow negative impls (except inside std). This also makes sense to do here IMO, although here that justification is weaker.

Instead, this happened: the code compiles.

@rustbot label +F-unsafe_pinned +B-unstable +requires-nightly

Contributor guide

Open the contributing guide

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.

Research direction

Start by compiling the provided nightly reproducer with the unsafe_unpin feature enabled, then trace how compiler-internal traits such as UnsafeUnpin and Freeze handle user-defined positive and negative impls. Done means the shown impl is rejected, with the corresponding negative-impl restriction addressed if applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.