Skip to content

Marker types should implement standard traits (Hash, Eq, etc.) #17461

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

Closed
zwarich opened this issue Sep 22, 2014 · 2 comments
Closed

Marker types should implement standard traits (Hash, Eq, etc.) #17461

zwarich opened this issue Sep 22, 2014 · 2 comments

Comments

@zwarich
Copy link

zwarich commented Sep 22, 2014

It was surprising to me that the program

use std::kinds::marker::ContravariantLifetime;

#[deriving(Hash, Eq, PartialEq)]
struct A<'a> {
    x: u64,
    marker: ContravariantLifetime<'a>,
}

fn main() { }

gives this error:

test.rs:6:5: 6:38 error: type `core::kinds::marker::ContravariantLifetime<'_>` does not implement any method in scope named `assert_receiver_is_total_eq`
test.rs:6     marker: ContravariantLifetime<'a>,
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:3:18: 3:20 note: in expansion of #[deriving(Eq)]
test.rs:6:5: 6:38 note: expansion site
test.rs:6:5: 6:38 error: type `core::kinds::marker::ContravariantLifetime<'_>` does not implement any method in scope named `hash`
test.rs:6     marker: ContravariantLifetime<'a>,
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:3:12: 3:16 note: in expansion of #[deriving(Hash)]
test.rs:6:5: 6:38 note: expansion site
error: aborting due to 2 previous errors
@huonw huonw added the A-libs label Sep 23, 2014
@nham
Copy link
Contributor

nham commented Apr 20, 2015

I think the updated equivalent of this code is:

use std::marker::PhantomData;

#[derive(Hash, Eq, PartialEq)]
struct A<'a> {
    x: u64,
    marker: PhantomData<&'a ()>,
}

fn main() { }

which compiles on this version of rust-nightly:

rustc 1.0.0-nightly (a52182ffd 2015-04-17) (built 2015-04-17)

So it seems this issue may be resolved.

@alexcrichton
Copy link
Member

Thanks @nham!

lnicola pushed a commit to lnicola/rust that referenced this issue Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants