|
| 1 | +// Public enum with #[derive(PartialOrd)] and struct variant with reordered fields - should trigger warning |
| 2 | +#[derive(PartialOrd, PartialEq)] |
| 3 | +pub enum PublicEnum { |
| 4 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 5 | +} |
| 6 | + |
| 7 | +// Private enum with #[derive(PartialOrd)] and struct variant with reordered fields - should not trigger |
| 8 | +#[derive(PartialOrd, PartialEq)] |
| 9 | +enum PrivateEnum { |
| 10 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 11 | +} |
| 12 | + |
| 13 | +// Public enum without #[derive(PartialOrd)] but with struct variant with reordered fields - should not trigger |
| 14 | +pub enum RegularEnum { |
| 15 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 16 | +} |
| 17 | + |
| 18 | +// Public enum with #[derive(PartialOrd)] and doc(hidden) - should not trigger |
| 19 | +#[doc(hidden)] |
| 20 | +#[derive(PartialOrd, PartialEq)] |
| 21 | +pub enum DocHiddenEnum { |
| 22 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 23 | +} |
| 24 | + |
| 25 | +// Public enum with #[derive(PartialOrd)] and doc(hidden) variant - should not trigger |
| 26 | +#[derive(PartialOrd, PartialEq)] |
| 27 | +pub enum EnumWithDocHiddenVariant { |
| 28 | + #[doc(hidden)] |
| 29 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 30 | +} |
| 31 | + |
| 32 | +// Public enum with #[derive(PartialOrd)] and doc(hidden) fields - should not trigger |
| 33 | +#[derive(PartialOrd, PartialEq)] |
| 34 | +pub enum EnumWithDocHiddenFields { |
| 35 | + StructVariant { |
| 36 | + a: u8, |
| 37 | + #[doc(hidden)] |
| 38 | + c: u32, |
| 39 | + #[doc(hidden)] |
| 40 | + b: u16, |
| 41 | + }, |
| 42 | +} |
| 43 | + |
| 44 | +// Public enum with #[derive(PartialOrd)] and same field order - should not trigger |
| 45 | +#[derive(PartialOrd, PartialEq)] |
| 46 | +pub enum UnchangedEnum { |
| 47 | + StructVariant { x: u8, y: u16 }, |
| 48 | +} |
| 49 | + |
| 50 | +// Test with manual PartialOrd implementation - should not trigger |
| 51 | +#[derive(PartialEq)] |
| 52 | +pub enum ManuallyImplemented { |
| 53 | + StructVariant { b: u16, a: u8 }, |
| 54 | +} |
| 55 | + |
| 56 | +impl PartialOrd for ManuallyImplemented { |
| 57 | + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 58 | + todo!() |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// Test with multiple variants - should check each struct variant independently |
| 63 | +#[derive(PartialOrd, PartialEq)] |
| 64 | +pub enum MultipleVariants { |
| 65 | + First { b: u16, a: u8 }, |
| 66 | + Second { y: u64, x: u32 }, |
| 67 | + Third(u16, u8), // tuple variant reordered but should be ignored |
| 68 | + Fourth, // unit variant unchanged |
| 69 | +} |
| 70 | + |
| 71 | +// Test case: Used to derive PartialOrd but no longer does - should not trigger this lint |
| 72 | +#[derive(PartialEq)] |
| 73 | +pub enum NoLongerPartialOrd { |
| 74 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 75 | +} |
| 76 | + |
| 77 | +// Test case: Didn't derive PartialOrd before but now does - should not trigger this lint |
| 78 | +#[derive(PartialOrd, PartialEq)] |
| 79 | +pub enum NewlyPartialOrd { |
| 80 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 81 | +} |
| 82 | + |
| 83 | +// Test case: Switching from derived to hand-implemented PartialOrd - should not trigger this lint |
| 84 | +#[derive(PartialEq)] |
| 85 | +pub enum DerivedToHandImpl { |
| 86 | + StructVariant { b: u16, c: u32, a: u8 }, |
| 87 | +} |
| 88 | + |
| 89 | +impl PartialOrd for DerivedToHandImpl { |
| 90 | + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 91 | + todo!() |
| 92 | + } |
| 93 | +} |
0 commit comments