|
| 1 | +// Public enum with #[derive(PartialOrd)] and reordered variants - should trigger warning |
| 2 | +#[derive(PartialOrd, PartialEq)] |
| 3 | +pub enum PublicEnum { |
| 4 | + B, |
| 5 | + C, |
| 6 | + A, |
| 7 | +} |
| 8 | + |
| 9 | +// Private enum with #[derive(PartialOrd)] and reordered variants - should not trigger |
| 10 | +#[derive(PartialOrd, PartialEq)] |
| 11 | +enum PrivateEnum { |
| 12 | + B, |
| 13 | + C, |
| 14 | + A, |
| 15 | +} |
| 16 | + |
| 17 | +// Public enum without #[derive(PartialOrd)] but with reordered variants - should not trigger |
| 18 | +pub enum RegularEnum { |
| 19 | + B, |
| 20 | + C, |
| 21 | + A, |
| 22 | +} |
| 23 | + |
| 24 | +// Public enum with #[derive(PartialOrd)] and doc(hidden) - should not trigger |
| 25 | +#[doc(hidden)] |
| 26 | +#[derive(PartialOrd, PartialEq)] |
| 27 | +pub enum DocHiddenEnum { |
| 28 | + B, |
| 29 | + C, |
| 30 | + A, |
| 31 | +} |
| 32 | + |
| 33 | +// Public enum with #[derive(PartialOrd)] and doc(hidden) variants - should not trigger |
| 34 | +#[derive(PartialOrd, PartialEq)] |
| 35 | +pub enum EnumWithDocHiddenVariants { |
| 36 | + A, |
| 37 | + #[doc(hidden)] |
| 38 | + C, |
| 39 | + #[doc(hidden)] |
| 40 | + B, |
| 41 | + D, |
| 42 | +} |
| 43 | + |
| 44 | +// Public enum with #[derive(PartialOrd)] and same order - should not trigger |
| 45 | +#[derive(PartialOrd, PartialEq)] |
| 46 | +pub enum UnchangedEnum { |
| 47 | + X, |
| 48 | + Y, |
| 49 | +} |
| 50 | + |
| 51 | +// Test with manual PartialOrd implementation - should not trigger |
| 52 | +#[derive(PartialEq)] |
| 53 | +pub enum ManuallyImplemented { |
| 54 | + B, |
| 55 | + A, |
| 56 | +} |
| 57 | + |
| 58 | +impl PartialOrd for ManuallyImplemented { |
| 59 | + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 60 | + match (self, other) { |
| 61 | + (Self::A, Self::A) => Some(std::cmp::Ordering::Equal), |
| 62 | + (Self::A, Self::B) => Some(std::cmp::Ordering::Less), |
| 63 | + (Self::B, Self::A) => Some(std::cmp::Ordering::Greater), |
| 64 | + (Self::B, Self::B) => Some(std::cmp::Ordering::Equal), |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// Test with multiple derives including PartialOrd - should trigger |
| 70 | +#[derive(Debug, PartialOrd, Clone, PartialEq)] |
| 71 | +pub enum MultipleDerivesWithPartialOrd { |
| 72 | + B, |
| 73 | + C, |
| 74 | + A, |
| 75 | +} |
| 76 | + |
| 77 | +// Test with mixed variant types - should trigger |
| 78 | +#[derive(PartialOrd, PartialEq)] |
| 79 | +pub enum MixedVariantTypes { |
| 80 | + Tuple(i32, String), |
| 81 | + Struct { x: i32, y: String }, |
| 82 | + Unit, |
| 83 | +} |
| 84 | + |
| 85 | +// Test with struct variants - should trigger |
| 86 | +#[derive(PartialOrd, PartialEq)] |
| 87 | +pub enum StructVariants { |
| 88 | + B { y: String }, |
| 89 | + C { z: bool }, |
| 90 | + A { x: i32 }, |
| 91 | +} |
| 92 | + |
| 93 | +// Test with tuple variants - should trigger |
| 94 | +#[derive(PartialOrd, PartialEq)] |
| 95 | +pub enum TupleVariants { |
| 96 | + B(String), |
| 97 | + C(bool), |
| 98 | + A(i32), |
| 99 | +} |
| 100 | + |
| 101 | +// Test with discriminants - should trigger |
| 102 | +#[derive(PartialOrd, PartialEq)] |
| 103 | +pub enum WithDiscriminants { |
| 104 | + B = 20, |
| 105 | + C = 30, |
| 106 | + A = 10, |
| 107 | +} |
| 108 | + |
| 109 | +// Test case: Used to derive PartialOrd but no longer does - should not trigger this lint |
| 110 | +#[derive(PartialEq)] |
| 111 | +pub enum NoLongerPartialOrd { |
| 112 | + B, |
| 113 | + C, |
| 114 | + A, |
| 115 | +} |
| 116 | + |
| 117 | +// Test case: Didn't derive PartialOrd before but now does - should not trigger this lint |
| 118 | +#[derive(PartialOrd, PartialEq)] |
| 119 | +pub enum NewlyPartialOrd { |
| 120 | + B, |
| 121 | + C, |
| 122 | + A, |
| 123 | +} |
| 124 | + |
| 125 | +// Test case: Switching from derived to hand-implemented PartialOrd - should not trigger this lint |
| 126 | +#[derive(PartialEq)] |
| 127 | +pub enum DerivedToHandImpl { |
| 128 | + B, |
| 129 | + C, |
| 130 | + A, |
| 131 | +} |
| 132 | + |
| 133 | +impl PartialOrd for DerivedToHandImpl { |
| 134 | + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 135 | + todo!() |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +// Test case: Switching from hand-implemented to derived PartialOrd - should not trigger this lint |
| 140 | +#[derive(PartialOrd, PartialEq)] |
| 141 | +pub enum HandImplToDerived { |
| 142 | + B, |
| 143 | + C, |
| 144 | + A, |
| 145 | +} |
0 commit comments