-
Notifications
You must be signed in to change notification settings - Fork 13k
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
caed822
to
3166da0
Compare
3166da0
to
c558d94
Compare
There was a problem hiding this 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
library/core/src/marker/variance.rs
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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 |
There was a problem hiding this comment.
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 😆
library/core/src/marker/variance.rs
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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 |
library/core/src/marker/variance.rs
Outdated
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.
This comment was marked as resolved.
Sorry, something went wrong.
/// - [`PhantomCovariantLifetime`] | ||
/// - [`PhantomContravariantLifetime`] | ||
/// - [`PhantomInvariantLifetime`] | ||
pub const fn variance<T>() -> T |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
c558d94
to
ff415fe
Compare
Swapped the descriptions so as to be correct, reworded them a bit for clarity, and added an example (contrived as it may be). |
ACP accepted rust-lang/libs-team#488
Tracking issue #135806