Skip to content

Commit 1e770c5

Browse files
author
Julius de Bruijn
authored
Fix clippy warnings (prisma#282)
* Deny clippy warnings * Fix clippy warnings
1 parent f0bd031 commit 1e770c5

File tree

20 files changed

+70
-92
lines changed

20 files changed

+70
-92
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
jobs:
88
clippy:
99
runs-on: ubuntu-latest
10+
env:
11+
RUSTFLAGS: "-Dwarnings"
1012
steps:
1113
- uses: actions/checkout@v1
1214
- uses: actions-rs/toolchain@v1

src/ast/compare.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ pub trait Comparable<'a> {
541541
/// # Ok(())
542542
/// # }
543543
/// ```
544+
#[allow(clippy::wrong_self_convention)]
544545
fn is_null(self) -> Compare<'a>;
545546

546547
/// Tests if the left side is not `NULL`.
@@ -555,6 +556,7 @@ pub trait Comparable<'a> {
555556
/// # Ok(())
556557
/// # }
557558
/// ```
559+
#[allow(clippy::wrong_self_convention)]
558560
fn is_not_null(self) -> Compare<'a>;
559561

560562
/// Tests if the value is between two given values.
@@ -754,12 +756,14 @@ where
754756
val.not_ends_into(pattern)
755757
}
756758

759+
#[allow(clippy::wrong_self_convention)]
757760
fn is_null(self) -> Compare<'a> {
758761
let col: Column<'a> = self.into();
759762
let val: Expression<'a> = col.into();
760763
val.is_null()
761764
}
762765

766+
#[allow(clippy::wrong_self_convention)]
763767
fn is_not_null(self) -> Compare<'a> {
764768
let col: Column<'a> = self.into();
765769
let val: Expression<'a> = col.into();

src/ast/expression.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub enum ExpressionKind<'a> {
165165
/// A nested `SELECT` or `SELECT .. UNION` statement
166166
Selection(SelectQuery<'a>),
167167
/// A database function call
168-
Function(Function<'a>),
168+
Function(Box<Function<'a>>),
169169
/// A qualified asterisk to a table
170170
Asterisk(Option<Box<Table<'a>>>),
171171
/// An operation: sum, sub, mul or div.
@@ -209,7 +209,15 @@ pub fn default_value() -> Expression<'static> {
209209
}
210210

211211
expression!(Row, Row);
212-
expression!(Function, Function);
212+
213+
impl<'a> From<Function<'a>> for Expression<'a> {
214+
fn from(f: Function<'a>) -> Self {
215+
Expression {
216+
kind: ExpressionKind::Function(Box::new(f)),
217+
alias: None,
218+
}
219+
}
220+
}
213221

214222
impl<'a> From<Raw<'a>> for Expression<'a> {
215223
fn from(r: Raw<'a>) -> Self {
@@ -377,10 +385,12 @@ impl<'a> Comparable<'a> for Expression<'a> {
377385
Compare::NotEndsInto(Box::new(self), pattern.into())
378386
}
379387

388+
#[allow(clippy::wrong_self_convention)]
380389
fn is_null(self) -> Compare<'a> {
381390
Compare::Null(Box::new(self))
382391
}
383392

393+
#[allow(clippy::wrong_self_convention)]
384394
fn is_not_null(self) -> Compare<'a> {
385395
Compare::NotNull(Box::new(self))
386396
}

src/ast/function/row_to_json.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ pub struct RowToJson<'a> {
2121
/// # async fn main() -> Result<(), quaint::error::Error> {
2222
/// # let conn = Quaint::new_in_memory()?;
2323
/// let cte = Select::default()
24-
/// .value(val!("hello_world").alias("toto"))
25-
/// .into_cte("one");
24+
/// .value(val!("hello_world").alias("toto"))
25+
/// .into_cte("one");
2626
///
2727
/// let select = Select::from_table("one")
28-
/// .value(row_to_json("one", false))
29-
/// .with(cte);
28+
/// .value(row_to_json("one", false))
29+
/// .with(cte);
3030
///
3131
/// let result = conn.select(select).await?;
3232
///
3333
/// assert_eq!(
34-
/// Value::Json(Some(serde_json::json!({
35-
/// "toto": "hello_world"
36-
/// }))),
37-
/// result.into_single().unwrap()[0]
34+
/// Value::Json(Some(serde_json::json!({
35+
/// "toto": "hello_world"
36+
/// }))),
37+
/// result.into_single().unwrap()[0]
3838
/// );
3939
/// # Ok(())
4040
/// # }

src/ast/row.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ impl<'a> Comparable<'a> for Row<'a> {
274274
value.not_ends_into(pattern)
275275
}
276276

277+
#[allow(clippy::wrong_self_convention)]
277278
fn is_null(self) -> Compare<'a> {
278279
let value: Expression<'a> = self.into();
279280
value.is_null()
280281
}
281282

283+
#[allow(clippy::wrong_self_convention)]
282284
fn is_not_null(self) -> Compare<'a> {
283285
let value: Expression<'a> = self.into();
284286
value.is_not_null()

src/ast/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl<'a> Select<'a> {
632632

633633
ctes.into_iter().collect()
634634
})
635-
.unwrap_or_else(|| Vec::new());
635+
.unwrap_or_else(Vec::new);
636636

637637
if top_level {
638638
let clashing_names = self
@@ -669,7 +669,7 @@ impl<'a> Select<'a> {
669669
ExpressionKind::Parameterized(_) => expr.alias.as_ref().map(|a| a.to_string()),
670670
_ => None,
671671
})
672-
.filter_map(|c| c)
672+
.flatten()
673673
.collect()
674674
}
675675
}

src/ast/table.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub trait Aliasable<'a> {
1919
/// Either an identifier or a nested query.
2020
pub enum TableType<'a> {
2121
Table(Cow<'a, str>),
22-
JoinedTable((Cow<'a, str>, Vec<Join<'a>>)),
23-
Query(Select<'a>),
22+
JoinedTable(Box<(Cow<'a, str>, Vec<Join<'a>>)>),
23+
Query(Box<Select<'a>>),
2424
Values(Values<'a>),
2525
}
2626

@@ -161,9 +161,9 @@ impl<'a> Table<'a> {
161161
{
162162
match self.typ {
163163
TableType::Table(table_name) => {
164-
self.typ = TableType::JoinedTable((table_name, vec![Join::Left(join.into())]))
164+
self.typ = TableType::JoinedTable(Box::new((table_name, vec![Join::Left(join.into())])))
165165
}
166-
TableType::JoinedTable((_, ref mut joins)) => joins.push(Join::Left(join.into())),
166+
TableType::JoinedTable(ref mut jt) => jt.1.push(Join::Left(join.into())),
167167
TableType::Query(_) => {
168168
panic!("You cannot left_join on a table of type Query")
169169
}
@@ -208,9 +208,9 @@ impl<'a> Table<'a> {
208208
{
209209
match self.typ {
210210
TableType::Table(table_name) => {
211-
self.typ = TableType::JoinedTable((table_name, vec![Join::Inner(join.into())]))
211+
self.typ = TableType::JoinedTable(Box::new((table_name, vec![Join::Inner(join.into())])))
212212
}
213-
TableType::JoinedTable((_, ref mut joins)) => joins.push(Join::Inner(join.into())),
213+
TableType::JoinedTable(ref mut jt) => jt.1.push(Join::Inner(join.into())),
214214
TableType::Query(_) => {
215215
panic!("You cannot inner_join on a table of type Query")
216216
}
@@ -255,9 +255,9 @@ impl<'a> Table<'a> {
255255
{
256256
match self.typ {
257257
TableType::Table(table_name) => {
258-
self.typ = TableType::JoinedTable((table_name, vec![Join::Right(join.into())]))
258+
self.typ = TableType::JoinedTable(Box::new((table_name, vec![Join::Right(join.into())])))
259259
}
260-
TableType::JoinedTable((_, ref mut joins)) => joins.push(Join::Right(join.into())),
260+
TableType::JoinedTable(ref mut jt) => jt.1.push(Join::Right(join.into())),
261261
TableType::Query(_) => {
262262
panic!("You cannot right_join on a table of type Query")
263263
}
@@ -302,9 +302,9 @@ impl<'a> Table<'a> {
302302
{
303303
match self.typ {
304304
TableType::Table(table_name) => {
305-
self.typ = TableType::JoinedTable((table_name, vec![Join::Full(join.into())]))
305+
self.typ = TableType::JoinedTable(Box::new((table_name, vec![Join::Full(join.into())])))
306306
}
307-
TableType::JoinedTable((_, ref mut joins)) => joins.push(Join::Full(join.into())),
307+
TableType::JoinedTable(ref mut jt) => jt.1.push(Join::Full(join.into())),
308308
TableType::Query(_) => {
309309
panic!("You cannot full_join on a table of type Query")
310310
}
@@ -405,7 +405,7 @@ impl<'a> From<(String, String)> for Table<'a> {
405405
impl<'a> From<Select<'a>> for Table<'a> {
406406
fn from(select: Select<'a>) -> Self {
407407
Table {
408-
typ: TableType::Query(select),
408+
typ: TableType::Query(Box::new(select)),
409409
alias: None,
410410
database: None,
411411
index_definitions: Vec::new(),

src/ast/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ impl<'a> Value<'a> {
453453
pub fn into_numeric(self) -> Option<BigDecimal> {
454454
match self {
455455
Value::Numeric(d) => d,
456-
Value::Float(f) => f.and_then(|f| BigDecimal::from_f32(f)),
457-
Value::Double(f) => f.and_then(|f| BigDecimal::from_f64(f)),
456+
Value::Float(f) => f.and_then(BigDecimal::from_f32),
457+
Value::Double(f) => f.and_then(BigDecimal::from_f64),
458458
_ => None,
459459
}
460460
}

src/connector/mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ impl MysqlUrl {
231231
connection_limit,
232232
use_ssl,
233233
socket,
234-
connect_timeout,
235234
socket_timeout,
235+
connect_timeout,
236236
pool_timeout,
237237
max_connection_lifetime,
238238
max_idle_connection_lifetime,

src/connector/mysql/conversion.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ pub fn conv_params<'a>(params: &[Value<'a>]) -> crate::Result<my::Params> {
3030
Value::Enum(s) => s.clone().map(|s| my::Value::Bytes((&*s).as_bytes().to_vec())),
3131
Value::Boolean(b) => b.map(|b| my::Value::Int(b as i64)),
3232
Value::Char(c) => c.map(|c| my::Value::Bytes(vec![c as u8])),
33-
Value::Xml(s) => match s {
34-
Some(ref s) => Some(my::Value::Bytes((s).as_bytes().to_vec())),
35-
None => None,
36-
},
33+
Value::Xml(s) => s.as_ref().map(|s| my::Value::Bytes((s).as_bytes().to_vec())),
3734
Value::Array(_) => {
3835
let msg = "Arrays are not supported in MySQL.";
3936
let kind = ErrorKind::conversion(msg);
@@ -44,10 +41,7 @@ pub fn conv_params<'a>(params: &[Value<'a>]) -> crate::Result<my::Params> {
4441
return Err(builder.build());
4542
}
4643
#[cfg(feature = "bigdecimal")]
47-
Value::Numeric(f) => match f {
48-
Some(f) => Some(my::Value::Bytes(f.to_string().as_bytes().to_vec())),
49-
None => None,
50-
},
44+
Value::Numeric(f) => f.as_ref().map(|f| my::Value::Bytes(f.to_string().as_bytes().to_vec())),
5145
#[cfg(feature = "json")]
5246
Value::Json(s) => match s {
5347
Some(ref s) => {

src/connector/mysql/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl From<my::Error> for Error {
138138
let user = message
139139
.split_whitespace()
140140
.nth(4)
141-
.and_then(|s| s.split('@').nth(0))
141+
.and_then(|s| s.split('@').next())
142142
.and_then(|s| s.split('\'').nth(1))
143143
.into();
144144

src/connector/postgres/conversion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'a> ToSql for Value<'a> {
503503
#[cfg(feature = "bigdecimal")]
504504
(Value::Integer(integer), &PostgresType::NUMERIC) => integer
505505
.map(|integer| BigDecimal::from_i64(integer).unwrap())
506-
.map(|bd| DecimalWrapper(bd))
506+
.map(DecimalWrapper)
507507
.map(|dw| dw.to_sql(ty, out)),
508508
(Value::Integer(integer), &PostgresType::TEXT) => {
509509
integer.map(|integer| format!("{}", integer).to_sql(ty, out))
@@ -549,7 +549,7 @@ impl<'a> ToSql for Value<'a> {
549549
v
550550
));
551551

552-
Err(Error::builder(kind).build())?
552+
return Err(Error::builder(kind).build().into());
553553
}
554554
};
555555

@@ -573,7 +573,7 @@ impl<'a> ToSql for Value<'a> {
573573
v
574574
));
575575

576-
Err(Error::builder(kind).build())?
576+
return Err(Error::builder(kind).build().into());
577577
}
578578
};
579579

src/connector/postgres/conversion/decimal.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn to_postgres(decimal: &BigDecimal) -> crate::Result<PostgresDecimal<Vec<i16>>>
8585
let remainder = 4 - groups_diff as u32;
8686
let power = 10u32.pow(remainder as u32) as u128;
8787

88-
mantissa = mantissa * power;
88+
mantissa *= power;
8989
}
9090

9191
// Array to store max mantissa of Decimal in Postgres decimal format.
@@ -116,8 +116,8 @@ fn to_postgres(decimal: &BigDecimal) -> crate::Result<PostgresDecimal<Vec<i16>>>
116116

117117
Ok(PostgresDecimal {
118118
neg,
119-
scale,
120119
weight,
120+
scale,
121121
digits,
122122
})
123123
}
@@ -204,10 +204,7 @@ impl<'a> FromSql<'a> for DecimalWrapper {
204204
}
205205

206206
fn accepts(ty: &Type) -> bool {
207-
match ty {
208-
&Type::NUMERIC => true,
209-
_ => false,
210-
}
207+
matches!(*ty, Type::NUMERIC)
211208
}
212209
}
213210

@@ -246,10 +243,7 @@ impl ToSql for DecimalWrapper {
246243
}
247244

248245
fn accepts(ty: &Type) -> bool {
249-
match ty {
250-
&Type::NUMERIC => true,
251-
_ => false,
252-
}
246+
matches!(*ty, Type::NUMERIC)
253247
}
254248

255249
to_sql_checked!();

src/connector/postgres/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl From<tokio_postgres::error::Error> for Error {
2929

3030
let constraint = detail
3131
.as_ref()
32-
.and_then(|d| d.split(")=(").nth(0))
32+
.and_then(|d| d.split(")=(").next())
3333
.and_then(|d| d.split(" (").nth(1).map(|s| s.replace("\"", "")))
3434
.map(|s| DatabaseConstraint::fields(s.split(", ")))
3535
.unwrap_or(DatabaseConstraint::CannotParse);

src/connector/result_set/result_row.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ impl ResultRow {
5656
/// Take a value with the given column name from the row. Usage
5757
/// documentation in [ResultRowRef](struct.ResultRowRef.html).
5858
pub fn get(&self, name: &str) -> Option<&Value<'static>> {
59-
if let Some(idx) = self.columns.iter().position(|c| c == name) {
60-
Some(&self.values[idx])
61-
} else {
62-
None
63-
}
59+
self.columns.iter().position(|c| c == name).map(|idx| &self.values[idx])
6460
}
6561

6662
/// Make a referring [ResultRowRef](struct.ResultRowRef.html).
@@ -110,10 +106,6 @@ impl<'a> ResultRowRef<'a> {
110106
/// assert_eq!(Some(&row["id"]), row.get("id"));
111107
/// ```
112108
pub fn get(&self, name: &str) -> Option<&Value<'static>> {
113-
if let Some(idx) = self.columns.iter().position(|c| c == name) {
114-
Some(&self.values[idx])
115-
} else {
116-
None
117-
}
109+
self.columns.iter().position(|c| c == name).map(|idx| &self.values[idx])
118110
}
119111
}

src/connector/sqlite/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl From<rusqlite::Error> for Error {
4545
.nth(1)
4646
.map(|s| s.split(", "))
4747
.map(|i| i.flat_map(|s| s.split('.').last()))
48-
.map(|i| DatabaseConstraint::fields(i))
48+
.map(DatabaseConstraint::fields)
4949
.unwrap_or(DatabaseConstraint::CannotParse);
5050

5151
let kind = ErrorKind::UniqueConstraintViolation { constraint };

0 commit comments

Comments
 (0)