← ClaudeAtlas

rust-pin-projectionlisted

Use when you put Pin in a signature, write a self-referential struct, or project a pinned reference into a field. Covers the gate that Pin enforces nothing when the target is Unpin, why Unpin does not mean movable and a PhantomPinned value still moves in safe code, the choice between std::pin::pin!, Box::pin and Pin::new_unchecked and the stack escape that compiles with zero warnings and is undefined behaviour, why a hand-rolled shadowing pin macro is broken, the four structural pinning obligations with their diagnostics, Drop taking &mut self on a pinned value, repr(packed) as incompatible with pinning, and the Unpin rule the projection macros change under you. Triggers on "pin projection", "structural pinning", "pin-project", "pin-project-lite", "PhantomPinned", "Pin::new_unchecked", "self-referential struct", "Unpin", "Box::pin", "std::pin::pin!", "PinnedDrop", "address-sensitive", "E0596", or "cannot borrow data in dereference of".
po4yka/rust-skills · ★ 2 · AI & Automation · score 76
Install: claude install-skill po4yka/rust-skills
# Rust pin projection ## Purpose Decide whether `Pin` buys anything in your signature, then meet the obligations it creates. This skill covers address-sensitive types, `Unpin`, `PhantomPinned`, the three ways to pin a value, and pinning projection into a field, by hand and through the macro crates. The sentence to not get wrong: `Pin<&mut T>` enforces nothing when `T: Unpin`, and `!Unpin` never makes a type unmovable. The restriction starts at the pin, and only for a `!Unpin` type. The skill stops at `Pin`. Polling and cancel safety belong to `rust-async-internals`. Miri belongs to `rust-sanitizers-miri`. Every diagnostic and Miri transcript below comes from rustc 1.97.0, edition 2024, aarch64-apple-darwin, Miri on nightly, pin-project 1.1.13, and pin-project-lite 0.2.17. ## Route the symptom to a section | Symptom or task | Section | | --- | --- | | You are about to write `self: Pin<&mut Self>` | [Pin enforces nothing for an Unpin target](#pin-enforces-nothing-for-an-unpin-target) | | `PhantomPinned`, or a claim that a type "cannot move" | [Unpin does not mean movable](#unpin-does-not-mean-movable) | | `error[E0277]: PhantomPinned cannot be unpinned` | [Get a value pinned](#get-a-value-pinned) | | `error[E0515]: cannot return value referencing temporary value`, at a `pin!` | [Get a value pinned](#get-a-value-pinned) | | `error[E0382]: use of moved value`, `does not implement the Copy trait` | [Get a value pinned](#get-a-value-pinned) | | Miri: `allocN has been freed, s