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

Implement phantom variance markers #135807

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jhpratt
Copy link
Member

@jhpratt jhpratt commented Jan 21, 2025

ACP accepted rust-lang/libs-team#488

Tracking issue #135806

@jhpratt jhpratt added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@Sky9x Sky9x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but I think these should be the other way around

phantom_type! {
/// Zero-sized type used to mark a type parameter as covariant.
///
/// Types passed as arguments to functions are covariant. See [the reference][1] for more
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Types passed as arguments to functions are covariant. See [the reference][1] for more
/// Types returned from functions are covariant. See [the reference][1] for more

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, definitely backwards. Case in point as to why this is necessary 😆

pub struct PhantomCovariant<T>(PhantomData<T>);
/// Zero-sized type used to mark a type parameter as contravariant.
///
/// Types returned from functions are contravariant. See [the reference][1] for more
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Types returned from functions are contravariant. See [the reference][1] for more
/// Types passed as arguments to functions are contravariant. See [the reference][1] for more

pub struct PhantomContravariant<T>(PhantomData<fn(T)>);
/// Zero-sized type used to mark a type parameter as invariant.
///
/// Types used as both arguments and return values. See [the reference][1] for more information.

This comment was marked as resolved.

/// - [`PhantomCovariantLifetime`]
/// - [`PhantomContravariantLifetime`]
/// - [`PhantomInvariantLifetime`]
pub const fn variance<T>() -> T

This comment was marked as resolved.

@jhpratt
Copy link
Member Author

jhpratt commented Jan 22, 2025

Swapped the descriptions so as to be correct, reworded them a bit for clarity, and added an example (contrived as it may be).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants