File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
crates/formality-macros/src Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change 3
3
Unless you include ` #[customize(constructors)] ` , the ` #[term] ` macro automatically creates constructors as follows:
4
4
5
5
- For a ` struct ` , defines a ` new ` method that takes an ` impl Upcast<T> ` for each of your fields.
6
- - For an ` enum ` , defines a method per variant (converted to snake-case).
6
+ - For an ` enum ` , defines a method per variant that has fields (converted to snake-case).
7
7
- If the name of the variant is a Rust keyword like ` Struct ` , the method will be called ` struct_ ` .
8
+ - We do not generate constructors for variants with no arguments.
Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ fn derive_new_for_variant(
51
51
let type_name = & s. ast ( ) . ident ;
52
52
let ( impl_generics, type_generics, where_clauses) = s. ast ( ) . generics . split_for_impl ( ) ;
53
53
54
+ // If there are no bindings, not worth it.
55
+ if v. bindings ( ) . is_empty ( ) {
56
+ return TokenStream :: default ( ) ;
57
+ }
58
+
54
59
let binding_names = v. bindings ( ) . iter ( ) . map ( |b| & b. binding ) . collect :: < Vec < _ > > ( ) ;
55
60
let binding_types = v. bindings ( ) . iter ( ) . map ( |b| & b. ast ( ) . ty ) . collect :: < Vec < _ > > ( ) ;
56
61
let construct = v. construct ( |_b, i| {
You can’t perform that action at this time.
0 commit comments