Skip to content

Add Invariant<T> marker type #31218

Closed
Closed
@bluss

Description

@bluss

From a discussion about different ways to write an Invariant type parameter marker; since we need to express it via PhantomData.

candidates were basically (although this was only used for &'a () cases)

  1. PhantomData<*mut T>
  2. PhantomData<Cell<T>>
  3. PhantomData<fn(T) -> T>

Which all have different drawbacks and incidental other implications.

The source of the confusion was (3) case not passing my simple test for invariance.

Because of the drawbacks, it seems it would be useful to have a real invariance marker in rust's libstd.

(1) and (2) make the type !Sync. (2) has owns-T implications (3) has bug #31200. All of (1), (2), (3) don't respond like Invarant<T> should to custom new OIBITS.

cc @reem if you are interested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions