]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/infallible_destructuring_match.rs
1 #![feature(exhaustive_patterns, never_type)]
2 #![allow(dead_code, unreachable_code, unused_variables)]
3 #![allow(clippy::let_and_return)]
5 enum SingleVariantEnum
{
9 struct TupleStruct(i32);
12 struct TupleStructWithNonCopy(NonCopy
);
16 macro_rules
! match_enum
{
18 let data
= match $param
{
19 SingleVariantEnum
::Variant(i
) => i
,
24 fn infallible_destructuring_match_enum() {
25 let wrapper
= SingleVariantEnum
::Variant(0);
28 let data
= match wrapper
{
29 SingleVariantEnum
::Variant(i
) => i
,
32 // This shouldn't (inside macro)
36 let data
= match wrapper
{
37 SingleVariantEnum
::Variant(_
) => -1,
40 // Neither should this!
41 let data
= match wrapper
{
42 SingleVariantEnum
::Variant(i
) => -1,
45 let SingleVariantEnum
::Variant(data
) = wrapper
;
48 macro_rules
! match_struct
{
50 let data
= match $param
{
56 fn infallible_destructuring_match_struct() {
57 let wrapper
= TupleStruct(0);
60 let data
= match wrapper
{
64 // This shouldn't (inside macro)
65 match_struct
!(wrapper
);
68 let data
= match wrapper
{
72 // Neither should this!
73 let data
= match wrapper
{
77 let TupleStruct(data
) = wrapper
;
80 fn infallible_destructuring_match_struct_with_noncopy() {
81 let wrapper
= TupleStructWithNonCopy(NonCopy
);
83 // This should lint! (keeping `ref` in the suggestion)
84 let data
= match wrapper
{
85 TupleStructWithNonCopy(ref n
) => n
,
88 let TupleStructWithNonCopy(ref data
) = wrapper
;
91 macro_rules
! match_never_enum
{
93 let data
= match $param
{
100 let wrapper
: Result
<i32, !> = Ok(23);
103 let data
= match wrapper
{
107 // This shouldn't (inside macro)
108 match_never_enum
!(wrapper
);
111 let data
= match wrapper
{
115 // Neither should this!
116 let data
= match wrapper
{
120 let Ok(data
) = wrapper
;
124 fn match_on(&self) -> ! {
125 // The lint shouldn't pick this up, as `let` won't work here!
126 let data
= match *self {}
;