diff --git a/sea-orm-codegen/src/entity/relation.rs b/sea-orm-codegen/src/entity/relation.rs index 969d0429..57722e50 100644 --- a/sea-orm-codegen/src/entity/relation.rs +++ b/sea-orm-codegen/src/entity/relation.rs @@ -81,7 +81,7 @@ impl Relation { let module_name = if let Some(module_name) = self.get_module_name() { format!("super::{}::", module_name) } else { - format!("") + String::new() }; let ref_entity = format!("{}Entity", module_name); match self.rel_type { diff --git a/sea-orm-codegen/src/entity/transformer.rs b/sea-orm-codegen/src/entity/transformer.rs index d526c98c..43cc111b 100644 --- a/sea-orm-codegen/src/entity/transformer.rs +++ b/sea-orm-codegen/src/entity/transformer.rs @@ -108,15 +108,14 @@ impl EntityTransformer { .get_indexes() .iter() .filter(|index| index.is_primary_key()) - .map(|index| { + .flat_map(|index| { index .get_index_spec() .get_column_names() .into_iter() .map(|name| PrimaryKey { name }) .collect::>() - }) - .flatten(), + }), ); let entity = Entity { table_name: table_name.clone(), diff --git a/sea-orm-macros/src/derives/entity_model.rs b/sea-orm-macros/src/derives/entity_model.rs index 25ea2727..0c7a0148 100644 --- a/sea-orm-macros/src/derives/entity_model.rs +++ b/sea-orm-macros/src/derives/entity_model.rs @@ -220,7 +220,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res let field_type = &field.ty; let temp = quote! { #field_type } .to_string() //E.g.: "Option < String >" - .replace(" ", ""); + .replace(' ', ""); let temp = if temp.starts_with("Option<") { nullable = true; &temp[7..(temp.len() - 1)] diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index 3d062627..ceb4f726 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -636,10 +636,10 @@ where } macro_rules! impl_into_active_value { - ($ty: ty, $fn: ident) => { + ($ty: ty) => { impl IntoActiveValue<$ty> for $ty { fn into_active_value(self) -> ActiveValue<$ty> { - $fn(self) + Set(self) } } @@ -663,55 +663,55 @@ macro_rules! impl_into_active_value { }; } -impl_into_active_value!(bool, Set); -impl_into_active_value!(i8, Set); -impl_into_active_value!(i16, Set); -impl_into_active_value!(i32, Set); -impl_into_active_value!(i64, Set); -impl_into_active_value!(u8, Set); -impl_into_active_value!(u16, Set); -impl_into_active_value!(u32, Set); -impl_into_active_value!(u64, Set); -impl_into_active_value!(f32, Set); -impl_into_active_value!(f64, Set); -impl_into_active_value!(&'static str, Set); -impl_into_active_value!(String, Set); +impl_into_active_value!(bool); +impl_into_active_value!(i8); +impl_into_active_value!(i16); +impl_into_active_value!(i32); +impl_into_active_value!(i64); +impl_into_active_value!(u8); +impl_into_active_value!(u16); +impl_into_active_value!(u32); +impl_into_active_value!(u64); +impl_into_active_value!(f32); +impl_into_active_value!(f64); +impl_into_active_value!(&'static str); +impl_into_active_value!(String); #[cfg(feature = "with-json")] #[cfg_attr(docsrs, doc(cfg(feature = "with-json")))] -impl_into_active_value!(crate::prelude::Json, Set); +impl_into_active_value!(crate::prelude::Json); #[cfg(feature = "with-chrono")] #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] -impl_into_active_value!(crate::prelude::Date, Set); +impl_into_active_value!(crate::prelude::Date); #[cfg(feature = "with-chrono")] #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] -impl_into_active_value!(crate::prelude::Time, Set); +impl_into_active_value!(crate::prelude::Time); #[cfg(feature = "with-chrono")] #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] -impl_into_active_value!(crate::prelude::DateTime, Set); +impl_into_active_value!(crate::prelude::DateTime); #[cfg(feature = "with-chrono")] #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] -impl_into_active_value!(crate::prelude::DateTimeWithTimeZone, Set); +impl_into_active_value!(crate::prelude::DateTimeWithTimeZone); #[cfg(feature = "with-chrono")] #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] -impl_into_active_value!(crate::prelude::DateTimeUtc, Set); +impl_into_active_value!(crate::prelude::DateTimeUtc); #[cfg(feature = "with-chrono")] #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] -impl_into_active_value!(crate::prelude::DateTimeLocal, Set); +impl_into_active_value!(crate::prelude::DateTimeLocal); #[cfg(feature = "with-rust_decimal")] #[cfg_attr(docsrs, doc(cfg(feature = "with-rust_decimal")))] -impl_into_active_value!(crate::prelude::Decimal, Set); +impl_into_active_value!(crate::prelude::Decimal); #[cfg(feature = "with-uuid")] #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] -impl_into_active_value!(crate::prelude::Uuid, Set); +impl_into_active_value!(crate::prelude::Uuid); impl Default for ActiveValue where diff --git a/src/executor/delete.rs b/src/executor/delete.rs index c69b90ca..ed2a2579 100644 --- a/src/executor/delete.rs +++ b/src/executor/delete.rs @@ -61,14 +61,14 @@ impl Deleter { } } -async fn exec_delete_only<'a, C>(query: DeleteStatement, db: &'a C) -> Result +async fn exec_delete_only(query: DeleteStatement, db: &C) -> Result where C: ConnectionTrait, { Deleter::new(query).exec(db).await } -async fn exec_delete<'a, C>(statement: Statement, db: &'a C) -> Result +async fn exec_delete(statement: Statement, db: &C) -> Result where C: ConnectionTrait, { diff --git a/src/executor/execute.rs b/src/executor/execute.rs index 821f7bed..3da4ec8a 100644 --- a/src/executor/execute.rs +++ b/src/executor/execute.rs @@ -7,6 +7,7 @@ pub struct ExecResult { } /// Holds a result depending on the database backend chosen by the feature flag +#[allow(clippy::enum_variant_names)] #[derive(Debug)] pub(crate) enum ExecResultHolder { /// Holds the result of executing an operation on a MySQL database diff --git a/src/executor/insert.rs b/src/executor/insert.rs index ef5c11ea..61e7bfb6 100644 --- a/src/executor/insert.rs +++ b/src/executor/insert.rs @@ -102,10 +102,10 @@ where } } -async fn exec_insert<'a, A, C>( +async fn exec_insert( primary_key: Option, statement: Statement, - db: &'a C, + db: &C, ) -> Result, DbErr> where C: ConnectionTrait, @@ -136,10 +136,10 @@ where Ok(InsertResult { last_insert_id }) } -async fn exec_insert_with_returning<'a, A, C>( +async fn exec_insert_with_returning( primary_key: Option, mut insert_statement: InsertStatement, - db: &'a C, + db: &C, ) -> Result<::Model, DbErr> where ::Model: IntoActiveModel, diff --git a/src/executor/query.rs b/src/executor/query.rs index 918d513b..5d19aa1f 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -9,6 +9,7 @@ pub struct QueryResult { pub(crate) row: QueryResultRow, } +#[allow(clippy::enum_variant_names)] pub(crate) enum QueryResultRow { #[cfg(feature = "sqlx-mysql")] SqlxMySql(sqlx::mysql::MySqlRow), diff --git a/src/executor/select.rs b/src/executor/select.rs index f32ae7f4..c7be57c2 100644 --- a/src/executor/select.rs +++ b/src/executor/select.rs @@ -419,7 +419,7 @@ where } } - fn into_selector_raw<'a, C>(self, db: &C) -> SelectorRaw + fn into_selector_raw(self, db: &C) -> SelectorRaw where C: ConnectionTrait, { diff --git a/src/executor/update.rs b/src/executor/update.rs index 70e971a8..ea3c223a 100644 --- a/src/executor/update.rs +++ b/src/executor/update.rs @@ -73,17 +73,17 @@ impl Updater { } } -async fn exec_update_only<'a, C>(query: UpdateStatement, db: &'a C) -> Result +async fn exec_update_only(query: UpdateStatement, db: &C) -> Result where C: ConnectionTrait, { Updater::new(query).exec(db).await } -async fn exec_update_and_return_updated<'a, A, C>( +async fn exec_update_and_return_updated( mut query: UpdateStatement, model: A, - db: &'a C, + db: &C, ) -> Result<::Model, DbErr> where A: ActiveModelTrait, @@ -136,9 +136,9 @@ where } } -async fn exec_update<'a, C>( +async fn exec_update( statement: Statement, - db: &'a C, + db: &C, check_record_exists: bool, ) -> Result where diff --git a/src/query/json.rs b/src/query/json.rs index a3a1ba01..63a21444 100644 --- a/src/query/json.rs +++ b/src/query/json.rs @@ -166,6 +166,7 @@ impl FromQueryResult for JsonValue { } Ok(JsonValue::Object(map)) } + #[allow(unreachable_patterns)] _ => unreachable!(), } } diff --git a/tests/relational_tests.rs b/tests/relational_tests.rs index 05e081ff..ed696bb8 100644 --- a/tests/relational_tests.rs +++ b/tests/relational_tests.rs @@ -35,7 +35,7 @@ pub async fn left_join() { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" })), - bakery_id: Set(Some(bakery.id.clone())), + bakery_id: Set(Some(bakery.id)), ..Default::default() } .insert(&ctx.db) @@ -124,8 +124,8 @@ pub async fn right_join() { .expect("could not insert customer"); let _order = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(15.10)), placed_at: Set(Utc::now().naive_utc()), @@ -135,7 +135,8 @@ pub async fn right_join() { .await .expect("could not insert order"); - #[derive(Debug, FromQueryResult)] + #[derive(FromQueryResult)] + #[allow(dead_code)] struct SelectResult { name: String, order_total: Option, @@ -210,8 +211,8 @@ pub async fn inner_join() { .expect("could not insert customer"); let kate_order_1 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(15.10)), placed_at: Set(Utc::now().naive_utc()), @@ -222,8 +223,8 @@ pub async fn inner_join() { .expect("could not insert order"); let kate_order_2 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(100.00)), placed_at: Set(Utc::now().naive_utc()), @@ -253,13 +254,13 @@ pub async fn inner_join() { assert_eq!(results.len(), 2); assert!((&results) - .into_iter() + .iter() .any(|result| result.name == customer_kate.name.clone() - && result.order_total == Some(kate_order_1.total.clone()))); + && result.order_total == Some(kate_order_1.total))); assert!((&results) - .into_iter() + .iter() .any(|result| result.name == customer_kate.name.clone() - && result.order_total == Some(kate_order_2.total.clone()))); + && result.order_total == Some(kate_order_2.total))); ctx.delete().await; } @@ -292,8 +293,8 @@ pub async fn group_by() { .expect("could not insert customer"); let kate_order_1 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(99.95)), placed_at: Set(Utc::now().naive_utc()), @@ -304,8 +305,8 @@ pub async fn group_by() { .expect("could not insert order"); let kate_order_2 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(200.00)), placed_at: Set(Utc::now().naive_utc()), @@ -345,15 +346,15 @@ pub async fn group_by() { assert_eq!(result.number_orders, Some(2)); assert_eq!( result.total_spent, - Some(kate_order_1.total.clone() + kate_order_2.total.clone()) + Some(kate_order_1.total + kate_order_2.total) ); assert_eq!( result.min_spent, - Some(kate_order_1.total.clone().min(kate_order_2.total.clone())) + Some(kate_order_1.total.min(kate_order_2.total)) ); assert_eq!( result.max_spent, - Some(kate_order_1.total.clone().max(kate_order_2.total.clone())) + Some(kate_order_1.total.max(kate_order_2.total)) ); ctx.delete().await; } @@ -387,8 +388,8 @@ pub async fn having() { .expect("could not insert customer"); let kate_order_1 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(100.00)), placed_at: Set(Utc::now().naive_utc()), @@ -399,8 +400,8 @@ pub async fn having() { .expect("could not insert order"); let _kate_order_2 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_kate.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_kate.id), total: Set(dec!(12.00)), placed_at: Set(Utc::now().naive_utc()), @@ -419,8 +420,8 @@ pub async fn having() { .expect("could not insert customer"); let _bob_order_1 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_bob.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_bob.id), total: Set(dec!(50.0)), placed_at: Set(Utc::now().naive_utc()), @@ -431,8 +432,8 @@ pub async fn having() { .expect("could not insert order"); let _bob_order_2 = order::ActiveModel { - bakery_id: Set(bakery.id.clone()), - customer_id: Set(customer_bob.id.clone()), + bakery_id: Set(bakery.id), + customer_id: Set(customer_bob.id), total: Set(dec!(50.0)), placed_at: Set(Utc::now().naive_utc()), @@ -463,7 +464,7 @@ pub async fn having() { assert_eq!(results.len(), 1); assert_eq!(results[0].name, customer_kate.name.clone()); - assert_eq!(results[0].order_total, Some(kate_order_1.total.clone())); + assert_eq!(results[0].order_total, Some(kate_order_1.total)); ctx.delete().await; } @@ -514,7 +515,6 @@ pub async fn linked() -> Result<(), DbErr> { let bob_cakes_bakers = cakes_bakers::ActiveModel { cake_id: Set(mud_cake_res.last_insert_id as i32), baker_id: Set(baker_bob_res.last_insert_id as i32), - ..Default::default() }; CakesBakers::insert(bob_cakes_bakers).exec(&ctx.db).await?; @@ -540,7 +540,6 @@ pub async fn linked() -> Result<(), DbErr> { let bobby_cakes_bakers = cakes_bakers::ActiveModel { cake_id: Set(cheese_cake_res.last_insert_id as i32), baker_id: Set(baker_bobby_res.last_insert_id as i32), - ..Default::default() }; CakesBakers::insert(bobby_cakes_bakers) .exec(&ctx.db) @@ -557,7 +556,6 @@ pub async fn linked() -> Result<(), DbErr> { let bobby_cakes_bakers = cakes_bakers::ActiveModel { cake_id: Set(chocolate_cake_res.last_insert_id as i32), baker_id: Set(baker_bobby_res.last_insert_id as i32), - ..Default::default() }; CakesBakers::insert(bobby_cakes_bakers) .exec(&ctx.db) diff --git a/tests/sequential_op_tests.rs b/tests/sequential_op_tests.rs index 30d9b041..bc24e104 100644 --- a/tests/sequential_op_tests.rs +++ b/tests/sequential_op_tests.rs @@ -76,7 +76,6 @@ async fn seed_data(db: &DatabaseConnection) { let cake_baker = cakes_bakers::ActiveModel { cake_id: Set(cake_insert_res.last_insert_id as i32), baker_id: Set(baker_1.id.clone().unwrap()), - ..Default::default() }; let cake_baker_res = CakesBakers::insert(cake_baker.clone()) @@ -181,7 +180,7 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option .unwrap() .into_iter() .map(|b| LeastSalesBakerResult { - id: b.id.clone(), + id: b.id, cakes_sold: b.cakes_sold_opt.unwrap_or_default().into(), }) .collect(); @@ -201,7 +200,7 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option Option Result<(), DbErr> { id: Set(1), name: Set("Duplicated primary key".to_owned()), profit_margin: Set(20.0), - ..Default::default() } .insert(txn) .await?; // Throw error and rollback // This line won't be reached - assert!(false); + unreachable!(); + #[allow(unreachable_code)] Ok(()) }) })