2

Stabilize `arbitrary_enum_discriminant` by fee1-dead · Pull Request #86860 · rus...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/86860
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

fee1-dead commented 19 days ago

edited

Closes #60553.


Stabilization Report

copied from #60553 (comment)

Summary

Enables a user to specify explicit discriminants on arbitrary enums.

Previously, this was hard to achieve:

#[repr(u8)]
enum Foo {
    A(u8) = 0,
    B(i8) = 1,
    C(bool) = 42,
}

Someone would need to add 41 hidden variants in between as a workaround with implicit discriminants.

In conjunction with RFC 2195, this feature would provide more flexibility for FFI and unsafe code involving enums.

Test cases

Most tests are in src/test/ui/enum-discriminant, there are two historical tests that are now covered by the feature (removed by this pr due to them being obsolete).

Edge cases

The feature is well defined and does not have many edge cases.
One edge case was related to another unstable feature named repr128 and is resolved.

Previous PRs

The implementation PR added documentation to the Unstable Book, rust-lang/reference#1055 was opened as a continuation of rust-lang/reference#639.

Resolution of unresolved questions

The questions are resolved in #60553 (comment).


(someone please add needs-fcp)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK