Closed
Description
Hi all
Following code produces always the same output in console and emits
warning: unreachable pattern
--> src/main.rs:31:5
|
31 | plus => println!("plus"),
| ^^^^ this is an unreachable pattern
|
= note: #[warn(unreachable_patterns)] on by default
note: this pattern matches any value
... in compilation.
type
TFunc = fn (i64,i64)->i64;
fn plus(a:i64, b:i64)->i64 {
a+b
}
fn minus(a:i64, b:i64)->i64 {
a-b
}
fn other(a:i64, b:i64)->i64 {
0
}
fn test(c:i64) -> TFunc {
match c {
0 => plus,
1 => minus,
_ => other
}
}
extern crate rand;
use rand::Rng;
fn main() {
let mut rng = rand::thread_rng();
for i in 0..10 {
match test( rng.gen() ) {
minus => println!("minus"),
plus => println!("plus"),
_ => println!("other"),
}
}
}
Tested in Rust playground in nightly.
Any comments?