@@ -698,26 +698,30 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
698
698
} ;
699
699
other_arms. push ( move matching_arm) ;
700
700
701
- // Create the nonmatching pattern.
702
- let nonmatching_pat = @{
703
- id: cx. next_id ( ) ,
704
- node: pat_wild,
705
- span: span
706
- } ;
707
-
708
- // Create the nonmatching pattern body.
709
- let nonmatching_expr = build:: mk_bool ( cx, span, !is_eq) ;
710
- let nonmatching_body_block = build:: mk_simple_block ( cx,
711
- span,
712
- nonmatching_expr) ;
713
-
714
- // Create the nonmatching arm.
715
- let nonmatching_arm = {
716
- pats: ~[ nonmatching_pat ] ,
717
- guard: None ,
718
- body: move nonmatching_body_block
719
- } ;
720
- other_arms. push ( move nonmatching_arm) ;
701
+ // Maybe generate a non-matching case. If there is only one
702
+ // variant then there will always be a match.
703
+ if enum_definition. variants . len ( ) > 1 {
704
+ // Create the nonmatching pattern.
705
+ let nonmatching_pat = @{
706
+ id: cx. next_id ( ) ,
707
+ node: pat_wild,
708
+ span: span
709
+ } ;
710
+
711
+ // Create the nonmatching pattern body.
712
+ let nonmatching_expr = build:: mk_bool ( cx, span, !is_eq) ;
713
+ let nonmatching_body_block = build:: mk_simple_block ( cx,
714
+ span,
715
+ nonmatching_expr) ;
716
+
717
+ // Create the nonmatching arm.
718
+ let nonmatching_arm = {
719
+ pats: ~[ nonmatching_pat ] ,
720
+ guard: None ,
721
+ body: move nonmatching_body_block
722
+ } ;
723
+ other_arms. push ( move nonmatching_arm) ;
724
+ }
721
725
722
726
// Create the self pattern.
723
727
let self_pat = create_enum_variant_pattern ( cx,
0 commit comments