Skip to content

PhantomData is not structurally matchable (#[structural_match]) #55028

Closed
@Centril

Description

@Centril

Given:

use std::marker::PhantomData;

const DATA: PhantomData<String> = PhantomData;

fn main() {
    match PhantomData {
        DATA => {}
    };
}

results in:

error: to use a constant of type `std::marker::PhantomData` in a pattern,
`std::marker::PhantomData` must be annotated with `#[derive(PartialEq, Eq)]`
 --> src/main.rs:7:9
  |
7 |         DATA => {}
  |         ^^^^

Is this intentional due to some soundness issue with having it otherwise? (I cannot think of any...)

We could fix this by attaching #[structural_match] to PhantomData<T> manually.

While having PhantomData<T> be structurally matchable is quite boring and useless on its lonesome it prevents other types that contain it from being structurally matchable. (not likely to occur very often, but when it occur it seems like it would be annoying...)

r? @nikomatsakis

cc @rust-lang/lang

Metadata

Metadata

Assignees

Labels

A-type-systemArea: Type systemT-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions