sea-orm
sea-orm copied to clipboard
[codegen] Struct / enum derive `PartialEq` should also derive `Eq`
Motivation
New clippy lint was added in Rust 1.63.0. which checks for types that derive PartialEq
and could implement Eq
.
Example:
#[derive(PartialEq)]
struct Foo {
i_am_eq: i32,
i_am_eq_too: Vec<String>,
}
Do this instead:
#[derive(PartialEq, Eq)]
struct Foo {
i_am_eq: i32,
i_am_eq_too: Vec<String>,
}
Proposed Solutions
Check sea-orm-codegen
where #[derive(PartialEq)]
should be changed to #[derive(PartialEq, Eq)]
.
Additional Information
Clippy lints index: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
Thanks! @baoyachi
Oh,I see you've done it。
Nope, it's not
https://github.com/SeaQL/sea-orm/pull/967 doesn't touch code generator of codegen
It's seem's touch sea-query create
...
/// Value variants
///
/// We want Value to be exactly 1 pointer sized, so anything larger should be boxed.
+ #[derive(Clone, Debug, PartialEq)]
pub enum Value {
Bool(Option<bool>),
TinyInt(Option<i8>),
SmallInt(Option<i16>),
Int(Option<i32>),
...
So,first need change sea-query?
I don't think we need an option for this behaviour. It seems to be universally true that we want Eq and PartialEq wherever possible.
We can simply change the codegen for enum. For any struct (that contains a f64), implementing Eq is not possible.
There are only three place in the codegen we need to modify:
- https://github.com/SeaQL/sea-orm/blob/d262501a44c048ed36a17bbf661ced3c5193f455/sea-orm-codegen/src/entity/active_enum.rs#L33-L42
- https://github.com/SeaQL/sea-orm/blob/d262501a44c048ed36a17bbf661ced3c5193f455/sea-orm-codegen/src/entity/writer.rs#L387-L390
- https://github.com/SeaQL/sea-orm/blob/d262501a44c048ed36a17bbf661ced3c5193f455/sea-orm-codegen/src/entity/writer.rs#L623-L633
Btw... both f32
and f64
does not implement Eq
but implemented PartialEq
May I take this one? If I understand correctly, only the above files need to be changed?
Hey @w93163red, sure! Please go ahead :)
But note that if we have any f32
/ f64
fields in the model, it shouldn't derive Eq
(PartialEq is allowed). Also, we need to add a test cases for this as well.
I submitted a PR. If you find anything wrong, please let me know. Thanks~
Thanks! @w93163red Please check the comment: https://github.com/SeaQL/sea-orm/pull/988#pullrequestreview-1084965612