Skip to content

Commit 0df05eb

Browse files
committed
fix: clippy warnings in tests and macros
- Fix deprecated chrono DateTime::from_utc usage - Add workspace lint config to allow postgres_14 cfg - Fix dead code warnings in sqlx-macros query data - Fix needless_borrows_for_generic_args in sqlx-macros - Fix useless_conversion by removing redundant .into() - Fix useless_vec by using array instead of vec! in test
1 parent c64bbfe commit 0df05eb

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ members = [
1818
"examples/sqlite/todos",
1919
]
2020

21+
[workspace.lints.rust]
22+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(postgres_14)'] }
23+
2124
[package]
2225
name = "sqlx-oldapi"
2326
version = "0.6.48"

sqlx-macros/src/query/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub mod offline {
8080
}
8181

8282
#[derive(serde::Deserialize)]
83+
#[allow(dead_code)]
8384
pub struct DynQueryData {
8485
#[serde(skip)]
8586
pub db_name: String,
@@ -153,6 +154,7 @@ pub mod offline {
153154
where
154155
Describe<DB>: serde::Serialize + serde::de::DeserializeOwned,
155156
{
157+
#[allow(dead_code)]
156158
pub fn from_dyn_data(dyn_data: DynQueryData) -> crate::Result<Self> {
157159
assert!(!dyn_data.db_name.is_empty());
158160
assert!(!dyn_data.hash.is_empty());

sqlx-macros/src/query/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Metadata {
4949
let cargo = env("CARGO").expect("`CARGO` must be set");
5050

5151
let output = Command::new(&cargo)
52-
.args(&["metadata", "--format-version=1", "--no-deps"])
52+
.args(["metadata", "--format-version=1", "--no-deps"])
5353
.current_dir(&self.manifest_dir)
5454
.env_remove("__CARGO_FIX_PLZ")
5555
.output()
@@ -78,8 +78,7 @@ static METADATA: Lazy<Metadata> = Lazy::new(|| {
7878

7979
#[cfg(feature = "offline")]
8080
let package_name: String = env("CARGO_PKG_NAME")
81-
.expect("`CARGO_PKG_NAME` must be set")
82-
.into();
81+
.expect("`CARGO_PKG_NAME` must be set");
8382

8483
#[cfg(feature = "offline")]
8584
let target_dir = env("CARGO_TARGET_DIR").map_or_else(|_| "target".into(), |dir| dir.into());

tests/mssql/mssql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ CREATE TABLE #qb_test (
530530
name: String,
531531
}
532532

533-
let items_to_insert = vec![
533+
let items_to_insert = [
534534
TestItem {
535535
id: 1,
536536
name: "Alice".to_string(),

tests/mysql/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ mod chrono {
8888

8989
test_type!(chrono_timestamp<DateTime::<Utc>>(MySql,
9090
"TIMESTAMP '2019-01-02 05:10:20.115100'"
91-
== DateTime::<Utc>::from_utc(
91+
== DateTime::from_naive_utc_and_offset(
9292
NaiveDateTime::parse_from_str("2019-01-02 05:10:20.115100", "%Y-%m-%d %H:%M:%S%.f").unwrap(),
9393
Utc,
9494
)
9595
));
9696

9797
test_type!(chrono_fixed_offset<DateTime::<FixedOffset>>(MySql,
9898
"TIMESTAMP '2019-01-02 05:10:20.115100'"
99-
== DateTime::<Utc>::from_utc(
99+
== DateTime::from_naive_utc_and_offset(
100100
NaiveDateTime::parse_from_str("2019-01-02 05:10:20.115100", "%Y-%m-%d %H:%M:%S%.f").unwrap(),
101101
Utc,
102102
)

tests/postgres/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ mod chrono {
286286

287287
test_type!(chrono_date_time_tz_utc<DateTime::<Utc>>(Postgres,
288288
"TIMESTAMPTZ '2019-01-02 05:10:20.115100'"
289-
== DateTime::<Utc>::from_utc(
289+
== DateTime::from_naive_utc_and_offset(
290290
NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_micro_opt(5, 10, 20, 115100).unwrap(),
291291
Utc,
292292
)
@@ -300,7 +300,7 @@ mod chrono {
300300
test_type!(chrono_date_time_tz_vec<Vec<DateTime::<Utc>>>(Postgres,
301301
"array['2019-01-02 05:10:20.115100']::timestamptz[]"
302302
== vec![
303-
DateTime::<Utc>::from_utc(
303+
DateTime::from_naive_utc_and_offset(
304304
NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_micro_opt(5, 10, 20, 115100).unwrap(),
305305
Utc,
306306
)

0 commit comments

Comments
 (0)