"negative trait bounds are not yet fully implemented; use marker types for now"

For some reason I want my struct to be thread unsafe, so I write code like this:

struct Foo {}

impl !Sync for Foo {}

impl !Send for Foo {}

But the compiler gave me an error like this:

negative trait bounds are not yet fully implemented; use marker types for now

I have no idea on how to do this, but I got a workaround:

struct Bar {
    phantom: PhantomData<Rc<()>>,
}

Since Rc does not implement Sync and Send, My struct Bar will act the same.

My question is:

  1. Is my workaround actually what the error message wants me to do? (I don't like importing the Rc since I don't really use it)
  2. If not, what is the proper way to use a marker to un-implement Sync?

That's fine. You can also use a raw pointer, which does not require an import.

struct Bar {
    _not_send_sync: PhantomData<*const ()>,
}
5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.