-
Notifications
You must be signed in to change notification settings - Fork 13.3k
add wrapper for discriminant_value, take 2 #36823
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
Conversation
assert!(mem::discriminant(&ADT::Second(5)) == mem::discriminant(&ADT::Second(6))); | ||
assert!(mem::discriminant(&ADT::First(2,2)) != mem::discriminant(&ADT::Second(2))); | ||
|
||
let _ = mem::discriminant(&10); |
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.
this could be `assert_eq!(mem::discriminant(&10), mem::discriminant(&20));
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.
The return value for non-enums is unspecified but that doesn't imply it's the same for all non-enums (it is zero, in truth, but...).
It is undefined value. No purpose in testing it. On Sep 29, 2016 3:25 PM, "Oliver Schneider" [email protected]
|
|
||
/// Opaque type representing the discriminant of an enum. | ||
/// | ||
/// See the `discriminant` function in this module for more information. |
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.
This could link to the function in question.
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.
I guess I can do this in a follow-up PR since this already got r+'ed.
@bors r=nagisa |
📌 Commit a84b550 has been approved by |
add wrapper for discriminant_value, take 2 [This is #34785 reopened, since @bors apparently gave up on that thread.] add wrapper for discriminant_value intrinsic Implementation of [RFC 1696](https://github.com/rust-lang/rfcs/blob/master/text/1696-discriminant.md). Wraps the `discriminant_value` intrinsic under the name `std::mem::discriminant`. In order to avoid prematurely leaking information about the implementation of enums, the return value is an opaque type, generic over the enum type, which implements Copy, Clone, PartialEq, Eq, Hash, and Debug (notably not PartialOrd). There is currently no way to get the value out excepting printing the debug representation. The wrapper is safe and can be stabilized soon as per discussion in #24263. cc @aturon r? @nagisa
/// Opaque type representing the discriminant of an enum. | ||
/// | ||
/// See the `discriminant` function in this module for more information. | ||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")] |
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.
IIRC the "reason" field is no longer required since the contents always ended up saying basically the same thing.
Good to know. On Fri, Sep 30, 2016 at 11:24 AM, Steven Fackler [email protected]
|
[This is #34785 reopened, since @bors apparently gave up on that thread.]
add wrapper for discriminant_value intrinsic
Implementation of RFC 1696.
Wraps the
discriminant_value
intrinsic under the namestd::mem::discriminant
. In order to avoid prematurely leaking information about the implementation of enums, the return value is an opaque type, generic over the enum type, which implements Copy, Clone, PartialEq, Eq, Hash, and Debug (notably not PartialOrd). There is currently no way to get the value out excepting printing the debug representation.The wrapper is safe and can be stabilized soon as per discussion in #24263.
cc @aturon
r? @nagisa