-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Description
This leads to somewhat confusing results (see this SO question). Example code:
fn main() {
let pair = (2953495866u, -2953495866);
println!("Tell me about {}", pair);
match pair {
(x, y) if x == y => println!("These are twins"),
(x, y) if x + y == 0 => println!("Antimatter, kaboom!"),
(x, _) if x % 2 == 1 => println!("The first one is odd"),
_ => println!("No correlation..."),
}
}
Prints
Tell me about (2953495866, 18446744070756055750)
Antimatter, kaboom!
No compiler output is produced.
However, when u
is added to the second literal:
fn main() {
let pair = (2953495866u, -2953495866u);
println!("Tell me about {}", pair);
match pair {
(x, y) if x == y => println!("These are twins"),
(x, y) if x + y == 0 => println!("Antimatter, kaboom!"),
(x, _) if x % 2 == 1 => println!("The first one is odd"),
_ => println!("No correlation..."),
}
}
A warning is printed by the compiler:
<anon>:3:30: 3:42 warning: negation of unsigned int literal may be unintentional, #[warn(unsigned_negate)] on by default
<anon>:3 let pair = (2953495866u, -2953495866u);
^~~~~~~~~~~~
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.