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