Skip to content

Commit c1bab51

Browse files
authored
Make common clock ref-count clones explicit (#4302)
1 parent 3657eee commit c1bab51

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

crates/common/src/clock.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
//! Real-time and static `Clock` implementations.
1717
18+
#![warn(clippy::clone_on_ref_ptr)]
19+
1820
use std::{any::Any, cell::RefCell, collections::BTreeMap, fmt::Debug, ops::Deref, time::Duration};
1921

2022
use ahash::AHashMap;
@@ -2219,10 +2221,10 @@ mod tests {
22192221
let cancellations = Arc::new(Mutex::new(Vec::new()));
22202222
let cancel_all = Arc::new(Mutex::new(false));
22212223

2222-
let alerts_for_handler = alerts.clone();
2223-
let timers_for_handler = timers.clone();
2224-
let cancellations_for_handler = cancellations.clone();
2225-
let cancel_all_for_handler = cancel_all.clone();
2224+
let alerts_for_handler = Arc::clone(&alerts);
2225+
let timers_for_handler = Arc::clone(&timers);
2226+
let cancellations_for_handler = Arc::clone(&cancellations);
2227+
let cancel_all_for_handler = Arc::clone(&cancel_all);
22262228
let api = ClockApi::from_handlers(
22272229
|| UnixNanos::from(1_700_000_000_123_456_789),
22282230
move |name, alert_time_ns, _callback, allow_past| {

crates/common/src/python/clock.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414
// -------------------------------------------------------------------------------------------------
1515

16+
#![warn(clippy::clone_on_ref_ptr)]
17+
1618
use std::{cell::RefCell, rc::Rc};
1719

1820
use chrono::{DateTime, Duration, Utc};
@@ -255,7 +257,7 @@ impl PyClock {
255257
/// Gets the inner `Rc<RefCell<dyn Clock>>` for use in Rust code.
256258
#[must_use]
257259
pub fn clock_rc(&self) -> Rc<RefCell<dyn Clock>> {
258-
self.0.clone()
260+
Rc::clone(&self.0)
259261
}
260262

261263
/// Creates a clock backed by [`TestClock`].

0 commit comments

Comments
 (0)