]> git.lizzy.rs Git - rust.git/blob - tests/ui/infallible_destructuring_match.rs
Merge pull request #3085 from mikerite/revert-98dbce
[rust.git] / tests / ui / infallible_destructuring_match.rs
1 #![feature(tool_lints)]
2
3 #![feature(exhaustive_patterns, never_type)]
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 fn infallible_destructuring_match_enum() {
15     let wrapper = SingleVariantEnum::Variant(0);
16
17     // This should lint!
18     let data = match wrapper {
19         SingleVariantEnum::Variant(i) => i,
20     };
21
22     // This shouldn't!
23     let data = match wrapper {
24         SingleVariantEnum::Variant(_) => -1,
25     };
26
27     // Neither should this!
28     let data = match wrapper {
29         SingleVariantEnum::Variant(i) => -1,
30     };
31
32     let SingleVariantEnum::Variant(data) = wrapper;
33 }
34
35 fn infallible_destructuring_match_struct() {
36     let wrapper = TupleStruct(0);
37
38     // This should lint!
39     let data = match wrapper {
40         TupleStruct(i) => i,
41     };
42
43     // This shouldn't!
44     let data = match wrapper {
45         TupleStruct(_) => -1,
46     };
47
48     // Neither should this!
49     let data = match wrapper {
50         TupleStruct(i) => -1,
51     };
52
53     let TupleStruct(data) = wrapper;
54 }
55
56 fn never_enum() {
57     let wrapper: Result<i32, !> = Ok(23);
58
59     // This should lint!
60     let data = match wrapper {
61         Ok(i) => i,
62     };
63
64     // This shouldn't!
65     let data = match wrapper {
66         Ok(_) => -1,
67     };
68
69     // Neither should this!
70     let data = match wrapper {
71         Ok(i) => -1,
72     };
73
74     let Ok(data) = wrapper;
75 }
76
77 impl EmptyEnum {
78     fn match_on(&self) -> ! {
79         // The lint shouldn't pick this up, as `let` won't work here!
80         let data = match *self {};
81         data
82     }
83 }
84
85 fn main() {}