Merge pull request #4164 from brson/deriving
Fix deriving for single-variant enums
This commit is contained in:
commit
bfb09ee80d
@ -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
|
||||
};
|
||||
// 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 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 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,
|
||||
|
8
src/test/run-pass/deriving-enum-single-variant.rs
Normal file
8
src/test/run-pass/deriving-enum-single-variant.rs
Normal file
@ -0,0 +1,8 @@
|
||||
type task_id = int;
|
||||
|
||||
#[deriving_eq]
|
||||
pub enum Task {
|
||||
TaskHandle(task_id)
|
||||
}
|
||||
|
||||
fn main() { }
|
Loading…
Reference in New Issue
Block a user