-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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?
Metadata
Metadata
Assignees
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.