Skip to content

Commit

Permalink
style: switch instances of allow to expect
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
GregoryConrad committed Sep 5, 2024
1 parent 710ae30 commit 11cddf1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
5 changes: 4 additions & 1 deletion rearch-effects/src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ fn multi_impl<const LENGTH: usize>(register: SideEffectRegistrar) -> MultiSideEf
/// Allows you to register multiple side effects _sequentially_,
/// unlike the standard [`SideEffectRegistrar`].
/// Provided by [`multi`].
#[allow(clippy::module_name_repetitions)] // re-exported at crate level (not from module)
#[expect(
clippy::module_name_repetitions,
reason = "https://github.com/rust-lang/rust-clippy/issues/8524"
)]
pub struct MultiSideEffectRegistrar<'a> {
// NOTE: the Cells are needed in order to support register(&self) (versus &mut self)
curr_index: Cell<usize>,
Expand Down
41 changes: 21 additions & 20 deletions rearch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,7 @@ impl CapsuleManager {
}

#[cfg(test)]
#[allow(
clippy::unwrap_used,
clippy::too_many_lines,
clippy::cognitive_complexity
)]
#[allow(clippy::unwrap_used)]
mod tests {
use crate::*;

Expand Down Expand Up @@ -745,20 +741,24 @@ mod tests {
}

#[test]
#[allow(
clippy::needless_pass_by_value,
clippy::too_many_lines,
clippy::cognitive_complexity
)]
fn eq_check_skips_unneeded_rebuilds() {
use std::{any::TypeId, collections::HashMap};

static BUILDS: Mutex<OnceCell<HashMap<TypeId, u32>>> = Mutex::new(OnceCell::new());

#[allow(clippy::needless_pass_by_value)]
fn increment_build_count<C: Capsule>(_capsule: C) {
let mut cell = BUILDS.lock();
cell.get_or_init(HashMap::new);
let entry = cell.get_mut().unwrap().entry(TypeId::of::<C>());
*entry.or_default() += 1;
drop(cell);
}
#[allow(clippy::needless_pass_by_value)]

fn get_build_count<C: Capsule>(_capsule: C) -> u32 {
*BUILDS
.lock()
Expand Down Expand Up @@ -975,6 +975,7 @@ mod tests {
//
// C, D, E, G, H are idempotent. A, B, F are not.
#[test]
#[allow(clippy::cognitive_complexity)]
fn complex_dependency_graph() {
fn stateful_a(CapsuleHandle { register, .. }: CapsuleHandle) -> (u8, impl CData + Fn(u8)) {
register.register(effects::cloned_state(0))
Expand Down Expand Up @@ -1032,28 +1033,28 @@ mod tests {

let txn = container.0.read_txn();
assert!(txn.try_read(&stateful_a).is_some());
assert_eq!(txn.try_read(&a).unwrap(), 0);
assert_eq!(txn.try_read(&b).unwrap(), 1);
assert_eq!(txn.try_read(&c).unwrap(), 2);
assert_eq!(txn.try_read(&d).unwrap(), 2);
assert_eq!(txn.try_read(&e).unwrap(), 1);
assert_eq!(txn.try_read(&f).unwrap(), 1);
assert_eq!(txn.try_read(&g).unwrap(), 3);
assert_eq!(txn.try_read(&h).unwrap(), 1);
assert_eq!(txn.try_read(&a), Some(0));
assert_eq!(txn.try_read(&b), Some(1));
assert_eq!(txn.try_read(&c), Some(2));
assert_eq!(txn.try_read(&d), Some(2));
assert_eq!(txn.try_read(&e), Some(1));
assert_eq!(txn.try_read(&f), Some(1));
assert_eq!(txn.try_read(&g), Some(3));
assert_eq!(txn.try_read(&h), Some(1));
drop(txn);

container.read(stateful_a).1(10);

let txn = container.0.read_txn();
assert!(txn.try_read(&stateful_a).is_some());
assert_eq!(txn.try_read(&a).unwrap(), 10);
assert_eq!(txn.try_read(&b).unwrap(), 11);
assert_eq!(txn.try_read(&a), Some(10));
assert_eq!(txn.try_read(&b), Some(11));
assert_eq!(txn.try_read(&c), None);
assert_eq!(txn.try_read(&d), None);
assert_eq!(txn.try_read(&e).unwrap(), 11);
assert_eq!(txn.try_read(&f).unwrap(), 11);
assert_eq!(txn.try_read(&e), Some(11));
assert_eq!(txn.try_read(&f), Some(11));
assert_eq!(txn.try_read(&g), None);
assert_eq!(txn.try_read(&h).unwrap(), 1);
assert_eq!(txn.try_read(&h), Some(1));
drop(txn);
}

Expand Down
5 changes: 4 additions & 1 deletion rearch/src/side_effect_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ impl<'a> SideEffectRegistrar<'a> {

impl<'a> SideEffectRegistrar<'a> {
/// The basic building block for all side effects.
#[allow(clippy::missing_panics_doc)] // false positive
///
/// # Panics
/// Panics when the supplied type `T` changes between builds.
/// Ensure T remains the same across builds (e.g., by calling this function unconditionally).
pub fn raw<T>(
self,
initial: T,
Expand Down
11 changes: 8 additions & 3 deletions rearch/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use crate::{
EXCLUSIVE_OWNER_MSG,
};

#[allow(clippy::module_name_repetitions)] // re-exported at crate level (not in module)
#[expect(
clippy::module_name_repetitions,
reason = "https://github.com/rust-lang/rust-clippy/issues/8524"
)]
pub struct ContainerReadTxn<'a> {
pub(crate) data: RwLockReadGuard<'a, HashMap<CapsuleId, Box<dyn Any + Send + Sync>>>,
}
Expand Down Expand Up @@ -40,7 +43,10 @@ impl ContainerReadTxn<'_> {
}
}

#[allow(clippy::module_name_repetitions)] // re-exported at crate level (not in module)
#[expect(
clippy::module_name_repetitions,
reason = "https://github.com/rust-lang/rust-clippy/issues/8524"
)]
pub struct ContainerWriteTxn<'a> {
pub(crate) side_effect_txn_orchestrator: SideEffectTxnOrchestrator,
pub(crate) data: RwLockWriteGuard<'a, HashMap<CapsuleId, Box<dyn Any + Send + Sync>>>,
Expand Down Expand Up @@ -78,7 +84,6 @@ impl ContainerWriteTxn<'_> {
self.read_or_init_ref(capsule).clone()
}

#[allow(clippy::missing_panics_doc)] // false positive
pub fn read_or_init_ref<C: Capsule>(&mut self, capsule: C) -> &C::Data {
let id = capsule.id();
self.ensure_initialized(capsule);
Expand Down

0 comments on commit 11cddf1

Please sign in to comment.