Skip to content

PhantomPinned warns that field is never read, but PhantomData does not #154888

@clarfonthey

Description

@clarfonthey

I tried this code:

use core::marker::{PhantomData, PhantomPinned};

struct Test {
    pin: PhantomPinned,
    data: PhantomData<()>,
}

fn main() {
    let _ = Test { pin: PhantomPinned, data: PhantomData };
}

This should not show any errors indicating that pin was not read, since its purpose is merely to avoid an Unpin impl. Instead, I get this output:

warning: field `pin` is never read
 --> src/main.rs:4:5
  |
3 | struct Test {
  |        ---- field in this struct
4 |     pin: PhantomPinned,
  |     ^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

Note that PhantomData is specially handled to not do this, and I would expect PhantomPinned to act the same.

Meta

rustc --version --verbose:

rustc 1.96.0-nightly (55e86c996 2026-04-02)
binary: rustc
commit-hash: 55e86c996809902e8bbad512cfb4d2c18be446d9
commit-date: 2026-04-02
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.L-dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions