Skip to content

Commit 1a9e0d9

Browse files
committed
ban Ord::{min, max} with Clippy as it's too easy to misread
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)`. This has bitten us in the gluteus maximus a number of times both in SQLx and in private projects. Signed-off-by: Austin Bonander <[email protected]>
1 parent cbe8207 commit 1a9e0d9

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

clippy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
disallowed-methods = [
2+
# It is *much* too easy to misread `x.min(y)` as "x should be *at least* y" when in fact it
3+
# means the *exact* opposite, and same with `x.max(y)`; use `cmp::{min, max}` instead.
4+
"core::cmp::Ord::min", "core::cmp::Ord::max"
5+
]

sqlx-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#![recursion_limit = "512"]
44
#![warn(future_incompatible, rust_2018_idioms)]
55
#![allow(clippy::needless_doctest_main, clippy::type_complexity)]
6+
// See `clippy.toml` at the workspace root
7+
#![deny(clippy::disallowed_method)]
68
//
79
// Allows an API be documented as only available in some specific platforms.
810
// <https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html>

sqlx-core/src/pool/options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::pool::inner::SharedPool;
55
use crate::pool::Pool;
66
use futures_core::future::BoxFuture;
77
use sqlx_rt::spawn;
8+
use std::cmp;
89
use std::fmt::{self, Debug, Formatter};
910
use std::sync::Arc;
1011
use std::time::{Duration, Instant};
@@ -228,7 +229,7 @@ impl<DB: Database> PoolOptions<DB> {
228229
}
229230

230231
async fn init_min_connections<DB: Database>(pool: &SharedPool<DB>) -> Result<(), Error> {
231-
for _ in 0..pool.options.min_connections.max(1) {
232+
for _ in 0..cmp::max(pool.options.min_connections, 1) {
232233
let deadline = Instant::now() + pool.options.connect_timeout;
233234

234235
// this guard will prevent us from exceeding `max_size`

0 commit comments

Comments
 (0)