Special-case nullable-unwrapped's null tag

This commit is contained in:
Richard Feldman 2022-08-06 23:35:29 -04:00
parent 31f1aef8e0
commit f644c8ac50
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 21 additions and 2 deletions

View file

@ -610,7 +610,7 @@ pub struct {name} {{
}
}
for (tag_name, opt_payload_id) in tags {
for (tag_index, (tag_name, opt_payload_id)) in tags.into_iter().enumerate() {
// Add a convenience constructor function to the impl, e.g.
//
// /// Construct a tag named Foo, with the appropriate payload
@ -819,6 +819,21 @@ pub struct {name} {{
}}"#,
),
);
} else if Some(tag_index) == null_tag_index {
// The null tag index only occurs for nullable-wrapped tag unions,
// and it always has no payload. This is the one scenario where
// that constructor could come up!
add_decl(
impls,
opt_impl.clone(),
target_info,
format!(
r#"/// A tag named {tag_name}, which has no payload.
pub const {tag_name}: Self = Self {{
pointer: core::ptr::null_mut(),
}};"#,
),
);
} else {
add_decl(
impls,