We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Long story short. When trying to use the ::MAX properties of sized integers and converting them to usize, they get the wrong value. Like so:
let a: [u8; 255] = [0; core::u8::MAX as usize]; 14:54 error: mismatched types: expected [u8; 255], found [u8; 18446744073709551615]
[u8; 255]
[u8; 18446744073709551615]
https://play.rust-lang.org/?code=%23![feature%28asm,+simd,+thread_local,+unsafe_destructor%29]%0A%23![feature%28core,+libc,+collections,+std_misc,+io,+path%29]%0A%23![allow%28dead_code,+unused_variables%29]%0A%23![allow%28unused_features%29]%0A%0Aextern+crate+libc;%0A%0Astatic+VERSION:+%26%27static+str+%3D+%22rustc+1.0.0-nightly+%28ba2f13ef0+2015-02-04+20:03:55+%2B0000%29%22;%0A%0Afn+show%3CT:+std::fmt::Debug%3E%28e:+T%29+{+println!%28%22{:%3F}%22,+e%29+}%0A%0Afn+main%28%29+{%0A++++show%28{%0A++++++++let+a:+[u8;+255]+%3D+[0;+std::u8::MAX+as+usize];%0A++++}%29;%0A}&run=1
The text was updated successfully, but these errors were encountered:
Probably a consequence of the fact that these are consts and defined thusly:
pub const MIN: $T = 0 as $T; pub const MAX: $T = 0 as $T - 1 as $T;
Sorry, something went wrong.
Noting that u8::MAX as usize works fine in other places, just not in array decelerations. e.g. println!("{}", u8::MAX as usize); works as expected.
u8::MAX as usize
println!("{}", u8::MAX as usize);
dup of #13768
Thanks @mitaa!
No branches or pull requests
Long story short. When trying to use the ::MAX properties of sized integers and converting them to usize, they get the wrong value. Like so:
let a: [u8; 255] = [0; core::u8::MAX as usize];
14:54 error: mismatched types:
expected
[u8; 255]
,found
[u8; 18446744073709551615]
https://play.rust-lang.org/?code=%23![feature%28asm,+simd,+thread_local,+unsafe_destructor%29]%0A%23![feature%28core,+libc,+collections,+std_misc,+io,+path%29]%0A%23![allow%28dead_code,+unused_variables%29]%0A%23![allow%28unused_features%29]%0A%0Aextern+crate+libc;%0A%0Astatic+VERSION:+%26%27static+str+%3D+%22rustc+1.0.0-nightly+%28ba2f13ef0+2015-02-04+20:03:55+%2B0000%29%22;%0A%0Afn+show%3CT:+std::fmt::Debug%3E%28e:+T%29+{+println!%28%22{:%3F}%22,+e%29+}%0A%0Afn+main%28%29+{%0A++++show%28{%0A++++++++let+a:+[u8;+255]+%3D+[0;+std::u8::MAX+as+usize];%0A++++}%29;%0A}&run=1
The text was updated successfully, but these errors were encountered: