diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-12-11 15:40:49 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-12-11 15:41:16 -0800 |
| commit | 7d556e18b05dbac67d2c5d17c332b5d44afcb192 (patch) | |
| tree | d15ccd96524b3c6d0db0700ad7f17fa7aed68218 /src/libsyntax | |
| parent | 6e38e334de13d878da91991c4c5e9014a06f93cb (diff) | |
| download | rust-7d556e18b05dbac67d2c5d17c332b5d44afcb192.tar.gz rust-7d556e18b05dbac67d2c5d17c332b5d44afcb192.zip | |
Fix deriving for single-variant enums
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving.rs | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index f37f1e268ce..d41e7e31536 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -698,26 +698,30 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, }; other_arms.push(move matching_arm); - // Create the nonmatching pattern. - let nonmatching_pat = @{ - id: cx.next_id(), - node: pat_wild, - span: span - }; - - // Create the nonmatching pattern body. - let nonmatching_expr = build::mk_bool(cx, span, !is_eq); - let nonmatching_body_block = build::mk_simple_block(cx, - span, - nonmatching_expr); - - // Create the nonmatching arm. - let nonmatching_arm = { - pats: ~[ nonmatching_pat ], - guard: None, - body: move nonmatching_body_block - }; - other_arms.push(move nonmatching_arm); + // Maybe generate a non-matching case. If there is only one + // variant then there will always be a match. + if enum_definition.variants.len() > 1 { + // Create the nonmatching pattern. + let nonmatching_pat = @{ + id: cx.next_id(), + node: pat_wild, + span: span + }; + + // Create the nonmatching pattern body. + let nonmatching_expr = build::mk_bool(cx, span, !is_eq); + let nonmatching_body_block = build::mk_simple_block(cx, + span, + nonmatching_expr); + + // Create the nonmatching arm. + let nonmatching_arm = { + pats: ~[ nonmatching_pat ], + guard: None, + body: move nonmatching_body_block + }; + other_arms.push(move nonmatching_arm); + } // Create the self pattern. let self_pat = create_enum_variant_pattern(cx, |
