diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-10-25 18:22:03 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-10-26 20:19:53 +1100 |
| commit | 144a12acdd673f333b420e946965621be76d3544 (patch) | |
| tree | 74941306e07207fe752e2100f80acbb37088022c /compiler/rustc_macros/src/lib.rs | |
| parent | 80d0d927d5069b67cc08c0c65b48e7b6e0cdeeb5 (diff) | |
| download | rust-144a12acdd673f333b420e946965621be76d3544.tar.gz rust-144a12acdd673f333b420e946965621be76d3544.zip | |
Add a macro that derives `TryFrom<u32>` for fieldless enums
Diffstat (limited to 'compiler/rustc_macros/src/lib.rs')
| -rw-r--r-- | compiler/rustc_macros/src/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index f46c795b956..0df674eb4c9 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -20,6 +20,7 @@ mod lift; mod query; mod serialize; mod symbols; +mod try_from; mod type_foldable; mod type_visitable; @@ -165,3 +166,12 @@ decl_derive!( suggestion_part, applicability)] => diagnostics::subdiagnostic_derive ); + +decl_derive! { + [TryFromU32] => + /// Derives `TryFrom<u32>` for the annotated `enum`, which must have no fields. + /// Each variant maps to the value it would produce under an `as u32` cast. + /// + /// The error type is `u32`. + try_from::try_from_u32 +} |
