Skip to content

Commit

Permalink
Removed dead structures after changes to PartialOrd/Ord derivings.
Browse files Browse the repository at this point in the history
Remove the `NonMatchesExplode` variant now that no deriving impl uses it.
Removed `EnumNonMatching` entirely.
Remove now irrelevant `on_matching` field and `HandleNonMatchingEnums` type.
Removed unused `EnumNonMatchFunc` type def.

Drive-by: revise `EnumNonMatchCollapsedFunc` doc.

Made all calls to `expand_enum_method_body` go directly to
`build_enum_match_tuple`.

Alpha-rename `enum_nonmatch_g` back to `enum_nonmatch_f` to reduce overall diff noise.
Inline sole call of `some_ordering_const`.
Inline sole call of `ordering_const`.

Removed a bunch of code that became dead after the above changes.
  • Loading branch information
pnkfelix committed Jul 11, 2014
1 parent c8ae446 commit 5cee578
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 352 deletions.
3 changes: 1 addition & 2 deletions src/libsyntax/ext/deriving/clone.rs
Expand Up @@ -39,7 +39,6 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
args: Vec::new(),
ret_ty: Self,
attributes: attrs,
on_nonmatching: NonMatchHandlingIrrelevant,
combine_substructure: combine_substructure(|c, s, sub| {
cs_clone("Clone", c, s, sub)
}),
Expand Down Expand Up @@ -69,7 +68,7 @@ fn cs_clone(
ctor_ident = variant.node.name;
all_fields = af;
},
EnumNonMatching(..) | EnumNonMatchingCollapsed (..) => {
EnumNonMatchingCollapsed (..) => {
cx.span_bug(trait_span,
format!("non-matching enum variants in \
`deriving({})`",
Expand Down
5 changes: 1 addition & 4 deletions src/libsyntax/ext/deriving/cmp/eq.rs
Expand Up @@ -27,12 +27,10 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
// any fields are not equal or if the enum variants are different
fn cs_eq(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> Gc<Expr> {
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr)
cx, span, substr)
}
fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> Gc<Expr> {
cs_or(|cx, span, _, _| cx.expr_bool(span, true),
|cx, span, _, _| cx.expr_bool(span, true),
cx, span, substr)
}

Expand All @@ -47,7 +45,6 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
attributes: attrs,
on_nonmatching: NonMatchesCollapse,
combine_substructure: combine_substructure(|a, b, c| {
$f(a, b, c)
})
Expand Down
47 changes: 6 additions & 41 deletions src/libsyntax/ext/deriving/cmp/ord.rs
Expand Up @@ -35,7 +35,6 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
attributes: attrs,
on_nonmatching: NonMatchesCollapseWithTags,
combine_substructure: combine_substructure(|cx, span, substr| {
cs_op($op, $equal, cx, span, substr)
})
Expand All @@ -59,7 +58,6 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
args: vec![borrowed_self()],
ret_ty: ret_ty,
attributes: attrs,
on_nonmatching: NonMatchesCollapseWithTags,
combine_substructure: combine_substructure(|cx, span, substr| {
cs_partial_cmp(cx, span, substr)
})
Expand All @@ -82,20 +80,6 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
trait_def.expand(cx, mitem, item, push)
}

pub fn some_ordering_const(cx: &mut ExtCtxt, span: Span, cnst: Ordering) -> Gc<ast::Expr> {
let cnst = match cnst {
Less => "Less",
Equal => "Equal",
Greater => "Greater"
};
let ordering = cx.path_global(span,
vec!(cx.ident_of("std"),
cx.ident_of("cmp"),
cx.ident_of(cnst)));
let ordering = cx.expr_path(ordering);
cx.expr_some(span, ordering)
}

pub enum OrderingOp {
PartialCmpOp, LtOp, LeOp, GtOp, GeOp,
}
Expand All @@ -117,7 +101,12 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
substr: &Substructure) -> Gc<Expr> {
let test_id = cx.ident_of("__test");
let equals_expr = some_ordering_const(cx, span, Equal);
let ordering = cx.path_global(span,
vec!(cx.ident_of("std"),
cx.ident_of("cmp"),
cx.ident_of("Equal")));
let ordering = cx.expr_path(ordering);
let equals_expr = cx.expr_some(span, ordering);

/*
Builds:
Expand Down Expand Up @@ -159,15 +148,6 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
},
equals_expr.clone(),
|cx, span, list, _| {
match list {
// an earlier nonmatching variant is Less than a
// later one.
[(self_var, _, _), (other_var, _, _)] =>
some_ordering_const(cx, span, self_var.cmp(&other_var)),
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`"),
}
},
|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
Expand Down Expand Up @@ -216,21 +196,6 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, span: Span,
cx.expr_binary(span, ast::BiOr, cmp, and)
},
cx.expr_bool(span, equal),
|cx, span, args, _| {
// nonmatching enums, order by the order the variants are
// written
match args {
[(self_var, _, _),
(other_var, _, _)] =>
cx.expr_bool(span,
if less {
self_var < other_var
} else {
self_var > other_var
}),
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
}
},
|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax/ext/deriving/cmp/totaleq.rs
Expand Up @@ -32,7 +32,6 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
let block = cx.block(span, stmts, None);
cx.expr_block(block)
},
|cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"),
|cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"),
cx,
span,
Expand All @@ -58,7 +57,6 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
args: vec!(),
ret_ty: nil_ty(),
attributes: attrs,
on_nonmatching: NonMatchesCollapse,
combine_substructure: combine_substructure(|a, b, c| {
cs_total_eq_assert(a, b, c)
})
Expand Down
31 changes: 4 additions & 27 deletions src/libsyntax/ext/deriving/cmp/totalord.rs
Expand Up @@ -17,7 +17,6 @@ use ext::deriving::generic::*;
use ext::deriving::generic::ty::*;
use parse::token::InternedString;

use std::cmp::{Ordering, Equal, Less, Greater};
use std::gc::Gc;

pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
Expand All @@ -41,7 +40,6 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
attributes: attrs,
on_nonmatching: NonMatchesCollapseWithTags,
combine_substructure: combine_substructure(|a, b, c| {
cs_cmp(a, b, c)
}),
Expand All @@ -53,18 +51,6 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
}


pub fn ordering_const(cx: &mut ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
let cnst = match cnst {
Less => "Less",
Equal => "Equal",
Greater => "Greater"
};
cx.path_global(span,
vec!(cx.ident_of("std"),
cx.ident_of("cmp"),
cx.ident_of(cnst)))
}

pub fn ordering_collapsed(cx: &mut ExtCtxt,
span: Span,
self_arg_tags: &[ast::Ident]) -> Gc<ast::Expr> {
Expand All @@ -76,7 +62,10 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt,
pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
substr: &Substructure) -> Gc<Expr> {
let test_id = cx.ident_of("__test");
let equals_path = ordering_const(cx, span, Equal);
let equals_path = cx.path_global(span,
vec!(cx.ident_of("std"),
cx.ident_of("cmp"),
cx.ident_of("Equal")));

/*
Builds:
Expand Down Expand Up @@ -118,18 +107,6 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
},
cx.expr_path(equals_path.clone()),
|cx, span, list, _| {
match list {
// an earlier nonmatching variant is Less than a
// later one.
[(self_var, _, _),
(other_var, _, _)] => {
let order = ordering_const(cx, span, self_var.cmp(&other_var));
cx.expr_path(order)
}
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
}
},
|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `deriving(TotalOrd)`")
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/deriving/decodable.rs
Expand Up @@ -54,7 +54,6 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
vec!(box Self,
box Literal(Path::new_local("__E"))), true)),
attributes: Vec::new(),
on_nonmatching: NonMatchHandlingIrrelevant,
combine_substructure: combine_substructure(|a, b, c| {
decodable_substructure(a, b, c)
}),
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/deriving/default.rs
Expand Up @@ -39,7 +39,6 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
args: Vec::new(),
ret_ty: Self,
attributes: attrs,
on_nonmatching: NonMatchHandlingIrrelevant,
combine_substructure: combine_substructure(|a, b, c| {
default_substructure(a, b, c)
})
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/deriving/encodable.rs
Expand Up @@ -121,7 +121,6 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
box Literal(Path::new_local("__E"))),
true)),
attributes: Vec::new(),
on_nonmatching: NonMatchHandlingIrrelevant,
combine_substructure: combine_substructure(|a, b, c| {
encodable_substructure(a, b, c)
}),
Expand Down

5 comments on commit 5cee578

@bors
Copy link
Contributor

@bors bors commented on 5cee578 Jul 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at pnkfelix@5cee578

@bors
Copy link
Contributor

@bors bors commented on 5cee578 Jul 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pnkfelix/rust/fsk-linear-deriving-partialord = 5cee578 into auto

@bors
Copy link
Contributor

@bors bors commented on 5cee578 Jul 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnkfelix/rust/fsk-linear-deriving-partialord = 5cee578 merged ok, testing candidate = aeab250

@bors
Copy link
Contributor

@bors bors commented on 5cee578 Jul 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = aeab250

Please sign in to comment.