Skip to content

Commit be77046

Browse files
committed
fix: resolve clippy warnings in pool/inner.rs
- Fix non-binding let on future by spawning close() future - Replace map_or(false, ...) with is_some_and(...) - Remove needless borrow in Arc::clone()
1 parent a7dda12 commit be77046

File tree

2 files changed

+10
-71
lines changed

2 files changed

+10
-71
lines changed

sqlx-core/src/lib.rs

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,7 @@
22
//! Not intended to be used directly.
33
#![recursion_limit = "512"]
44
#![warn(future_incompatible, rust_2018_idioms)]
5-
#![allow(
6-
clippy::needless_doctest_main,
7-
clippy::type_complexity,
8-
dead_code,
9-
// Common style warnings that are numerous in the codebase
10-
clippy::explicit_auto_deref,
11-
clippy::needless_borrow,
12-
clippy::needless_return,
13-
clippy::redundant_closure,
14-
clippy::question_mark,
15-
clippy::unnecessary_cast,
16-
clippy::from_iter_instead_of_collect,
17-
clippy::doc_lazy_continuation,
18-
clippy::legacy_numeric_constants,
19-
clippy::should_implement_trait,
20-
clippy::derivable_impls,
21-
clippy::manual_map,
22-
clippy::nonminimal_bool,
23-
clippy::extra_unused_lifetimes,
24-
clippy::deref_by_slicing,
25-
clippy::let_underscore_future,
26-
clippy::needless_borrowed_reference,
27-
clippy::map_clone,
28-
clippy::large_enum_variant,
29-
clippy::cast_sign_loss,
30-
clippy::cast_possible_truncation,
31-
clippy::cast_possible_wrap,
32-
clippy::cast_precision_loss,
33-
clippy::multiple_bound_locations,
34-
clippy::unnecessary_map_or,
35-
clippy::extra_unused_type_parameters,
36-
clippy::iter_cloned_collect,
37-
clippy::io_other_error,
38-
clippy::needless_borrows_for_generic_args,
39-
clippy::is_digit_ascii_radix,
40-
clippy::len_zero,
41-
clippy::manual_is_multiple_of,
42-
clippy::while_let_on_iterator,
43-
clippy::wrong_self_convention,
44-
clippy::useless_conversion,
45-
clippy::ptr_arg,
46-
clippy::clone_on_copy,
47-
clippy::explicit_counter_loop,
48-
clippy::manual_inspect,
49-
clippy::len_without_is_empty,
50-
clippy::borrow_deref_ref,
51-
clippy::get_first,
52-
clippy::enum_variant_names,
53-
clippy::let_and_return,
54-
clippy::needless_option_as_deref,
55-
clippy::op_ref,
56-
clippy::drop_non_drop,
57-
clippy::bool_assert_comparison,
58-
clippy::empty_line_after_doc_comments,
59-
clippy::single_char_add_str,
60-
clippy::let_unit_value,
61-
clippy::unit_arg,
62-
clippy::result_large_err,
63-
clippy::needless_range_loop,
64-
clippy::manual_div_ceil,
65-
clippy::manual_range_patterns,
66-
clippy::never_loop,
67-
clippy::module_inception,
68-
clippy::unwrap_or_default,
69-
clippy::zero_prefixed_literal
70-
)]
5+
#![allow(clippy::needless_doctest_main, clippy::type_complexity, dead_code)]
716
// Note: Cast warnings are allowed on a case-by-case basis with explicit #[allow(...)]
727
// This ensures we're aware of potential issues with numeric conversions
738
// See `clippy.toml` at the workspace root

sqlx-core/src/pool/inner.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ impl<DB: Database> PoolInner<DB> {
142142

143143
if parent_close_event.as_mut().poll(cx).is_ready() {
144144
// Propagate the parent's close event to the child.
145-
let _ = self.close();
145+
// We can't await here, so we spawn the close future
146+
let close_future = self.close();
147+
sqlx_rt::spawn(async move {
148+
close_future.await;
149+
});
146150
return Poll::Ready(Err(Error::PoolClosed));
147151
}
148152

@@ -197,7 +201,7 @@ impl<DB: Database> PoolInner<DB> {
197201

198202
let Floating { inner: idle, guard } = floating.into_idle();
199203

200-
if !self.idle_conns.push(idle).is_ok() {
204+
if self.idle_conns.push(idle).is_err() {
201205
panic!("BUG: connection queue overflow in release()");
202206
}
203207

@@ -403,14 +407,14 @@ impl<DB: Database> Drop for PoolInner<DB> {
403407
fn is_beyond_max_lifetime<DB: Database>(live: &Live<DB>, options: &PoolOptions<DB>) -> bool {
404408
options
405409
.max_lifetime
406-
.map_or(false, |max| live.created_at.elapsed() > max)
410+
.is_some_and(|max| live.created_at.elapsed() > max)
407411
}
408412

409413
/// Returns `true` if the connection has exceeded `options.idle_timeout` if set, `false` otherwise.
410414
fn is_beyond_idle_timeout<DB: Database>(idle: &Idle<DB>, options: &PoolOptions<DB>) -> bool {
411415
options
412416
.idle_timeout
413-
.map_or(false, |timeout| idle.idle_since.elapsed() > timeout)
417+
.is_some_and(|timeout| idle.idle_since.elapsed() > timeout)
414418
}
415419

416420
async fn check_idle_conn<DB: Database>(
@@ -458,7 +462,7 @@ async fn check_idle_conn<DB: Database>(
458462
}
459463

460464
fn spawn_maintenance_tasks<DB: Database>(pool: &Arc<PoolInner<DB>>) {
461-
let pool = Arc::clone(&pool);
465+
let pool = Arc::clone(pool);
462466

463467
let period = match (pool.options.max_lifetime, pool.options.idle_timeout) {
464468
(Some(it), None) | (None, Some(it)) => it,

0 commit comments

Comments
 (0)