Closed
Description
Given the following code:
#[derive(Debug)]
pub enum BusinessType {
First,
Second,
Third,
}
fn my_tricky_func(business_type: &BusinessType) {
match &business_type {
First => {
println!("First");
}
Second => {
println!("Second");
}
Third => {
println!("Third");
}
}
}
fn my_ok_func(business_type: &BusinessType) {
match &business_type {
BusinessType::First => {
println!("First");
}
BusinessType::Second => {
println!("Second");
}
BusinessType::Third => {
println!("Third");
}
}
}
fn main() {
println!("\n\n↓↓↓ trying my_tricky_func");
my_tricky_func(&BusinessType::Third);
my_tricky_func(&BusinessType::Second);
my_tricky_func(&BusinessType::First);
println!("\n\n↓↓↓ trying my_ok_func");
my_ok_func(&BusinessType::Third);
my_ok_func(&BusinessType::Second);
my_ok_func(&BusinessType::First);
}
The current output is:
Compiling playground v0.0.1 (/playground)
warning[[E0170]](https://doc.rust-lang.org/stable/error-index.html#E0170): pattern binding `First` is named the same as one of the variants of the type `BusinessType`
--> src/main.rs:10:9
|
10 | First => {
| ^^^^^ help: to match on the variant, qualify the path: `BusinessType::First`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
warning[[E0170]](https://doc.rust-lang.org/stable/error-index.html#E0170): pattern binding `Second` is named the same as one of the variants of the type `BusinessType`
--> src/main.rs:13:9
|
13 | Second => {
| ^^^^^^ help: to match on the variant, qualify the path: `BusinessType::Second`
warning[[E0170]](https://doc.rust-lang.org/stable/error-index.html#E0170): pattern binding `Third` is named the same as one of the variants of the type `BusinessType`
--> src/main.rs:16:9
|
16 | Third => {
| ^^^^^ help: to match on the variant, qualify the path: `BusinessType::Third`
warning: unreachable pattern
--> src/main.rs:13:9
|
10 | First => {
| ----- matches any value
...
13 | Second => {
| ^^^^^^ unreachable pattern
|
= note: `#[warn(unreachable_patterns)]` on by default
warning: unreachable pattern
--> src/main.rs:16:9
|
10 | First => {
| ----- matches any value
...
16 | Third => {
| ^^^^^ unreachable pattern
warning: unused variable: `First`
--> src/main.rs:10:9
|
10 | First => {
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_First`
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `Second`
--> src/main.rs:13:9
|
13 | Second => {
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Second`
warning: unused variable: `Third`
--> src/main.rs:16:9
|
16 | Third => {
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_Third`
warning: variable `First` should have a snake case name
--> src/main.rs:10:9
|
10 | First => {
| ^^^^^ help: convert the identifier to snake case (notice the capitalization): `first`
|
= note: `#[warn(non_snake_case)]` on by default
warning: variable `Second` should have a snake case name
--> src/main.rs:13:9
|
13 | Second => {
| ^^^^^^ help: convert the identifier to snake case (notice the capitalization): `second`
warning: variable `Third` should have a snake case name
--> src/main.rs:16:9
|
16 | Third => {
| ^^^^^ help: convert the identifier to snake case: `third`
For more information about this error, try `rustc --explain E0170`.
warning: `playground` (bin "playground") generated 11 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.60s
Running `target/debug/playground`
Standard Output
↓↓↓ trying my_tricky_func
First
First
First
↓↓↓ trying my_ok_func
Third
Second
First
Ideally the output should look like:
Compiling playground v0.0.1 (/playground)
error: should be like this:`BusinessType::First`
--> src/main.rs:10:9
|
10 | First => {
| ^^^^^ help: to match on the variant, qualify the path: `BusinessType::First`
|
= note: `#[warn(bindings_with_variant_name)]` on by default