rustc_session/macros.rs
1/// Derivable trait for enums with no fields (i.e. C-style enums) that want to
2/// allow iteration over a list of all variant values.
3pub(crate) trait AllVariants: Copy + 'static {
4 const ALL_VARIANTS: &[Self];
5}
6
7macro_rules! AllVariantsDerive {
8 derive() (
9 $(#[$meta:meta])*
10 $vis:vis enum $Type:ident {
11 $(
12 $(#[$varmeta:meta])*
13 $Variant:ident $( = $value:literal )?
14 ), *$(,)?
15 }
16 ) => {
17 impl $crate::macros::AllVariants for $Type {
18 const ALL_VARIANTS: &[$Type] = &[
19 $( $Type::$Variant, )*
20 ];
21 }
22 };
23}
24
25// For some reason the compiler won't allow `pub(crate) use AllVariants` due
26// to a conflict with the trait of the same name, but will allow this form.
27pub(crate) use AllVariantsDerive as AllVariants;