Don't glue ManuallyDrop for types that are Copy

This commit is contained in:
Richard Feldman 2022-08-18 11:50:33 -04:00
parent 577128d410
commit 64cea0e7ff
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 20 additions and 13 deletions

View file

@ -1165,10 +1165,10 @@ impl RocType {
/// Construct a tag named `RocDict`, with the appropriate payload
pub fn RocDict(arg0: u32, arg1: u32) -> Self {
let mut answer = Self {
RocDict: core::mem::ManuallyDrop::new(RocType_RocDict {
RocDict: RocType_RocDict {
f0: arg0,
f1: arg1,
})
}
};
answer.set_discriminant(discriminant_RocType::RocDict);
@ -1266,10 +1266,10 @@ impl RocType {
/// Construct a tag named `RocResult`, with the appropriate payload
pub fn RocResult(arg0: u32, arg1: u32) -> Self {
let mut answer = Self {
RocResult: core::mem::ManuallyDrop::new(RocType_RocResult {
RocResult: RocType_RocResult {
f0: arg0,
f1: arg1,
})
}
};
answer.set_discriminant(discriminant_RocType::RocResult);
@ -1780,10 +1780,10 @@ impl RocType {
/// Construct a tag named `RocDict`, with the appropriate payload
pub fn RocDict(arg0: u64, arg1: u64) -> Self {
let mut answer = Self {
RocDict: core::mem::ManuallyDrop::new(RocType_RocDict {
RocDict: RocType_RocDict {
f0: arg0,
f1: arg1,
})
}
};
answer.set_discriminant(discriminant_RocType::RocDict);
@ -1875,10 +1875,10 @@ impl RocType {
/// Construct a tag named `RocResult`, with the appropriate payload
pub fn RocResult(arg0: u64, arg1: u64) -> Self {
let mut answer = Self {
RocResult: core::mem::ManuallyDrop::new(RocType_RocResult {
RocResult: RocType_RocResult {
f0: arg0,
f1: arg1,
})
}
};
answer.set_discriminant(discriminant_RocType::RocResult);

View file

@ -2206,9 +2206,7 @@ fn tag_union_struct_help<'a, I: Iterator<Item = &'a (L, TypeId)>, L: Display + P
.collect::<Vec<String>>()
.join(", ");
let args_to_payload = if is_tag_union_payload {
format!(
"core::mem::ManuallyDrop::new({payload_type_name} {{\n{}\n{INDENT}{INDENT}{INDENT}{INDENT}}})",
sorted_fields
let prefixed_fields = sorted_fields
.iter()
.enumerate()
.map(|(index, (label, _))| {
@ -2223,8 +2221,17 @@ fn tag_union_struct_help<'a, I: Iterator<Item = &'a (L, TypeId)>, L: Display + P
format!("{indents}f{label}: arg{index},")
})
.collect::<Vec<String>>()
.join("\n")
)
.join("\n");
if cannot_derive_copy(types.get_type(payload_id), types) {
format!(
"core::mem::ManuallyDrop::new({payload_type_name} {{\n{}\n{INDENT}{INDENT}{INDENT}{INDENT}}})",prefixed_fields)
} else {
format!(
"{payload_type_name} {{\n{}\n{INDENT}{INDENT}{INDENT}{INDENT}}}",
prefixed_fields
)
}
} else {
"core::mem::ManuallyDrop::new(arg0)".to_string()
};