Closed
Description
In the section about integer literals, the Reference says:
Note that the Rust syntax considers
-1i8
as an application of the unary minus operator to an integer literal1i8
, rather than a single integer literal.
However, this is a bit misleading due to the way Rust handles literals that are "out of range": values like -128i8
actually work (due to const eval?). AFAIK you can use any integer literal in the range [0, 2^128)
as long as it evaluates to something in range, but either way things get a bit weird. For example:
fn main() {
println!("{}", -128i8); // prints -128
println!("{}", -(128i8)); // prints -128
// println!("{}", -(126i8 + 2)); // error: attempt to add with overflow
// let x = 128i8; // error: literal out of range for `i8`
}
Metadata
Metadata
Assignees
Labels
No labels