Fix debug_assert bindgen for tag unions

This commit is contained in:
Richard Feldman 2022-05-19 22:04:16 -04:00
parent 09acc5458b
commit 9a30aaff78
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -280,7 +280,7 @@ impl {name} {{
/// (Always examine .tag() first to make sure this is the correct variant!) /// (Always examine .tag() first to make sure this is the correct variant!)
/// Panics in debug builds if the .tag() doesn't return {tag_name}. /// Panics in debug builds if the .tag() doesn't return {tag_name}.
pub unsafe fn into_{tag_name}({self_for_into}) -> {payload_type_name} {{ pub unsafe fn into_{tag_name}({self_for_into}) -> {payload_type_name} {{
debug_assert_eq!(self.tag(), Self::{tag_name}); debug_assert_eq!(self.tag(), {discriminant_name}::{tag_name});
{get_payload} {get_payload}
}}"#, }}"#,
)?; )?;
@ -293,7 +293,7 @@ impl {name} {{
/// (Always examine .tag() first to make sure this is the correct variant!) /// (Always examine .tag() first to make sure this is the correct variant!)
/// Panics in debug builds if the .tag() doesn't return {tag_name}. /// Panics in debug builds if the .tag() doesn't return {tag_name}.
pub unsafe fn as_{tag_name}(&self) -> {ref_if_needed}{payload_type_name} {{ pub unsafe fn as_{tag_name}(&self) -> {ref_if_needed}{payload_type_name} {{
debug_assert_eq!(self.tag(), Self::{tag_name}); debug_assert_eq!(self.tag(), {discriminant_name}::{tag_name});
{ref_if_needed}self.variant.{tag_name} {ref_if_needed}self.variant.{tag_name}
}}"#, }}"#,
)?; )?;
@ -874,7 +874,7 @@ impl {name} {{
/// (Always examine .tag() first to make sure this is the correct variant!) /// (Always examine .tag() first to make sure this is the correct variant!)
/// Panics in debug builds if the .tag() doesn't return {non_null_tag}. /// Panics in debug builds if the .tag() doesn't return {non_null_tag}.
pub unsafe fn into_{non_null_tag}(self) -> {payload_type_name} {{ pub unsafe fn into_{non_null_tag}(self) -> {payload_type_name} {{
debug_assert_eq!(self.tag(), Self::{non_null_tag}); debug_assert_eq!(self.tag(), {discriminant_name}::{non_null_tag});
let payload = {assign_payload}; let payload = {assign_payload};
let align = core::mem::align_of::<{payload_type_name}>() as u32; let align = core::mem::align_of::<{payload_type_name}>() as u32;
@ -893,7 +893,7 @@ impl {name} {{
/// (Always examine .tag() first to make sure this is the correct variant!) /// (Always examine .tag() first to make sure this is the correct variant!)
/// Panics in debug builds if the .tag() doesn't return {non_null_tag}. /// Panics in debug builds if the .tag() doesn't return {non_null_tag}.
pub unsafe fn as_{non_null_tag}(&self) -> {ref_if_needed}{payload_type_name} {{ pub unsafe fn as_{non_null_tag}(&self) -> {ref_if_needed}{payload_type_name} {{
debug_assert_eq!(self.tag(), Self::{non_null_tag}); debug_assert_eq!(self.tag(), {discriminant_name}::{non_null_tag});
{ref_if_needed}*self.pointer {ref_if_needed}*self.pointer
}}"#, }}"#,
)?; )?;