Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sp3d opened this issue Oct 18, 2013 · 0 comments
Closed

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

sp3d opened this issue Oct 18, 2013 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@sp3d
Copy link
Contributor

sp3d commented Oct 18, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants