Skip to content

Commit b51e658

Browse files
authored
Merge pull request #3185 from weiznich/fix/3182
Fix/3182
2 parents 4fe9876 + ecd6294 commit b51e658

File tree

57 files changed

+246
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+246
-179
lines changed

.github/workflows/ci.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ jobs:
369369
run: |
370370
sudo apt-get update
371371
sudo apt-get -y install libsqlite3-dev libpq-dev libmysqlclient-dev
372+
- name: Set environment variables
373+
shell: bash
374+
run: |
375+
echo "RUSTFLAGS=-D warnings" >> $GITHUB_ENV
376+
echo "RUSTDOCFLAGS=-D warnings" >> $GITHUB_ENV
372377
373378
- name: Remove potential newer clippy.toml from dependencies
374379
run: |
@@ -377,10 +382,46 @@ jobs:
377382
find ~/.cargo/registry -iname "*clippy.toml" -delete
378383
379384
- name: Run clippy
380-
uses: actions-rs/cargo@v1
381-
with:
382-
command: clippy
383-
args: --all
385+
run: |
386+
cargo clippy --tests --manifest-path diesel_derives/Cargo.toml --features "postgres diesel/postgres"
387+
cargo clippy --tests --manifest-path diesel/Cargo.toml --features "postgres"
388+
cargo clippy --tests --manifest-path diesel_dynamic_schema/Cargo.toml --features "postgres diesel/postgres"
389+
cargo clippy --tests --manifest-path diesel_migrations/migrations_internals/Cargo.toml
390+
cargo clippy --tests --manifest-path diesel_migrations/migrations_macros/Cargo.toml --features "postgres diesel/postgres"
391+
cargo clippy --tests --manifest-path diesel_migrations/Cargo.toml --features "postgres diesel/postgres"
392+
cargo clippy --tests --manifest-path diesel_cli/Cargo.toml --features "postgres" --no-default-features
393+
cargo clippy --tests --manifest-path diesel_tests/Cargo.toml --features "postgres"
394+
cargo clippy --tests --manifest-path examples/postgres/getting_started_step_1/Cargo.toml
395+
cargo clippy --tests --manifest-path examples/postgres/getting_started_step_2/Cargo.toml
396+
cargo clippy --tests --manifest-path examples/postgres/getting_started_step_3/Cargo.toml
397+
cargo clippy --tests --manifest-path examples/postgres/advanced-blog-cli/Cargo.toml
398+
cargo clippy --tests --manifest-path examples/postgres/all_about_inserts/Cargo.toml
399+
cargo clippy --tests --manifest-path examples/postgres/all_about_updates/Cargo.toml
400+
cargo clippy --tests --manifest-path examples/postgres/custom_types/Cargo.toml
401+
402+
cargo clippy --tests --manifest-path diesel_derives/Cargo.toml --features "sqlite diesel/sqlite"
403+
cargo clippy --tests --manifest-path diesel/Cargo.toml --features "sqlite"
404+
cargo clippy --tests --manifest-path diesel_dynamic_schema/Cargo.toml --features "sqlite diesel/sqlite"
405+
cargo clippy --tests --manifest-path diesel_migrations/migrations_macros/Cargo.toml --features "sqlite diesel/sqlite"
406+
cargo clippy --tests --manifest-path diesel_migrations/Cargo.toml --features "sqlite diesel/sqlite"
407+
cargo clippy --tests --manifest-path diesel_cli/Cargo.toml --features "sqlite" --no-default-features
408+
cargo clippy --tests --manifest-path diesel_tests/Cargo.toml --features "sqlite"
409+
cargo clippy --tests --manifest-path examples/sqlite/getting_started_step_1/Cargo.toml
410+
cargo clippy --tests --manifest-path examples/sqlite/getting_started_step_2/Cargo.toml
411+
cargo clippy --tests --manifest-path examples/sqlite/getting_started_step_3/Cargo.toml
412+
cargo clippy --tests --manifest-path examples/sqlite/all_about_inserts/Cargo.toml
413+
414+
cargo clippy --tests --manifest-path diesel_derives/Cargo.toml --features "mysql diesel/mysql"
415+
cargo clippy --tests --manifest-path diesel/Cargo.toml --features "mysql"
416+
cargo clippy --tests --manifest-path diesel_dynamic_schema/Cargo.toml --features "mysql diesel/mysql"
417+
cargo clippy --tests --manifest-path diesel_migrations/migrations_macros/Cargo.toml --features "mysql diesel/mysql"
418+
cargo clippy --tests --manifest-path diesel_migrations/Cargo.toml --features "mysql diesel/mysql"
419+
cargo clippy --tests --manifest-path diesel_cli/Cargo.toml --features "mysql" --no-default-features
420+
cargo clippy --tests --manifest-path diesel_tests/Cargo.toml --features "mysql"
421+
cargo clippy --tests --manifest-path examples/mysql/getting_started_step_1/Cargo.toml
422+
cargo clippy --tests --manifest-path examples/mysql/getting_started_step_2/Cargo.toml
423+
cargo clippy --tests --manifest-path examples/mysql/getting_started_step_3/Cargo.toml
424+
cargo clippy --tests --manifest-path examples/mysql/all_about_inserts/Cargo.toml
384425
385426
- name: Check formating
386427
uses: actions-rs/cargo@v1

diesel/src/connection/transaction_manager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ mod test {
672672

673673
#[test]
674674
#[cfg(feature = "mysql")]
675+
// This function uses a collect with side effects (spawning threads)
676+
// so clippy is wrong here
677+
#[allow(clippy::needless_collect)]
675678
fn mysql_transaction_depth_commits_tracked_properly_on_serialization_failure() {
676679
use crate::result::DatabaseErrorKind::SerializationFailure;
677680
use crate::result::Error::DatabaseError;
@@ -775,6 +778,9 @@ mod test {
775778

776779
#[test]
777780
#[cfg(feature = "mysql")]
781+
// This function uses a collect with side effects (spawning threads)
782+
// so clippy is wrong here
783+
#[allow(clippy::needless_collect)]
778784
fn mysql_nested_transaction_depth_commits_tracked_properly_on_serialization_failure() {
779785
use crate::result::DatabaseErrorKind::SerializationFailure;
780786
use crate::result::Error::DatabaseError;

diesel/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
clippy::redundant_field_names,
179179
clippy::type_complexity
180180
)]
181-
#![cfg_attr(test, allow(clippy::option_map_unwrap_or, clippy::result_unwrap_used))]
182181
#![warn(
183182
clippy::unwrap_used,
184183
clippy::print_stdout,
@@ -191,6 +190,7 @@
191190
clippy::items_after_statements,
192191
clippy::used_underscore_binding
193192
)]
193+
#![cfg_attr(test, allow(clippy::map_unwrap_or, clippy::unwrap_used))]
194194

195195
extern crate diesel_derives;
196196

diesel/src/mysql/connection/bind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,15 +1289,15 @@ mod tests {
12891289

12901290
#[test]
12911291
fn check_json_bind() {
1292-
let conn = &mut crate::test_helpers::connection();
1293-
12941292
table! {
12951293
json_test {
12961294
id -> Integer,
12971295
json_field -> Text,
12981296
}
12991297
}
13001298

1299+
let conn = &mut crate::test_helpers::connection();
1300+
13011301
crate::sql_query("DROP TABLE IF EXISTS json_test CASCADE")
13021302
.execute(conn)
13031303
.unwrap();

diesel/src/mysql/query_builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl QueryBuilder<Mysql> for MysqlQueryBuilder {
2626

2727
fn push_identifier(&mut self, identifier: &str) -> QueryResult<()> {
2828
self.push_sql("`");
29-
self.push_sql(&identifier.replace("`", "``"));
29+
self.push_sql(&identifier.replace('`', "``"));
3030
self.push_sql("`");
3131
Ok(())
3232
}

diesel/src/mysql/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::deserialize;
44
use std::error::Error;
55

66
/// Raw mysql value as received from the database
7-
#[derive(Copy, Clone, Debug)]
7+
#[derive(Clone, Debug)]
88
pub struct MysqlValue<'a> {
99
raw: &'a [u8],
1010
tpe: MysqlType,

diesel/src/pg/connection/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,8 @@ mod tests {
273273
let query =
274274
crate::sql_query("SELECT not_existent FROM also_not_there;").execute(connection);
275275

276-
if let Err(err) = query {
277-
if let DatabaseError(_, string) = err {
278-
assert_eq!(Some(26), string.statement_position());
279-
} else {
280-
unreachable!();
281-
}
276+
if let Err(DatabaseError(_, string)) = query {
277+
assert_eq!(Some(26), string.statement_position());
282278
} else {
283279
unreachable!();
284280
}
@@ -367,14 +363,14 @@ mod tests {
367363
let insert = query
368364
.insert_into(users::table)
369365
.into_columns((users::id, users::name));
370-
assert_eq!(true, insert.execute(connection).is_ok());
366+
assert!(insert.execute(connection).is_ok());
371367
assert_eq!(1, connection.statement_cache.len());
372368

373369
let query = users::table.filter(users::id.eq(42)).into_boxed();
374370
let insert = query
375371
.insert_into(users::table)
376372
.into_columns((users::id, users::name));
377-
assert_eq!(true, insert.execute(connection).is_ok());
373+
assert!(insert.execute(connection).is_ok());
378374
assert_eq!(2, connection.statement_cache.len());
379375
}
380376

@@ -392,7 +388,7 @@ mod tests {
392388
let insert =
393389
crate::insert_into(users::table).values((users::id.eq(42), users::name.eq("Foo")));
394390

395-
assert_eq!(true, insert.execute(connection).is_ok());
391+
assert!(insert.execute(connection).is_ok());
396392
assert_eq!(1, connection.statement_cache.len());
397393
}
398394

@@ -410,7 +406,7 @@ mod tests {
410406
let insert = crate::insert_into(users::table)
411407
.values(vec![(users::id.eq(42), users::name.eq("Foo"))]);
412408

413-
assert_eq!(true, insert.execute(connection).is_ok());
409+
assert!(insert.execute(connection).is_ok());
414410
assert_eq!(0, connection.statement_cache.len());
415411
}
416412

@@ -428,7 +424,7 @@ mod tests {
428424
let insert =
429425
crate::insert_into(users::table).values([(users::id.eq(42), users::name.eq("Foo"))]);
430426

431-
assert_eq!(true, insert.execute(connection).is_ok());
427+
assert!(insert.execute(connection).is_ok());
432428
assert_eq!(1, connection.statement_cache.len());
433429
}
434430

@@ -585,6 +581,9 @@ mod tests {
585581
}
586582

587583
#[test]
584+
// This function uses collect with an side effect (spawning threads)
585+
// so this is a false positive from clippy
586+
#[allow(clippy::needless_collect)]
588587
fn postgres_transaction_depth_is_tracked_properly_on_serialization_failure() {
589588
use crate::pg::connection::raw::PgTransactionStatus;
590589
use crate::result::DatabaseErrorKind::SerializationFailure;
@@ -692,6 +691,9 @@ mod tests {
692691
}
693692

694693
#[test]
694+
// This function uses collect with an side effect (spawning threads)
695+
// so this is a false positive from clippy
696+
#[allow(clippy::needless_collect)]
695697
fn postgres_transaction_depth_is_tracked_properly_on_nested_serialization_failure() {
696698
use crate::pg::connection::raw::PgTransactionStatus;
697699
use crate::result::DatabaseErrorKind::SerializationFailure;

diesel/src/pg/expression/extensions/interval_dsl.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ impl IntervalDsl for f64 {
242242
}
243243

244244
#[cfg(test)]
245+
// those macros define nested function
246+
// that's fine for this test code
247+
#[allow(clippy::items_after_statements)]
245248
mod tests {
246249
extern crate dotenvy;
247250
extern crate quickcheck;

diesel/src/pg/types/array.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ use crate::expression::AsExpression;
6464
macro_rules! array_as_expression {
6565
($ty:ty, $sql_type:ty) => {
6666
#[cfg(feature = "postgres_backend")]
67+
// this simplifies the macro implemntation
68+
// as some macro calls use this lifetime
69+
#[allow(clippy::extra_unused_lifetimes)]
6770
impl<'a, 'b, ST: 'static, T> AsExpression<$sql_type> for $ty {
6871
type Expression = Bound<$sql_type, Self>;
6972

diesel/src/pg/types/date_and_time/std_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl FromSql<sql_types::Timestamp, Pg> for SystemTime {
3131
fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> {
3232
let usecs_passed = <i64 as FromSql<sql_types::BigInt, Pg>>::from_sql(bytes)?;
3333
let before_epoch = usecs_passed < 0;
34-
let time_passed = usecs_to_duration(usecs_passed.abs() as u64);
34+
let time_passed = usecs_to_duration(usecs_passed.unsigned_abs());
3535

3636
if before_epoch {
3737
Ok(pg_epoch() - time_passed)

diesel/src/query_builder/select_statement/dsl_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ where
604604
}
605605
}
606606

607-
impl<'a, F, S, D, W, O, LOf, G, H> SelectNullableDsl
607+
impl<F, S, D, W, O, LOf, G, H> SelectNullableDsl
608608
for SelectStatement<F, SelectClause<S>, D, W, O, LOf, G, H>
609609
{
610610
type Output = SelectStatement<F, SelectClause<Nullable<S>>, D, W, O, LOf, G, H>;
@@ -624,7 +624,7 @@ impl<'a, F, S, D, W, O, LOf, G, H> SelectNullableDsl
624624
}
625625
}
626626

627-
impl<'a, F, D, W, O, LOf, G, H> SelectNullableDsl
627+
impl<F, D, W, O, LOf, G, H> SelectNullableDsl
628628
for SelectStatement<F, DefaultSelectClause<F>, D, W, O, LOf, G, H>
629629
where
630630
F: AsQuerySource,

diesel/src/query_source/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub trait QuerySource {
3232

3333
/// The actual `FROM` clause of this type. This is typically only called in
3434
/// `QueryFragment` implementations.
35+
// from here is something different than from in rust
36+
// as this literally refercs to SQL from.
37+
#[allow(clippy::wrong_self_convention)]
3538
fn from_clause(&self) -> Self::FromClause;
3639
/// The default select clause of this type, which should be used if no
3740
/// select clause was explicitly specified. This should always be a tuple of

diesel/src/sqlite/connection/functions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ where
9696
Args::build_from_row(&row).map_err(Error::DeserializationError)
9797
}
9898

99+
// clippy is wrong here, the let binding is required
100+
// for lifetime reasons
101+
#[allow(clippy::let_unit_value)]
99102
pub(super) fn process_sql_function_result<RetSqlType, Ret>(
100103
result: &'_ Ret,
101104
) -> QueryResult<InternalSqliteBindValue<'_>>

diesel/src/sqlite/connection/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ mod tests {
456456
#[test]
457457
fn register_noarg_function() {
458458
let connection = &mut SqliteConnection::establish(":memory:").unwrap();
459-
answer::register_impl(&connection, || 42).unwrap();
459+
answer::register_impl(connection, || 42).unwrap();
460460

461461
let answer = crate::select(answer()).get_result::<i32>(connection);
462462
assert_eq!(Ok(42), answer);
@@ -465,7 +465,7 @@ mod tests {
465465
#[test]
466466
fn register_nondeterministic_noarg_function() {
467467
let connection = &mut SqliteConnection::establish(":memory:").unwrap();
468-
answer::register_nondeterministic_impl(&connection, || 42).unwrap();
468+
answer::register_nondeterministic_impl(connection, || 42).unwrap();
469469

470470
let answer = crate::select(answer()).get_result::<i32>(connection);
471471
assert_eq!(Ok(42), answer);

diesel/src/sqlite/connection/raw.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ extern "C" fn run_aggregator_final_function<ArgsSqlType, RetSqlType, Args, Ret,
475475
});
476476
if let Err(e) = result {
477477
e.emit(ctx);
478-
return;
479478
}
480479
}
481480

diesel/src/sqlite/query_builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl QueryBuilder<Sqlite> for SqliteQueryBuilder {
2727

2828
fn push_identifier(&mut self, identifier: &str) -> QueryResult<()> {
2929
self.push_sql("`");
30-
self.push_sql(&identifier.replace("`", "``"));
30+
self.push_sql(&identifier.replace('`', "``"));
3131
self.push_sql("`");
3232
Ok(())
3333
}

diesel_cli/src/infer_schema_internals/inference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn get_column_information(
9797
}
9898
};
9999
if let Err(NotFound) = column_info {
100-
Err(format!("no table exists named {}", table.to_string()).into())
100+
Err(format!("no table exists named {}", table).into())
101101
} else {
102102
column_info.map_err(Into::into)
103103
}
@@ -137,7 +137,7 @@ pub(crate) fn get_primary_keys(
137137
Err(format!(
138138
"Diesel only supports tables with primary keys. \
139139
Table {} has no primary key",
140-
table.to_string()
140+
table,
141141
)
142142
.into())
143143
} else {

diesel_cli/src/infer_schema_internals/information_schema.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ mod tests {
559559
let id = ColumnInformation::new("id", "int4", pg_catalog.clone(), false);
560560
let text_col = ColumnInformation::new("text_col", "varchar", pg_catalog.clone(), true);
561561
let not_null = ColumnInformation::new("not_null", "text", pg_catalog.clone(), false);
562-
let array_col = ColumnInformation::new("array_col", "_varchar", pg_catalog.clone(), false);
562+
let array_col = ColumnInformation::new("array_col", "_varchar", pg_catalog, false);
563563
assert_eq!(
564564
Ok(vec![id, text_col, not_null]),
565565
get_table_data(&mut connection, &table_1, &ColumnSorting::OrdinalPosition)
@@ -594,14 +594,14 @@ mod tests {
594594
let table_3 = TableName::new("table_3", "test_schema");
595595
let fk_one = ForeignKeyConstraint {
596596
child_table: table_2.clone(),
597-
parent_table: table_1.clone(),
597+
parent_table: table_1,
598598
foreign_key: "fk_one".into(),
599599
foreign_key_rust_name: "fk_one".into(),
600600
primary_key: "id".into(),
601601
};
602602
let fk_two = ForeignKeyConstraint {
603-
child_table: table_3.clone(),
604-
parent_table: table_2.clone(),
603+
child_table: table_3,
604+
parent_table: table_2,
605605
foreign_key: "fk_two".into(),
606606
foreign_key_rust_name: "fk_two".into(),
607607
primary_key: "id".into(),

diesel_cli/src/infer_schema_internals/sqlite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,14 @@ fn load_foreign_key_constraints_loads_foreign_keys() {
368368
let table_3 = TableName::from_name("table_3");
369369
let fk_one = ForeignKeyConstraint {
370370
child_table: table_2.clone(),
371-
parent_table: table_1.clone(),
371+
parent_table: table_1,
372372
foreign_key: "fk_one".into(),
373373
foreign_key_rust_name: "fk_one".into(),
374374
primary_key: "id".into(),
375375
};
376376
let fk_two = ForeignKeyConstraint {
377-
child_table: table_3.clone(),
378-
parent_table: table_2.clone(),
377+
child_table: table_3,
378+
parent_table: table_2,
379379
foreign_key: "fk_two".into(),
380380
foreign_key_rust_name: "fk_two".into(),
381381
primary_key: "id".into(),

diesel_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
clippy::used_underscore_binding,
1212
missing_copy_implementations
1313
)]
14-
#![cfg_attr(test, allow(clippy::result_unwrap_used))]
14+
#![cfg_attr(test, allow(clippy::unwrap_used))]
1515

1616
mod config;
1717

0 commit comments

Comments
 (0)