Skip to content

Commit 3a74574

Browse files
committed
Remove explicit casts from tests
1 parent fa34efb commit 3a74574

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

tests/test.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use postgres::error::{PgConnectDbError,
3535
InvalidCatalogName,
3636
PgWrongTransaction,
3737
CardinalityViolation};
38-
use postgres::types::{PgInt4, PgVarchar, ToSql};
38+
use postgres::types::{PgInt4, PgVarchar};
3939

4040
macro_rules! or_fail(
4141
($e:expr) => (
@@ -108,7 +108,7 @@ fn test_transaction_commit() {
108108
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
109109

110110
let trans = or_fail!(conn.transaction());
111-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
111+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
112112
trans.set_commit();
113113
drop(trans);
114114

@@ -124,7 +124,7 @@ fn test_transaction_commit_finish() {
124124
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
125125

126126
let trans = or_fail!(conn.transaction());
127-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
127+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
128128
trans.set_commit();
129129
assert!(trans.finish().is_ok());
130130

@@ -140,7 +140,7 @@ fn test_transaction_commit_method() {
140140
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
141141

142142
let trans = or_fail!(conn.transaction());
143-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
143+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
144144
assert!(trans.commit().is_ok());
145145

146146
let stmt = or_fail!(conn.prepare("SELECT * FROM foo"));
@@ -154,10 +154,10 @@ fn test_transaction_rollback() {
154154
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
155155
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
156156

157-
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
157+
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
158158

159159
let trans = or_fail!(conn.transaction());
160-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql]));
160+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32]));
161161
drop(trans);
162162

163163
let stmt = or_fail!(conn.prepare("SELECT * FROM foo"));
@@ -171,10 +171,10 @@ fn test_transaction_rollback_finish() {
171171
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
172172
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
173173

174-
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
174+
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
175175

176176
let trans = or_fail!(conn.transaction());
177-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql]));
177+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32]));
178178
assert!(trans.finish().is_ok());
179179

180180
let stmt = or_fail!(conn.prepare("SELECT * FROM foo"));
@@ -373,7 +373,7 @@ fn test_query() {
373373
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
374374
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []));
375375
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)",
376-
[&1i64 as &ToSql, &2i64 as &ToSql]));
376+
&[&1i64, &2i64]));
377377
let stmt = or_fail!(conn.prepare("SELECT * from foo ORDER BY id"));
378378
let result = or_fail!(stmt.query([]));
379379

@@ -415,7 +415,7 @@ fn test_lazy_query() {
415415
let stmt = or_fail!(trans.prepare("INSERT INTO foo (id) VALUES ($1)"));
416416
let values = vec!(0i32, 1, 2, 3, 4, 5);
417417
for value in values.iter() {
418-
or_fail!(stmt.execute([value as &ToSql]));
418+
or_fail!(stmt.execute(&[value]));
419419
}
420420
let stmt = or_fail!(trans.prepare("SELECT id FROM foo ORDER BY id"));
421421
let result = or_fail!(trans.lazy_query(&stmt, [], 2));
@@ -460,15 +460,15 @@ fn test_execute_counts() {
460460
b INT
461461
)", [])));
462462
assert_eq!(3, or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)",
463-
[&1i32 as &ToSql, &2i32 as &ToSql])));
463+
&[&1i32, &2i32])));
464464
assert_eq!(2, or_fail!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", [])));
465465
assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", [])));
466466
}
467467

468468
#[test]
469469
fn test_wrong_param_type() {
470470
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
471-
match conn.execute("SELECT $1::VARCHAR", [&1i32 as &ToSql]) {
471+
match conn.execute("SELECT $1::VARCHAR", &[&1i32]) {
472472
Err(PgWrongType(_)) => {}
473473
res => fail!("unexpected result {}", res)
474474
}
@@ -477,7 +477,7 @@ fn test_wrong_param_type() {
477477
#[test]
478478
fn test_too_few_params() {
479479
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
480-
match conn.execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]) {
480+
match conn.execute("SELECT $1::INT, $2::INT", &[&1i32]) {
481481
Err(PgWrongParamCount { expected: 2, actual: 1 }) => {},
482482
res => fail!("unexpected result {}", res)
483483
}
@@ -486,7 +486,7 @@ fn test_too_few_params() {
486486
#[test]
487487
fn test_too_many_params() {
488488
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
489-
match conn.execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql, &2i32 as &ToSql, &3i32 as &ToSql]) {
489+
match conn.execute("SELECT $1::INT, $2::INT", &[&1i32, &2i32, &3i32]) {
490490
Err(PgWrongParamCount { expected: 2, actual: 3 }) => {},
491491
res => fail!("unexpected result {}", res)
492492
}

tests/types/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S
2020
assert!(val == &result);
2121

2222
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice()));
23-
let result = or_fail!(stmt.query([val as &ToSql])).next().unwrap().get(0u);
23+
let result = or_fail!(stmt.query(&[val])).next().unwrap().get(0u);
2424
assert!(val == &result);
2525
}
2626
}
@@ -99,8 +99,7 @@ fn test_bpchar_params() {
9999
b CHAR(5)
100100
)", []));
101101
or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
102-
[&Some("12345") as &ToSql, &Some("123") as &ToSql,
103-
&None::<&'static str> as &ToSql]));
102+
&[&Some("12345"), &Some("123"), &None::<&'static str>]));
104103
let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id"));
105104
let res = or_fail!(stmt.query([]));
106105

@@ -345,7 +344,7 @@ fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
345344

346345
let nan: T = Float::nan();
347346
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice()));
348-
let mut result = or_fail!(stmt.query([&nan as &ToSql]));
347+
let mut result = or_fail!(stmt.query(&[&nan]));
349348
let val: T = result.next().unwrap().get(0u);
350349
assert!(val.is_nan())
351350
}

0 commit comments

Comments
 (0)