Skip to content

Commit

Permalink
Correctly derive Clone on generated types (#184)
Browse files Browse the repository at this point in the history
* Added a failing test

* Implement clone where possible

* Arguments can't be called "i"
  • Loading branch information
Michael Bryan committed Apr 1, 2022
1 parent 01231ec commit f5eed0f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/gen-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ pub trait RustGenerator {
// skip copy/clone
} else if !info.owns_data() {
self.push_str("#[derive(Clone, Copy)]\n");
} else if !info.has_handle {
self.push_str("#[derive(Clone)]\n");
}
self.push_str(&format!("pub enum {}", name.to_camel_case()));
self.print_generics(&info, lt, true);
Expand Down
7 changes: 7 additions & 0 deletions tests/codegen/variants.wit
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,10 @@ return-option-sugar: function() -> option<s32>
return-option-sugar2: function() -> option<my-errno>

expected-simple: function() -> expected<u32, s32>

record is-clone {
v1: v1,
}

is-clone-arg: function(a: is-clone)
is-clone-return: function() -> is-clone

0 comments on commit f5eed0f

Please sign in to comment.