]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/match_wild_err_arm.rs
7bdd75d7f46396480596c50283877c19653b1cd3
[rustc.git] / src / tools / clippy / tests / ui / match_wild_err_arm.rs
1 #![feature(exclusive_range_pattern)]
2 #![allow(clippy::match_same_arms, dead_code)]
3 #![warn(clippy::match_wild_err_arm)]
4
5 fn issue_10635() {
6 enum Error {
7 A,
8 B,
9 }
10
11 // Don't trigger in const contexts. Const unwrap is not yet stable
12 const X: () = match Ok::<_, Error>(()) {
13 Ok(x) => x,
14 Err(_) => panic!(),
15 };
16 }
17
18 fn match_wild_err_arm() {
19 let x: Result<i32, &str> = Ok(3);
20
21 match x {
22 Ok(3) => println!("ok"),
23 Ok(_) => println!("ok"),
24 Err(_) => panic!("err"),
25 //~^ ERROR: `Err(_)` matches all errors
26 //~| NOTE: match each error separately or use the error output, or use `.expect(ms
27 }
28
29 match x {
30 Ok(3) => println!("ok"),
31 Ok(_) => println!("ok"),
32 Err(_) => panic!(),
33 //~^ ERROR: `Err(_)` matches all errors
34 //~| NOTE: match each error separately or use the error output, or use `.expect(ms
35 }
36
37 match x {
38 Ok(3) => println!("ok"),
39 Ok(_) => println!("ok"),
40 Err(_) => {
41 //~^ ERROR: `Err(_)` matches all errors
42 //~| NOTE: match each error separately or use the error output, or use `.expect(ms
43 panic!();
44 },
45 }
46
47 match x {
48 Ok(3) => println!("ok"),
49 Ok(_) => println!("ok"),
50 Err(_e) => panic!(),
51 //~^ ERROR: `Err(_e)` matches all errors
52 //~| NOTE: match each error separately or use the error output, or use `.expect(ms
53 }
54
55 // Allowed when used in `panic!`.
56 match x {
57 Ok(3) => println!("ok"),
58 Ok(_) => println!("ok"),
59 Err(_e) => panic!("{}", _e),
60 }
61
62 // Allowed when not with `panic!` block.
63 match x {
64 Ok(3) => println!("ok"),
65 Ok(_) => println!("ok"),
66 Err(_) => println!("err"),
67 }
68
69 // Allowed when used with `unreachable!`.
70 match x {
71 Ok(3) => println!("ok"),
72 Ok(_) => println!("ok"),
73 Err(_) => unreachable!(),
74 }
75
76 // Allowed when used with `unreachable!`.
77 match x {
78 Ok(3) => println!("ok"),
79 Ok(_) => println!("ok"),
80 Err(_) => {
81 unreachable!();
82 },
83 }
84 }
85
86 fn main() {}