+ // We put these in const fields so they aren't generated even on -O0
+ #(const #const_field: bool =
+ #core::mem::size_of::<#name>() == #core::mem::size_of::<#int_type>();)*
+ match val {
+ // Every valid variant value has an explicit branch. If they get optimized out,
+ // great. If the representation has changed somehow, and they don't, oh well,
+ // there's still no UB.
+ #(#variant_value => #name::#variant_name,)*
+ // Helps hint to the LLVM that this is a transmute. Note that this branch is
+ // still unreachable.
+ #(x if #const_field => {
+ let x = x as #int_type;
+ *(&x as *const _ as *const #name)
+ })*
+ // Default case. Sometimes causes LLVM to generate a table instead of a simple
+ // transmute, but, oh well.
+ _ => #core::hint::unreachable_unchecked(),
+ }