Skip to content

Commit

Permalink
fix(clippy): warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsonin committed May 21, 2024
1 parent 4ea95a6 commit bbba3dc
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 66 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build project
run: cargo build --all-targets --all-features
run: cargo build --all-targets --features full

docs:
name: "Docs"
Expand All @@ -56,9 +56,9 @@ jobs:
- name: Run clippy
run: cargo clippy
- name: Run clippy with all features
run: cargo clippy --all-targets --all-features
run: cargo clippy --all-targets --features full
- name: Run clippy on tests
run: cargo clippy --tests --all-targets --all-features
run: cargo clippy --tests --all-targets --features full

tests:
name: "Tests"
Expand All @@ -70,9 +70,9 @@ jobs:
- name: Run tests
run: cargo test
- name: Run tests with all features
run: cargo test --all-features
run: cargo test --features full
- name: Run tests with all features in release mode
run: cargo test --all-features --release
run: cargo test --features full --release

loom:
name: "Loom"
Expand All @@ -98,4 +98,4 @@ jobs:
cargo install cargo-binstall
cargo binstall cargo-nextest --no-confirm --secure
- name: Run tests with Miri
run: cargo miri nextest run --features serde --test-threads 4
run: cargo miri nextest run --features full --test-threads 4
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ readme = "README.md"
edition = "2021"

[lints.rust]
rust_2018_idioms = "warn"
rust_2018_idioms = { level = "warn", priority = 1 }
unreachable_pub = "warn"
missing_docs = "warn"
missing_debug_implementations = "warn"
Expand All @@ -25,18 +25,18 @@ missing_debug_implementations = "warn"
pedantic = { level = "warn", priority = -1 }

[dependencies]
loom = { version = "0.7", optional = true }
once_cell = "1"
parking_lot = "0.12"
serde = { version = "1", optional = true, features = ["derive"] }

[target.'cfg(loom)'.dependencies]
loom = { version = "0.7", features = ["checkpoint"] }

[dev-dependencies]
rand = "0.8"
serde_json = "1"
static_assertions = "1"

[features]
miri_action_log = []
serde = ["dep:serde"]
serde = ["dep:serde"]
full = ["serde"]
loom = ["dep:loom"]
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// Collection types.
pub mod collections;
/// Utilities for testing the codebase with [`loom`](crate::external::loom).
#[cfg(loom)]
#[cfg(feature = "loom")]
pub mod loom;
#[doc(hidden)]
pub mod sync;
Expand All @@ -33,7 +33,7 @@ pub mod external {
#[cfg(feature = "serde")]
pub use serde;

#[cfg(loom)]
#[cfg(feature = "loom")]
pub use loom;
pub use once_cell;
pub use parking_lot;
Expand Down
4 changes: 2 additions & 2 deletions src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(loom)]
#[cfg(feature = "loom")]
pub use loom::sync::{atomic::AtomicUsize, atomic::Ordering, RwLock, RwLockReadGuard};

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
pub use {
parking_lot::RwLock,
std::sync::atomic::{AtomicUsize, Ordering},
Expand Down
2 changes: 1 addition & 1 deletion src/type_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod key_wrapper;
mod key_wrapper_bounded;
mod plain_id;

#[cfg(all(test, not(loom)))]
#[cfg(all(test, not(feature = "loom")))]
mod tests {
use crate::{
define_key_wrapper, define_key_wrapper_bounded, define_plain_id, prelude::BlazeMapId,
Expand Down
4 changes: 2 additions & 2 deletions src/type_gen/key_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ macro_rules! key_wrapper_inner {
#[repr(transparent)]
$vis struct $new_type($crate::utils::OffsetProvider<usize>);

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
impl $new_type
{
#[doc = ::std::concat!("Creates a new instance of [`", ::std::stringify!($new_type), "`].")]
Expand All @@ -134,7 +134,7 @@ macro_rules! key_wrapper_inner {
}
}

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
impl $crate::traits::BlazeMapIdStatic for $new_type
{
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/type_gen/key_wrapper_bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ macro_rules! key_wrapper_bounded_inner {
#[repr(transparent)]
$vis struct $new_type($crate::utils::OffsetProvider<usize>);

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
impl $new_type
{
#[doc = ::std::concat!("Creates a new instance of [`", ::std::stringify!($new_type), "`].")]
Expand Down Expand Up @@ -152,7 +152,7 @@ macro_rules! key_wrapper_bounded_inner {
}
}

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
impl $crate::traits::BlazeMapIdStatic for $new_type
{
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/type_gen/plain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ macro_rules! plain_id_inner {
{
#[doc = ::std::concat!("Creates a new instance of [`", ::std::stringify!($new_type), "`].")]
#[inline]
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
$vis fn new() -> Self {
let next_id = <Self as $crate::prelude::BlazeMapIdStatic>::static_container().next_id();
Self(unsafe { $crate::utils::OffsetProvider::<usize>::new(next_id) })
}

#[doc = ::std::concat!("Creates a new instance of [`", ::std::stringify!($new_type), "`].")]
#[inline]
#[cfg(loom)]
#[cfg(feature = "loom")]
$vis fn new(type_info_container: &<Self as $crate::prelude::BlazeMapId>::TypeInfoContainer) -> Self {
let next_id = type_info_container.next_id();
Self(unsafe { $crate::utils::OffsetProvider::<usize>::new(next_id) })
Expand All @@ -104,7 +104,7 @@ macro_rules! plain_id_inner {
}
}

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
impl $crate::traits::BlazeMapIdStatic for $new_type
{
#[inline]
Expand Down
37 changes: 22 additions & 15 deletions src/type_info_containers/key_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
ops::Deref,
};

#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
use once_cell::sync::Lazy;

use crate::{
Expand All @@ -16,7 +16,7 @@ use crate::{

/// Global, statically initialized container with correspondence mapping
/// between blazemap offset wrappers and original keys.
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
#[doc(hidden)]
#[derive(Debug)]
pub struct StaticContainer<K> {
Expand All @@ -28,19 +28,26 @@ pub struct StaticContainer<K> {
/// Note that it cannot be static
/// due to the [`loom` inability](https://github.com/tokio-rs/loom/issues/290)
/// to test statically initialized code.
#[cfg(loom)]
#[cfg(feature = "loom")]
#[doc(hidden)]
#[derive(Debug)]
pub struct StaticContainer<K> {
offset_to_orig: Vec<K>,
orig_to_offset: HashMap<K, usize>,
}

impl<K> Default for StaticContainer<K> {
#[inline]
fn default() -> Self {
Self::new()
}
}

impl<K> StaticContainer<K> {
/// Creates a new instance of [`StaticContainer`].
#[inline]
#[must_use]
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
pub const fn new() -> Self {
Self {
offset_to_orig: vec![],
Expand All @@ -57,7 +64,7 @@ impl<K> StaticContainer<K> {
/// different containers of the same type.
#[inline]
#[must_use]
#[cfg(loom)]
#[cfg(feature = "loom")]
pub fn new() -> Self {
Self {
offset_to_orig: vec![],
Expand All @@ -73,17 +80,17 @@ where
{
#[inline]
fn wrap_key(&self, key: K) -> I {
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
let offset = self.read().orig_to_offset.get(&key).copied();
#[cfg(loom)]
#[cfg(feature = "loom")]
let offset = self.read().unwrap().orig_to_offset.get(&key).copied();
unsafe {
if let Some(offset) = offset {
I::from_offset_unchecked(offset)
} else {
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
let mut guard = self.write();
#[cfg(loom)]
#[cfg(feature = "loom")]
let mut guard = self.write().unwrap();
let container = &mut *guard;
let offset = match container.orig_to_offset.entry(key) {
Expand All @@ -110,9 +117,9 @@ where

#[inline]
fn capacity_info_provider(&self) -> impl Deref<Target = impl CapacityInfoProvider> {
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
let result = self.read();
#[cfg(loom)]
#[cfg(feature = "loom")]
let result = self.read().unwrap();
result
}
Expand All @@ -121,9 +128,9 @@ where
fn key_by_offset_provider(
&self,
) -> impl Deref<Target = impl KeyByOffsetProvider<Self::OrigType>> {
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
let result = self.read();
#[cfg(loom)]
#[cfg(feature = "loom")]
let result = self.read().unwrap();
result
}
Expand All @@ -139,9 +146,9 @@ impl<K> CapacityInfoProvider for StaticContainer<K> {
impl<K> KeyByOffsetProvider<K> for StaticContainer<K> {
#[inline]
unsafe fn key_by_offset_unchecked(&self, offset: usize) -> impl Borrow<K> {
#[cfg(not(loom))]
#[cfg(not(feature = "loom"))]
let result = self.offset_to_orig.get_unchecked(offset);
#[cfg(loom)]
#[cfg(feature = "loom")]
let result = self.offset_to_orig.get(offset).unwrap();
result
}
Expand Down
Loading

0 comments on commit bbba3dc

Please sign in to comment.