use declarative macro for #[derive(TryFromU32)]
This commit is contained in:
22
compiler/rustc_codegen_llvm/src/macros.rs
Normal file
22
compiler/rustc_codegen_llvm/src/macros.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
macro_rules! TryFromU32 {
|
||||
derive() (
|
||||
$(#[$meta:meta])*
|
||||
$vis:vis enum $Type:ident {
|
||||
$(
|
||||
$(#[$varmeta:meta])*
|
||||
$Variant:ident $(= $discr:expr)?
|
||||
),* $(,)?
|
||||
}
|
||||
) => {
|
||||
impl ::core::convert::TryFrom<u32> for $Type {
|
||||
type Error = u32;
|
||||
#[allow(deprecated)] // Don't warn about deprecated variants.
|
||||
fn try_from(value: u32) -> ::core::result::Result<$Type, Self::Error> {
|
||||
$( if value == const { $Type::$Variant as u32 } { return Ok($Type::$Variant) } )*
|
||||
Err(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) use TryFromU32;
|
||||
Reference in New Issue
Block a user