]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | // run-rustfix |
2 | #![feature(exhaustive_patterns, never_type)] | |
3 | #![allow(dead_code, unreachable_code, unused_variables)] | |
4 | #![allow(clippy::let_and_return)] | |
5 | ||
6 | enum SingleVariantEnum { | |
7 | Variant(i32), | |
8 | } | |
9 | ||
10 | struct TupleStruct(i32); | |
11 | ||
12 | enum EmptyEnum {} | |
13 | ||
14 | macro_rules! match_enum { | |
15 | ($param:expr) => { | |
16 | let data = match $param { | |
17 | SingleVariantEnum::Variant(i) => i, | |
18 | }; | |
19 | }; | |
20 | } | |
21 | ||
22 | fn infallible_destructuring_match_enum() { | |
23 | let wrapper = SingleVariantEnum::Variant(0); | |
24 | ||
25 | // This should lint! | |
26 | let SingleVariantEnum::Variant(data) = wrapper; | |
27 | ||
28 | // This shouldn't (inside macro) | |
29 | match_enum!(wrapper); | |
30 | ||
31 | // This shouldn't! | |
32 | let data = match wrapper { | |
33 | SingleVariantEnum::Variant(_) => -1, | |
34 | }; | |
35 | ||
36 | // Neither should this! | |
37 | let data = match wrapper { | |
38 | SingleVariantEnum::Variant(i) => -1, | |
39 | }; | |
40 | ||
41 | let SingleVariantEnum::Variant(data) = wrapper; | |
42 | } | |
43 | ||
44 | macro_rules! match_struct { | |
45 | ($param:expr) => { | |
46 | let data = match $param { | |
47 | TupleStruct(i) => i, | |
48 | }; | |
49 | }; | |
50 | } | |
51 | ||
52 | fn infallible_destructuring_match_struct() { | |
53 | let wrapper = TupleStruct(0); | |
54 | ||
55 | // This should lint! | |
56 | let TupleStruct(data) = wrapper; | |
57 | ||
58 | // This shouldn't (inside macro) | |
59 | match_struct!(wrapper); | |
60 | ||
61 | // This shouldn't! | |
62 | let data = match wrapper { | |
63 | TupleStruct(_) => -1, | |
64 | }; | |
65 | ||
66 | // Neither should this! | |
67 | let data = match wrapper { | |
68 | TupleStruct(i) => -1, | |
69 | }; | |
70 | ||
71 | let TupleStruct(data) = wrapper; | |
72 | } | |
73 | ||
74 | macro_rules! match_never_enum { | |
75 | ($param:expr) => { | |
76 | let data = match $param { | |
77 | Ok(i) => i, | |
78 | }; | |
79 | }; | |
80 | } | |
81 | ||
82 | fn never_enum() { | |
83 | let wrapper: Result<i32, !> = Ok(23); | |
84 | ||
85 | // This should lint! | |
86 | let Ok(data) = wrapper; | |
87 | ||
88 | // This shouldn't (inside macro) | |
89 | match_never_enum!(wrapper); | |
90 | ||
91 | // This shouldn't! | |
92 | let data = match wrapper { | |
93 | Ok(_) => -1, | |
94 | }; | |
95 | ||
96 | // Neither should this! | |
97 | let data = match wrapper { | |
98 | Ok(i) => -1, | |
99 | }; | |
100 | ||
101 | let Ok(data) = wrapper; | |
102 | } | |
103 | ||
104 | impl EmptyEnum { | |
105 | fn match_on(&self) -> ! { | |
106 | // The lint shouldn't pick this up, as `let` won't work here! | |
107 | let data = match *self {}; | |
108 | data | |
109 | } | |
110 | } | |
111 | ||
112 | fn main() {} |