]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/match_same_arms.rs
Add 'src/tools/clippy/' from commit 'd2708873ef711ec8ab45df1e984ecf24a96cd369'
[rust.git] / src / tools / clippy / tests / ui / match_same_arms.rs
1 #![warn(clippy::match_same_arms)]
2
3 pub enum Abc {
4     A,
5     B,
6     C,
7 }
8
9 fn match_same_arms() {
10     let _ = match Abc::A {
11         Abc::A => 0,
12         Abc::B => 1,
13         _ => 0, //~ ERROR match arms have same body
14     };
15
16     match (1, 2, 3) {
17         (1, .., 3) => 42,
18         (.., 3) => 42, //~ ERROR match arms have same body
19         _ => 0,
20     };
21
22     let _ = match 42 {
23         42 => 1,
24         51 => 1, //~ ERROR match arms have same body
25         41 => 2,
26         52 => 2, //~ ERROR match arms have same body
27         _ => 0,
28     };
29
30     let _ = match 42 {
31         1 => 2,
32         2 => 2, //~ ERROR 2nd matched arms have same body
33         3 => 2, //~ ERROR 3rd matched arms have same body
34         4 => 3,
35         _ => 0,
36     };
37 }
38
39 mod issue4244 {
40     #[derive(PartialEq, PartialOrd, Eq, Ord)]
41     pub enum CommandInfo {
42         BuiltIn { name: String, about: Option<String> },
43         External { name: String, path: std::path::PathBuf },
44     }
45
46     impl CommandInfo {
47         pub fn name(&self) -> String {
48             match self {
49                 CommandInfo::BuiltIn { name, .. } => name.to_string(),
50                 CommandInfo::External { name, .. } => name.to_string(),
51             }
52         }
53     }
54 }
55
56 fn main() {}