Skip to content

Commit aed188e

Browse files
authored
Enable clippy::nursery (#938)
## PR Info I’ve enabled `clippy::nursery`, which helps us write more readable code. for example, from: ``` if from.is_empty() { self.prepare_iden(column, sql); } else { if let Some(table) = table { if let TableRef::Table(table) = table.deref() { self.prepare_column_ref( &ColumnRef::TableColumn(table.clone(), column.clone()), sql, ); return; } } self.prepare_iden(column, sql); } ``` to: ```rust if !from.is_empty() && let Some(table) = table && let TableRef::Table(table) = table.deref() { self.prepare_column_ref(&ColumnRef::TableColumn(table.clone(), column.clone()), sql); } else { self.prepare_iden(column, sql); } ``` ## Changes - [x] Some functions are marked as const
1 parent 6c1faf2 commit aed188e

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

rust-toolchain.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[toolchain]
2+
channel = "1.85"
3+
components = [
4+
"rustfmt",
5+
"clippy",
6+
]

src/backend/mysql/query.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ impl QueryBuilder for MysqlQueryBuilder {
9292
) {
9393
use std::ops::Deref;
9494

95-
if from.is_empty() {
96-
self.prepare_iden(column, sql);
97-
} else {
95+
if !from.is_empty() {
9896
if let Some(table) = table {
9997
// Support only "naked" table names with no schema or alias.
10098
if let TableRef::Table(TableName(None, table), None) = table.deref() {
@@ -103,8 +101,8 @@ impl QueryBuilder for MysqlQueryBuilder {
103101
return;
104102
}
105103
}
106-
self.prepare_iden(column, sql);
107104
}
105+
self.prepare_iden(column, sql)
108106
}
109107

110108
fn prepare_update_condition(

src/backend/postgres/table.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,12 @@ impl PostgresQueryBuilder {
262262
.spec
263263
.iter()
264264
.position(|s| matches!(s, ColumnSpec::AutoIncrement));
265+
266+
write!(sql, " ").unwrap();
267+
265268
if is_auto_increment.is_some() {
266-
write!(sql, " ").unwrap();
267269
self.prepare_column_auto_increment(column_type, sql);
268270
} else {
269-
write!(sql, " ").unwrap();
270271
self.prepare_column_type(column_type, sql);
271272
}
272273
}
@@ -281,7 +282,7 @@ impl PostgresQueryBuilder {
281282
f(column_def, sql);
282283

283284
for column_spec in column_def.spec.iter() {
284-
if let ColumnSpec::AutoIncrement = column_spec {
285+
if matches!(column_spec, ColumnSpec::AutoIncrement) {
285286
continue;
286287
}
287288
if let ColumnSpec::Comment(_) = column_spec {

src/backend/sqlite/table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ impl TableBuilder for SqliteQueryBuilder {
1313
let mut is_auto_increment = false;
1414

1515
for column_spec in column_def.spec.iter() {
16-
if let ColumnSpec::PrimaryKey = column_spec {
16+
if matches!(column_spec, ColumnSpec::PrimaryKey) {
1717
is_primary_key = true;
1818
continue;
1919
}
20-
if let ColumnSpec::AutoIncrement = column_spec {
20+
if matches!(column_spec, ColumnSpec::AutoIncrement) {
2121
is_auto_increment = true;
2222
continue;
2323
}

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#![cfg_attr(docsrs, feature(doc_cfg))]
2+
#![warn(clippy::nursery)]
23
#![deny(missing_debug_implementations)]
34
#![forbid(unsafe_code)]
5+
#![allow(
6+
clippy::derive_partial_eq_without_eq,
7+
clippy::option_if_let_else,
8+
clippy::redundant_pub_crate,
9+
clippy::use_self,
10+
clippy::missing_const_for_fn
11+
)]
412

513
//! <div align="center">
614
//!

src/query/select.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,7 @@ impl SelectStatement {
592592
T: IntoColumnRef,
593593
I: IntoIterator<Item = T>,
594594
{
595-
self.exprs(
596-
cols.into_iter()
597-
.map(|c| Expr::Column(c.into_column_ref()))
598-
.collect::<Vec<Expr>>(),
599-
)
595+
self.exprs(cols.into_iter().map(|c| Expr::Column(c.into_column_ref())))
600596
}
601597

602598
/// Select column.
@@ -1794,11 +1790,7 @@ impl SelectStatement {
17941790
T: IntoColumnRef,
17951791
I: IntoIterator<Item = T>,
17961792
{
1797-
self.add_group_by(
1798-
cols.into_iter()
1799-
.map(|c| Expr::Column(c.into_column_ref()))
1800-
.collect::<Vec<_>>(),
1801-
)
1793+
self.add_group_by(cols.into_iter().map(|c| Expr::Column(c.into_column_ref())))
18021794
}
18031795

18041796
/// Add a group by column.

src/query/with.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,10 @@ impl Search {
242242
}
243243
}
244244

245-
/// For recursive [WithQuery] [WithClause]s the CYCLE sql clause can be specified to avoid creating
246-
/// an infinite traversals that loops on graph cycles indefinitely. You specify an expression that
247-
/// identifies a node in the graph and that will be used to determine during the iteration of
248-
/// the execution of the query when appending of new values whether the new values are distinct new
249-
/// nodes or are already visited and therefore they should be added again into the result.
245+
/// For recursive [WithQuery] [WithClauses](WithClause) the CYCLE sql clause can be specified to avoid creating
246+
/// an infinite traversals that loops on graph cycles indefinitely.
247+
///
248+
/// You specify an expression that identifies a node in the graph, which is used during the query execution iteration, to determine newly appended values are distinct new nodes or are already visited, and therefore they should be added into the result again.
250249
///
251250
/// A query can have both SEARCH and CYCLE clauses.
252251
///

src/value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ pub enum Value {
320320
}
321321

322322
/// This test is to check if the size of [`Value`] exceeds the limit.
323+
///
323324
/// If the size exceeds the limit, you should box the variant.
324325
/// Previously, the size was 24. We bumped it to 32 such that `String`
325326
/// can be unboxed.

0 commit comments

Comments
 (0)