Closed
Description
Per this comment on the tracking issue for disallowing the use of constants set to floating point numbers (which errors as expected today), @nikomatsakis says the intention was to disallow floating point literal values in matches, but uh... this is totally accepted by Rust 1.16.0:
fn main() {
let x = 13.4;
match x {
1.0 => println!("one"),
22.4 => println!("two"),
3.67 => println!("three"),
13.4 => println!("thirteen point four"),
_ => println!("anything"),
}
}
This prints "thirteen point four". I expected to get a compiler error like the one I get if I change a floating point value in the match to a constant:
const FOO: f64 = 3.67;
fn main() {
let x = 13.4;
match x {
1.0 => println!("one"),
22.4 => println!("two"),
FOO => println!("three"),
13.4 => println!("thirteen point four"),
_ => println!("anything"),
}
}
results in:
error: floating point constants cannot be used in patterns, #[deny(illegal_floating_point_constant_pattern)] on by default
--> src/main.rs:9:9
|
9 | FOO => println!("three"),
| ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36890 <https://github.com/rust-lang/rust/issues/36890>