Merge pull request #1544 from kevina/issue-1393
Minor cleanups to custom discriminator code.
This commit is contained in:
commit
711fc20d88
@ -103,9 +103,9 @@ equivalent to a C enum:
|
||||
This will define `north`, `east`, `south`, and `west` as constants,
|
||||
all of which have type `direction`.
|
||||
|
||||
When the enum is is C like, that is none of the variants have
|
||||
parameters, it is possible to explicit set the discriminator values to
|
||||
an integer value:
|
||||
When the enum is C like, that is none of the variants have parameters,
|
||||
it is possible to explicitly set the discriminator values to an integer
|
||||
value:
|
||||
|
||||
enum color {
|
||||
red = 0xff0000;
|
||||
|
@ -2645,8 +2645,8 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
|
||||
@csearch::get_tag_variants(cx, id)
|
||||
} else {
|
||||
// FIXME: Now that the variants are run through the type checker (to
|
||||
// check the disr_expr if one exists), this code should likely be
|
||||
// moved there to avoid having to call eval_const_expr twice
|
||||
// check the disr_expr if it exists), this code should likely be
|
||||
// moved there to avoid having to call eval_const_expr twice.
|
||||
alt cx.items.get(id.node) {
|
||||
ast_map::node_item(@{node: ast::item_tag(variants, _), _}) {
|
||||
let disr_val = -1;
|
||||
|
@ -2489,8 +2489,8 @@ fn check_tag_variants(ccx: @crate_ctxt, _sp: span, vs: [ast::variant],
|
||||
demand::simple(fcx, e.span, declty, cty);
|
||||
// FIXME: issue #1417
|
||||
// Also, check_expr (from check_const pass) doesn't guarantee that
|
||||
// the expression in an form that eval_const_expr, so we may still
|
||||
// get an internal compiler error
|
||||
// the expression in an form that eval_const_expr can handle, so
|
||||
// we may still get an internal compiler error.
|
||||
alt syntax::ast_util::eval_const_expr(e) {
|
||||
syntax::ast_util::const_int(val) {
|
||||
disr_val = val as int;
|
||||
|
@ -9,7 +9,7 @@ fn main() {
|
||||
test_color(imaginary, -1, "imaginary");
|
||||
}
|
||||
|
||||
fn test_color(color: color, val: int, name: str) unsafe{
|
||||
fn test_color(color: color, val: int, name: str) {
|
||||
assert (color as int == val);
|
||||
assert (color as float == val as float);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user