1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#![warn(clippy::empty_enum_variants_with_brackets)]
#![allow(dead_code)]
pub enum PublicTestEnum {
NonEmptyBraces { x: i32, y: i32 }, // No error
NonEmptyParentheses(i32, i32), // No error
EmptyBraces,
//~^ empty_enum_variants_with_brackets
EmptyParentheses(), // No error as enum is pub
}
enum TestEnum {
NonEmptyBraces { x: i32, y: i32 }, // No error
NonEmptyParentheses(i32, i32), // No error
EmptyBraces,
//~^ empty_enum_variants_with_brackets
EmptyParentheses,
//~^ empty_enum_variants_with_brackets
AnotherEnum, // No error
}
mod issue12551 {
enum EvenOdd {
// Used as functions -> no error
Even(),
Odd(),
// Not used as a function
Unknown,
//~^ empty_enum_variants_with_brackets
}
fn even_odd(x: i32) -> EvenOdd {
(x % 2 == 0).then(EvenOdd::Even).unwrap_or_else(EvenOdd::Odd)
}
fn natural_number(x: i32) -> NaturalOrNot {
(x > 0)
.then(NaturalOrNot::Natural)
.unwrap_or_else(NaturalOrNot::NotNatural)
}
enum NaturalOrNot {
// Used as functions -> no error
Natural(),
NotNatural(),
// Not used as a function
Unknown,
//~^ empty_enum_variants_with_brackets
}
enum RedundantParenthesesFunctionCall {
// Used as a function call but with redundant parentheses
Parentheses,
//~^ empty_enum_variants_with_brackets
// Not used as a function
NoParentheses,
}
#[allow(clippy::no_effect)]
fn redundant_parentheses_function_call() {
// The parentheses in the below line are redundant.
RedundantParenthesesFunctionCall::Parentheses;
RedundantParenthesesFunctionCall::NoParentheses;
}
// Same test as above but with usage of the enum occurring before the definition.
#[allow(clippy::no_effect)]
fn redundant_parentheses_function_call_2() {
// The parentheses in the below line are redundant.
RedundantParenthesesFunctionCall2::Parentheses;
RedundantParenthesesFunctionCall2::NoParentheses;
}
enum RedundantParenthesesFunctionCall2 {
// Used as a function call but with redundant parentheses
Parentheses,
//~^ empty_enum_variants_with_brackets
// Not used as a function
NoParentheses,
}
}
enum TestEnumWithFeatures {
NonEmptyBraces {
#[cfg(feature = "thisisneverenabled")]
x: i32,
}, // No error
NonEmptyParentheses(#[cfg(feature = "thisisneverenabled")] i32), // No error
}
#[derive(Clone)]
enum Foo {
Variant1(i32),
Variant2,
Variant3, //~ ERROR: enum variant has empty brackets
}
#[derive(Clone)]
pub enum PubFoo {
Variant1(i32),
Variant2,
Variant3(),
}
fn main() {}
|