Skip to content

pretty printer for uints sometimes drops the "u" suffix #1532

Closed
@nikomatsakis

Description

@nikomatsakis

If I run rustc --pretty normal with this input (tag-disr-val-shape.rs):

// xfail-pretty Issue #1510

tag color {
    red = 0xff0000;
    green = 0x00ff00;
    blue = 0x0000ff;
    black = 0x000000;
    white = 0xFFFFFF;
}

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];
}

then the 10us which appear in the asserts become 10. Looking at the code, it's fairly clear that ast_util::uint_ty_to_str() is wrong:

fn uint_ty_to_str(t: uint_ty) -> str {
    alt t {
      ty_u. { "" } ty_u8. { "u8" } ty_u16. { "u16" }
      ty_u32. { "u32" } ty_u64. { "u64" }
    }
}

I was just going to fix this function... but then I found that almost every other example of printing 10u which I have tried works! I cannot for the life of me figure out why. I believe I've even seen the output vary from run to run. So I'm wondering if there is a deeper bug: I've been digging into it but haven't found it yet. I'm getting a bit bored of this bug though and want to get hacking on other things, so I'm filing an issue. Anyhow, maybe someone else has some idea what's going on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-prettyArea: Pretty printing (including `-Z unpretty`)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions