From 523bd35be53299a5aee1df7e94680afb37d7cb06 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Mon, 7 Nov 2022 14:01:02 +0100 Subject: [PATCH 1/3] Rust toolchain update --- diesel/src/connection/statement_cache.rs | 4 +-- diesel/src/connection/transaction_manager.rs | 6 ++--- diesel/src/expression/mod.rs | 28 +++++--------------- diesel/src/query_builder/ast_pass.rs | 13 ++++----- diesel/src/serialize.rs | 2 +- diesel_derives/tests/queryable_by_name.rs | 2 +- rust-toolchain | 2 +- 7 files changed, 22 insertions(+), 35 deletions(-) diff --git a/diesel/src/connection/statement_cache.rs b/diesel/src/connection/statement_cache.rs index f37f5b775a90..6ca0c8c1bc33 100644 --- a/diesel/src/connection/statement_cache.rs +++ b/diesel/src/connection/statement_cache.rs @@ -237,7 +237,7 @@ impl<'a, T> Deref for MaybeCached<'a, T> { fn deref(&self) -> &Self::Target { match *self { MaybeCached::CannotCache(ref x) => x, - MaybeCached::Cached(ref x) => &**x, + MaybeCached::Cached(ref x) => x, } } } @@ -246,7 +246,7 @@ impl<'a, T> DerefMut for MaybeCached<'a, T> { fn deref_mut(&mut self) -> &mut Self::Target { match *self { MaybeCached::CannotCache(ref mut x) => x, - MaybeCached::Cached(ref mut x) => &mut **x, + MaybeCached::Cached(ref mut x) => x, } } } diff --git a/diesel/src/connection/transaction_manager.rs b/diesel/src/connection/transaction_manager.rs index cc3c6883c78c..3e4e97546f12 100644 --- a/diesel/src/connection/transaction_manager.rs +++ b/diesel/src/connection/transaction_manager.rs @@ -322,7 +322,7 @@ where Cow::from(format!("SAVEPOINT diesel_savepoint_{}", transaction_depth)) } }; - conn.batch_execute(&*start_transaction_sql)?; + conn.batch_execute(&start_transaction_sql)?; Self::get_transaction_state(conn)? .change_transaction_depth(TransactionDepthChange::IncreaseDepth)?; @@ -362,7 +362,7 @@ where None => return Err(Error::NotInTransaction), }; - match conn.batch_execute(&*rollback_sql) { + match conn.batch_execute(&rollback_sql) { Ok(()) => { Self::get_transaction_state(conn)? .change_transaction_depth(TransactionDepthChange::DecreaseDepth)?; @@ -410,7 +410,7 @@ where transaction_depth.get() - 1 )), }; - match conn.batch_execute(&*commit_sql) { + match conn.batch_execute(&commit_sql) { Ok(()) => { Self::get_transaction_state(conn)? .change_transaction_depth(TransactionDepthChange::DecreaseDepth)?; diff --git a/diesel/src/expression/mod.rs b/diesel/src/expression/mod.rs index 470b4ebc040f..7792b3bbeba7 100644 --- a/diesel/src/expression/mod.rs +++ b/diesel/src/expression/mod.rs @@ -569,28 +569,14 @@ pub mod is_aggregate { } } -// Note that these docs are similar to but slightly different than the stable -// docs below. Make sure if you change these that you also change the docs -// below. -/// Trait alias to represent an expression that isn't aggregate by default. -/// -/// This alias represents a type which is not aggregate if there is no group by -/// clause. More specifically, it represents for types which implement -/// [`ValidGrouping<()>`] where `IsAggregate` is [`is_aggregate::No`] or -/// [`is_aggregate::Yes`]. -/// -/// While this trait is a useful stand-in for common cases, `T: NonAggregate` -/// cannot always be used when `T: ValidGrouping<(), IsAggregate = No>` or -/// `T: ValidGrouping<(), IsAggregate = Never>` could be. For that reason, -/// unless you need to abstract over both columns and literals, you should -/// prefer to use [`ValidGrouping<()>`] in your bounds instead. -/// -/// [`ValidGrouping<()>`]: ValidGrouping #[cfg(feature = "unstable")] -pub trait NonAggregate = ValidGrouping<()> -where - >::IsAggregate: - MixedAggregates; +// this needs to be a seperate module for the reasons given in +// https://github.com/rust-lang/rust/issues/65860 +mod unstable; + +#[cfg(feature = "unstable")] +#[doc(inline)] +pub use self::unstable::NonAggregate; // Note that these docs are similar to but slightly different than the unstable // docs above. Make sure if you change these that you also change the docs diff --git a/diesel/src/query_builder/ast_pass.rs b/diesel/src/query_builder/ast_pass.rs index a67fb350d0ec..1b5c80311f61 100644 --- a/diesel/src/query_builder/ast_pass.rs +++ b/diesel/src/query_builder/ast_pass.rs @@ -104,23 +104,24 @@ where /// done implicitly for references. For structs with lifetimes it must be /// done explicitly. This method matches the semantics of what Rust would do /// implicitly if you were passing a mutable reference + #[allow(clippy::explicit_auto_deref)] // clippy is wrong here pub fn reborrow(&'_ mut self) -> AstPass<'_, 'b, DB> { let internals = match self.internals { AstPassInternals::ToSql(ref mut builder, ref mut options) => { - AstPassInternals::ToSql(&mut **builder, &mut **options) + AstPassInternals::ToSql(*builder, options) } AstPassInternals::CollectBinds { ref mut collector, ref mut metadata_lookup, } => AstPassInternals::CollectBinds { - collector: &mut **collector, - metadata_lookup: &mut **metadata_lookup, + collector: *collector, + metadata_lookup: *metadata_lookup, }, AstPassInternals::IsSafeToCachePrepared(ref mut result) => { - AstPassInternals::IsSafeToCachePrepared(&mut **result) + AstPassInternals::IsSafeToCachePrepared(result) } - AstPassInternals::DebugBinds(ref mut f) => AstPassInternals::DebugBinds(&mut **f), - AstPassInternals::IsNoop(ref mut result) => AstPassInternals::IsNoop(&mut **result), + AstPassInternals::DebugBinds(ref mut f) => AstPassInternals::DebugBinds(f), + AstPassInternals::IsNoop(ref mut result) => AstPassInternals::IsNoop(result), }; AstPass { internals, diff --git a/diesel/src/serialize.rs b/diesel/src/serialize.rs index eeb2f319239c..62a54c0ab1d4 100644 --- a/diesel/src/serialize.rs +++ b/diesel/src/serialize.rs @@ -65,7 +65,7 @@ impl<'a, 'b, DB: Backend> Output<'a, 'b, DB> { /// Returns the backend's mechanism for dynamically looking up type /// metadata at runtime, if relevant for the given backend. pub fn metadata_lookup(&mut self) -> &mut DB::MetadataLookup { - *self.metadata_lookup.as_mut().expect("Lookup is there") + self.metadata_lookup.as_mut().expect("Lookup is there") } /// Set the inner buffer to a specific value diff --git a/diesel_derives/tests/queryable_by_name.rs b/diesel_derives/tests/queryable_by_name.rs index 9ccecffca622..875f89a098b8 100644 --- a/diesel_derives/tests/queryable_by_name.rs +++ b/diesel_derives/tests/queryable_by_name.rs @@ -1,4 +1,4 @@ -#![allow(clippy::blacklisted_name)] +#![allow(clippy::disallowed_names)] use diesel::sql_types::Integer; use diesel::*; diff --git a/rust-toolchain b/rust-toolchain index 9405730420ff..902c74186fb6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.64.0 +1.65.0 From f08f0aecfa8cad56ff35e6cfdb60586b467cc65f Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Mon, 7 Nov 2022 14:56:20 +0100 Subject: [PATCH 2/3] More clippy fixes --- diesel/src/expression/unstable.rs | 21 +++++++++++++++++++++ diesel/src/mysql/connection/bind.rs | 2 +- diesel/src/mysql/connection/url.rs | 2 +- diesel/src/mysql/types/mod.rs | 2 +- diesel_cli/src/database.rs | 2 +- diesel_cli/tests/migration_run.rs | 4 ++-- diesel_cli/tests/support/command.rs | 2 +- 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 diesel/src/expression/unstable.rs diff --git a/diesel/src/expression/unstable.rs b/diesel/src/expression/unstable.rs new file mode 100644 index 000000000000..df2b8da2faeb --- /dev/null +++ b/diesel/src/expression/unstable.rs @@ -0,0 +1,21 @@ +// Note that these docs are similar to but slightly different than the stable +// docs below. Make sure if you change these that you also change the docs +// below. +/// Trait alias to represent an expression that isn't aggregate by default. +/// +/// This alias represents a type which is not aggregate if there is no group by +/// clause. More specifically, it represents for types which implement +/// [`ValidGrouping<()>`] where `IsAggregate` is [`is_aggregate::No`] or +/// [`is_aggregate::Yes`]. +/// +/// While this trait is a useful stand-in for common cases, `T: NonAggregate` +/// cannot always be used when `T: ValidGrouping<(), IsAggregate = No>` or +/// `T: ValidGrouping<(), IsAggregate = Never>` could be. For that reason, +/// unless you need to abstract over both columns and literals, you should +/// prefer to use [`ValidGrouping<()>`] in your bounds instead. +/// +/// [`ValidGrouping<()>`]: ValidGrouping +pub trait NonAggregate = ValidGrouping<()> +where + >::IsAggregate: + MixedAggregates; diff --git a/diesel/src/mysql/connection/bind.rs b/diesel/src/mysql/connection/bind.rs index dfdb7676ef72..98ea8e434339 100644 --- a/diesel/src/mysql/connection/bind.rs +++ b/diesel/src/mysql/connection/bind.rs @@ -220,7 +220,7 @@ impl Drop for BindData { impl BindData { fn for_input((tpe, data): (MysqlType, Option>)) -> Self { let (tpe, flags) = tpe.into(); - let is_null = if data.is_none() { 1 } else { 0 }; + let is_null = i8::from(data.is_none()); let mut bytes = data.unwrap_or_default(); let ptr = NonNull::new(bytes.as_mut_ptr()); let len = bytes.len() as libc::c_ulong; diff --git a/diesel/src/mysql/connection/url.rs b/diesel/src/mysql/connection/url.rs index cc922840453b..218531180363 100644 --- a/diesel/src/mysql/connection/url.rs +++ b/diesel/src/mysql/connection/url.rs @@ -102,7 +102,7 @@ impl ConnectionOptions { let host = match url.host() { Some(Host::Ipv6(host)) => Some(CString::new(host.to_string())?), - Some(host) if host.to_string() == "localhost" && unix_socket != None => None, + Some(host) if host.to_string() == "localhost" && unix_socket.is_some() => None, Some(host) => Some(CString::new(host.to_string())?), None => None, }; diff --git a/diesel/src/mysql/types/mod.rs b/diesel/src/mysql/types/mod.rs index c60a8fc0e53b..d52d32afe228 100644 --- a/diesel/src/mysql/types/mod.rs +++ b/diesel/src/mysql/types/mod.rs @@ -129,7 +129,7 @@ impl FromSql, Mysql> for u64 { #[cfg(feature = "mysql_backend")] impl ToSql for bool { fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Mysql>) -> serialize::Result { - let int_value = if *self { 1 } else { 0 }; + let int_value = i32::from(*self); >::to_sql(&int_value, &mut out.reborrow()) } } diff --git a/diesel_cli/src/database.rs b/diesel_cli/src/database.rs index b921cb01d667..835beed57acd 100644 --- a/diesel_cli/src/database.rs +++ b/diesel_cli/src/database.rs @@ -253,7 +253,7 @@ fn drop_database(database_url: &str) -> DatabaseResult<()> { Backend::Sqlite => { if Path::new(database_url).exists() { println!("Dropping database: {}", database_url); - std::fs::remove_file(&database_url)?; + std::fs::remove_file(database_url)?; } } #[cfg(feature = "mysql")] diff --git a/diesel_cli/tests/migration_run.rs b/diesel_cli/tests/migration_run.rs index a2f9dfebe8fb..4baa3f463128 100644 --- a/diesel_cli/tests/migration_run.rs +++ b/diesel_cli/tests/migration_run.rs @@ -445,7 +445,7 @@ fn migrations_can_be_run_with_no_cargo_toml() { let db = database(&p.database_url()); let cargo_toml_path = Path::new("Cargo.toml"); - p.delete_single_file(&cargo_toml_path); + p.delete_single_file(cargo_toml_path); p.command("database").arg("setup").run(); @@ -476,7 +476,7 @@ fn migrations_can_be_run_with_no_down() { let db = database(&p.database_url()); let cargo_toml_path = Path::new("Cargo.toml"); - p.delete_single_file(&cargo_toml_path); + p.delete_single_file(cargo_toml_path); p.command("database").arg("setup").run(); diff --git a/diesel_cli/tests/support/command.rs b/diesel_cli/tests/support/command.rs index e2aac56c5ba4..2e41980e56cd 100644 --- a/diesel_cli/tests/support/command.rs +++ b/diesel_cli/tests/support/command.rs @@ -53,7 +53,7 @@ impl TestCommand { let mut command = Command::new(path_to_diesel_cli()); command.args(&self.args).current_dir(&self.cwd); for &(ref k, ref v) in self.env_vars.iter() { - command.env(&k, &v); + command.env(k, v); } command } From ec2c8bf4933c8f030f94815098e5d88a2a70c20a Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Mon, 7 Nov 2022 15:12:48 +0100 Subject: [PATCH 3/3] More fixes --- diesel/src/expression/unstable.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diesel/src/expression/unstable.rs b/diesel/src/expression/unstable.rs index df2b8da2faeb..bbfc2b16e74b 100644 --- a/diesel/src/expression/unstable.rs +++ b/diesel/src/expression/unstable.rs @@ -1,3 +1,5 @@ +use crate::expression::{is_aggregate, MixedAggregates, ValidGrouping}; + // Note that these docs are similar to but slightly different than the stable // docs below. Make sure if you change these that you also change the docs // below.