From b21abf617f5229d3c563db86b144ac047867a093 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 31 Jan 2023 16:46:44 +0800 Subject: [PATCH] Fix clippy warnings (#1437) --- .github/workflows/rust.yml | 1 + src/driver/sqlx_mysql.rs | 3 +- src/driver/sqlx_postgres.rs | 5 ++-- src/driver/sqlx_sqlite.rs | 3 +- src/executor/query.rs | 2 +- tests/basic.rs | 12 ++++---- tests/crud/error.rs | 4 +-- tests/loader_tests.rs | 4 +-- tests/relational_tests.rs | 58 ++++++++++++++++++------------------ tests/sequential_op_tests.rs | 8 ++--- 10 files changed, 52 insertions(+), 48 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 90de258c..acf0f5d1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -107,6 +107,7 @@ jobs: toolchain: stable components: clippy - run: cargo clippy --all -- -D warnings + - run: cargo clippy --all --features runtime-async-std-native-tls,sqlx-all -- -D warnings - run: cargo clippy --manifest-path sea-orm-cli/Cargo.toml -- -D warnings - run: cargo clippy --manifest-path sea-orm-migration/Cargo.toml -- -D warnings - run: cargo clippy --manifest-path sea-orm-rocket/Cargo.toml -- -D warnings diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index cd6fc68b..bdad0b78 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -224,7 +224,8 @@ impl SqlxMySqlPoolConnection { /// Explicitly close the MySQL connection pub async fn close(self) -> Result<(), DbErr> { - Ok(self.pool.close().await) + self.pool.close().await; + Ok(()) } } diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index f13e3e34..f766a9b3 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -56,7 +56,7 @@ impl SqlxPostgresConnector { let set_search_path_sql = options .schema_search_path .as_ref() - .map(|schema| format!("SET search_path = '{}'", schema)); + .map(|schema| format!("SET search_path = '{schema}'")); let mut pool_options = options.pool_options(); if let Some(sql) = set_search_path_sql { pool_options = pool_options.after_connect(move |conn, _| { @@ -239,7 +239,8 @@ impl SqlxPostgresPoolConnection { /// Explicitly close the Postgres connection pub async fn close(self) -> Result<(), DbErr> { - Ok(self.pool.close().await) + self.pool.close().await; + Ok(()) } } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 6c151cd2..dfaaa231 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -231,7 +231,8 @@ impl SqlxSqlitePoolConnection { /// Explicitly close the SQLite connection pub async fn close(self) -> Result<(), DbErr> { - Ok(self.pool.close().await) + self.pool.close().await; + Ok(()) } } diff --git a/src/executor/query.rs b/src/executor/query.rs index 971b55fb..87eabd73 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -108,7 +108,7 @@ impl fmt::Debug for QueryResultRow { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { #[cfg(feature = "sqlx-mysql")] - Self::SqlxMySql(row) => write!(f, "{:?}", row), + Self::SqlxMySql(row) => write!(f, "{row:?}"), #[cfg(feature = "sqlx-postgres")] Self::SqlxPostgres(_) => write!(f, "QueryResultRow::SqlxPostgres cannot be inspected"), #[cfg(feature = "sqlx-sqlite")] diff --git a/tests/basic.rs b/tests/basic.rs index a7ec72f2..8c466ea6 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -35,7 +35,7 @@ async fn setup_schema(db: &DbConn) -> Result<(), DbErr> { let builder = db.get_database_backend(); let result = db.execute(builder.build(&stmt)).await?; - println!("Create table cake: {:?}", result); + println!("Create table cake: {result:?}"); Ok(()) } @@ -50,7 +50,7 @@ async fn crud_cake(db: &DbConn) -> Result<(), DbErr> { let mut apple = apple.save(db).await?; println!(); - println!("Inserted: {:?}", apple); + println!("Inserted: {apple:?}"); assert_eq!( apple, @@ -65,12 +65,12 @@ async fn crud_cake(db: &DbConn) -> Result<(), DbErr> { let apple = apple.save(db).await?; println!(); - println!("Updated: {:?}", apple); + println!("Updated: {apple:?}"); let count = cake::Entity::find().count(db).await?; println!(); - println!("Count: {:?}", count); + println!("Count: {count:?}"); assert_eq!(count, 1); let apple = cake::Entity::find_by_id(1).one(db).await?; @@ -88,7 +88,7 @@ async fn crud_cake(db: &DbConn) -> Result<(), DbErr> { let result = apple.delete(db).await?; println!(); - println!("Deleted: {:?}", result); + println!("Deleted: {result:?}"); let apple = cake::Entity::find_by_id(1).one(db).await?; @@ -97,7 +97,7 @@ async fn crud_cake(db: &DbConn) -> Result<(), DbErr> { let count = cake::Entity::find().count(db).await?; println!(); - println!("Count: {:?}", count); + println!("Count: {count:?}"); assert_eq!(count, 0); Ok(()) diff --git a/tests/crud/error.rs b/tests/crud/error.rs index 4828d9cd..07bb5100 100644 --- a/tests/crud/error.rs +++ b/tests/crud/error.rs @@ -31,7 +31,7 @@ pub async fn test_cake_error_sqlx(db: &DbConn) { .expect_err("inserting should fail due to duplicate primary key"); #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] - match error { + match &error { DbErr::Exec(RuntimeErr::SqlxError(error)) => match error { Error::Database(e) => { #[cfg(feature = "sqlx-mysql")] @@ -44,7 +44,7 @@ pub async fn test_cake_error_sqlx(db: &DbConn) { _ => panic!("Unexpected Error kind"), } #[cfg(feature = "sqlx-postgres")] - match error { + match &error { DbErr::Query(RuntimeErr::SqlxError(error)) => match error { Error::Database(e) => { assert_eq!(e.code().unwrap(), "23505"); diff --git a/tests/loader_tests.rs b/tests/loader_tests.rs index 4f38d8f3..01c3b466 100644 --- a/tests/loader_tests.rs +++ b/tests/loader_tests.rs @@ -208,8 +208,8 @@ async fn loader_load_many() -> Result<(), DbErr> { .await .expect("Should load bakers"); - println!("A: {:?}", bakers); - println!("B: {:?}", bakeries); + println!("A: {bakers:?}"); + println!("B: {bakeries:?}"); assert_eq!(bakeries, [bakery_1, bakery_2]); diff --git a/tests/relational_tests.rs b/tests/relational_tests.rs index 7c85b8e5..29a1556c 100644 --- a/tests/relational_tests.rs +++ b/tests/relational_tests.rs @@ -253,11 +253,11 @@ pub async fn inner_join() { .unwrap(); assert_eq!(results.len(), 2); - assert!((&results) + assert!(results .iter() .any(|result| result.name == customer_kate.name.clone() && result.order_total == Some(kate_order_1.total))); - assert!((&results) + assert!(results .iter() .any(|result| result.name == customer_kate.name.clone() && result.order_total == Some(kate_order_2.total))); @@ -499,7 +499,7 @@ pub async fn linked() -> Result<(), DbErr> { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" })), - bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let baker_bob_res = Baker::insert(baker_bob).exec(&ctx.db).await?; @@ -508,13 +508,13 @@ pub async fn linked() -> Result<(), DbErr> { price: Set(dec!(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), - bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let mud_cake_res = Cake::insert(mud_cake).exec(&ctx.db).await?; 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), + cake_id: Set(mud_cake_res.last_insert_id), + baker_id: Set(baker_bob_res.last_insert_id), }; CakesBakers::insert(bob_cakes_bakers).exec(&ctx.db).await?; @@ -524,7 +524,7 @@ pub async fn linked() -> Result<(), DbErr> { contact_details: Set(serde_json::json!({ "mobile": "+85212345678", })), - bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let baker_bobby_res = Baker::insert(baker_bobby).exec(&ctx.db).await?; @@ -533,13 +533,13 @@ pub async fn linked() -> Result<(), DbErr> { price: Set(dec!(20.5)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), - bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let cheese_cake_res = Cake::insert(cheese_cake).exec(&ctx.db).await?; 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), + cake_id: Set(cheese_cake_res.last_insert_id), + baker_id: Set(baker_bobby_res.last_insert_id), }; CakesBakers::insert(bobby_cakes_bakers) .exec(&ctx.db) @@ -549,13 +549,13 @@ pub async fn linked() -> Result<(), DbErr> { price: Set(dec!(30.15)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), - bakery_id: Set(Some(seaside_bakery_res.last_insert_id as i32)), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let chocolate_cake_res = Cake::insert(chocolate_cake).exec(&ctx.db).await?; 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), + cake_id: Set(chocolate_cake_res.last_insert_id), + baker_id: Set(baker_bobby_res.last_insert_id), }; CakesBakers::insert(bobby_cakes_bakers) .exec(&ctx.db) @@ -569,16 +569,16 @@ pub async fn linked() -> Result<(), DbErr> { }; let customer_kate_res = Customer::insert(customer_kate).exec(&ctx.db).await?; let kate_order_1 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res.last_insert_id as i32), - customer_id: Set(customer_kate_res.last_insert_id as i32), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kate_res.last_insert_id), total: Set(dec!(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kate_order_1_res = Order::insert(kate_order_1).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(cheese_cake_res.last_insert_id as i32), - order_id: Set(kate_order_1_res.last_insert_id as i32), + cake_id: Set(cheese_cake_res.last_insert_id), + order_id: Set(kate_order_1_res.last_insert_id), price: Set(dec!(7.55)), quantity: Set(2), ..Default::default() @@ -586,16 +586,16 @@ pub async fn linked() -> Result<(), DbErr> { .save(&ctx.db) .await?; let kate_order_2 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res.last_insert_id as i32), - customer_id: Set(customer_kate_res.last_insert_id as i32), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kate_res.last_insert_id), total: Set(dec!(29.7)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kate_order_2_res = Order::insert(kate_order_2).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(chocolate_cake_res.last_insert_id as i32), - order_id: Set(kate_order_2_res.last_insert_id as i32), + cake_id: Set(chocolate_cake_res.last_insert_id), + order_id: Set(kate_order_2_res.last_insert_id), price: Set(dec!(9.9)), quantity: Set(3), ..Default::default() @@ -611,16 +611,16 @@ pub async fn linked() -> Result<(), DbErr> { }; let customer_kara_res = Customer::insert(customer_kara).exec(&ctx.db).await?; let kara_order_1 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res.last_insert_id as i32), - customer_id: Set(customer_kara_res.last_insert_id as i32), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kara_res.last_insert_id), total: Set(dec!(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kara_order_1_res = Order::insert(kara_order_1).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(mud_cake_res.last_insert_id as i32), - order_id: Set(kara_order_1_res.last_insert_id as i32), + cake_id: Set(mud_cake_res.last_insert_id), + order_id: Set(kara_order_1_res.last_insert_id), price: Set(dec!(7.55)), quantity: Set(2), ..Default::default() @@ -628,16 +628,16 @@ pub async fn linked() -> Result<(), DbErr> { .save(&ctx.db) .await?; let kara_order_2 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res.last_insert_id as i32), - customer_id: Set(customer_kara_res.last_insert_id as i32), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kara_res.last_insert_id), total: Set(dec!(29.7)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kara_order_2_res = Order::insert(kara_order_2).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(cheese_cake_res.last_insert_id as i32), - order_id: Set(kara_order_2_res.last_insert_id as i32), + cake_id: Set(cheese_cake_res.last_insert_id), + order_id: Set(kara_order_2_res.last_insert_id), price: Set(dec!(9.9)), quantity: Set(3), ..Default::default() diff --git a/tests/sequential_op_tests.rs b/tests/sequential_op_tests.rs index bc24e104..2b0ef97b 100644 --- a/tests/sequential_op_tests.rs +++ b/tests/sequential_op_tests.rs @@ -74,7 +74,7 @@ async fn seed_data(db: &DatabaseConnection) { .expect("could not insert cake"); let cake_baker = cakes_bakers::ActiveModel { - cake_id: Set(cake_insert_res.last_insert_id as i32), + cake_id: Set(cake_insert_res.last_insert_id), baker_id: Set(baker_1.id.clone().unwrap()), }; @@ -108,7 +108,7 @@ async fn seed_data(db: &DatabaseConnection) { .expect("could not insert order"); let _lineitem = lineitem::ActiveModel { - cake_id: Set(cake_insert_res.last_insert_id as i32), + cake_id: Set(cake_insert_res.last_insert_id), price: Set(dec!(10.00)), quantity: Set(12), order_id: Set(kate_order_1.id.clone().unwrap()), @@ -119,7 +119,7 @@ async fn seed_data(db: &DatabaseConnection) { .expect("could not insert order"); let _lineitem2 = lineitem::ActiveModel { - cake_id: Set(cake_insert_res.last_insert_id as i32), + cake_id: Set(cake_insert_res.last_insert_id), price: Set(dec!(50.00)), quantity: Set(2), order_id: Set(kate_order_1.id.clone().unwrap()), @@ -210,7 +210,7 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option