Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Centril opened this issue Oct 13, 2018 · 0 comments · Fixed by #55837
Closed

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

Centril opened this issue Oct 13, 2018 · 0 comments · Fixed by #55837
Assignees
Labels
A-typesystem Area: The type system T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Oct 13, 2018

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

@Centril Centril added A-typesystem Area: The type system T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 13, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Nov 12, 2018
…rellt-matchbar, r=eddyb

Make PhantomData #[structural_match]

fixes rust-lang#55028

This makes `PhantomData<T>` structurally matchable, irrespective of whether `T` is, per the discussion on this week's language team meeting (the general consensus was that this was a bug-fix).

All types containing `PhantomData<T>` and which used `#[derive(PartialEq, Eq)]` and were previously not `#[structural_match]` only because of `PhantomData<T>` will now be `#[structural_match]`.

r? @nikomatsakis
kennytm added a commit to kennytm/rust that referenced this issue Nov 13, 2018
…rellt-matchbar, r=eddyb

Make PhantomData #[structural_match]

fixes rust-lang#55028

This makes `PhantomData<T>` structurally matchable, irrespective of whether `T` is, per the discussion on this week's language team meeting (the general consensus was that this was a bug-fix).

All types containing `PhantomData<T>` and which used `#[derive(PartialEq, Eq)]` and were previously not `#[structural_match]` only because of `PhantomData<T>` will now be `#[structural_match]`.

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants