diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..83099122a0 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,5 @@ +disallowed-methods = [ + # It is *much* too easy to misread `x.min(y)` as "x should be *at least* y" when in fact it + # means the *exact* opposite, and same with `x.max(y)`; use `cmp::{min, max}` instead. + "core::cmp::Ord::min", "core::cmp::Ord::max" +] diff --git a/sqlx-core/src/lib.rs b/sqlx-core/src/lib.rs index 505181f82b..9e50d0d842 100644 --- a/sqlx-core/src/lib.rs +++ b/sqlx-core/src/lib.rs @@ -3,6 +3,8 @@ #![recursion_limit = "512"] #![warn(future_incompatible, rust_2018_idioms)] #![allow(clippy::needless_doctest_main, clippy::type_complexity)] +// See `clippy.toml` at the workspace root +#![deny(clippy::disallowed_method)] // // Allows an API be documented as only available in some specific platforms. // diff --git a/sqlx-core/src/pool/options.rs b/sqlx-core/src/pool/options.rs index d4d5db2ffa..8eb226e4ab 100644 --- a/sqlx-core/src/pool/options.rs +++ b/sqlx-core/src/pool/options.rs @@ -5,6 +5,7 @@ use crate::pool::inner::SharedPool; use crate::pool::Pool; use futures_core::future::BoxFuture; use sqlx_rt::spawn; +use std::cmp; use std::fmt::{self, Debug, Formatter}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -228,7 +229,7 @@ impl PoolOptions { } async fn init_min_connections(pool: &SharedPool) -> Result<(), Error> { - for _ in 0..pool.options.min_connections.max(1) { + for _ in 0..cmp::max(pool.options.min_connections, 1) { let deadline = Instant::now() + pool.options.connect_timeout; // this guard will prevent us from exceeding `max_size`