Skip to content

error: only u8 can be cast as char, not u8 #9918

Closed
@sp3d

Description

@sp3d

Running rustc 0.9-pre 9d6c251 on x86_64 linux, the following code

fn main()
{
    let a = 0u8; let b = 1 * a; b as char;
}

gives the highly confusing error:

u8.rs:3:29: 3:38 error: only `u8` can be cast as `char`, not `u8`
u8.rs:3     let a = 0u8; let b = 1 * a; b as char;
                                        ^~~~~~~~~
error: aborting due to previous error
task '<unnamed>' failed at 'explicit failure', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:98
task '<unnamed>' failed at 'explicit failure', /build/rust-git/src/rust/src/librustc/rustc.rs:391

This can be avoided by removing the "* 1", annotating b as a u8, or annotating the 1 as u8, but presumably should be perfectly valid as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions