Skip to content

C-like tags should be castable to int with or without custom discriminants #1511

Closed
@nikomatsakis

Description

@nikomatsakis

This type checks (tag-disr-val-shape.rs):

enum color {
    red = 0;
    green = 1;
    blue = 2;
    black = 3;
    white = 4;
}

fn main() {
    assert uint::to_str(red as uint, 10u) == #fmt["%?", red];
    assert uint::to_str(green as uint, 10u) == #fmt["%?", green];
    assert uint::to_str(white as uint, 10u) == #fmt["%?", white];
}

but this does not (tag-auto-disr-val-shape.rs):

enum color { red; green; blue; black; white; }

fn main() {
    assert (uint::to_str(red as uint, 10) == #fmt["%?", red]);
    assert (uint::to_str(green as uint, 10) == #fmt["%?", green]);
    assert (uint::to_str(white as uint, 10) == #fmt["%?", white]);
}

However, the two programs are equivalent but for the fact that in one case the discriminants were automatically assigned.

When fixing this bug, please remove the xfail-test directives from those two test files!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions