Skip to content

Commit

Permalink
Cleaner #[allow] attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Sep 12, 2024
1 parent fa906d9 commit 2eeaa63
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,14 @@ impl<T, C: Collector<T>> SlotMap<T, C> {
}
}

let index = self.slots.push(Slot::new(value, tag));
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = self.slots.push(Slot::new(value, tag)) as u32;

self.len.fetch_add(1, Relaxed);

// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
// SAFETY: The `OCCUPIED_BIT` is set.
unsafe {
SlotId::new_unchecked(index as u32, OCCUPIED_BIT | tag)
}
unsafe { SlotId::new_unchecked(index, OCCUPIED_BIT | tag) }
}

pub fn insert_mut(&mut self, value: T) -> SlotId {
Expand Down Expand Up @@ -253,16 +251,14 @@ impl<T, C: Collector<T>> SlotMap<T, C> {
return unsafe { SlotId::new_unchecked(free_list_head, new_generation) };
}

let index = self.slots.push_mut(Slot::new(value, tag));
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = self.slots.push_mut(Slot::new(value, tag)) as u32;

*self.len.get_mut() += 1;

// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
// SAFETY: The `OCCUPIED_BIT` is set.
unsafe {
SlotId::new_unchecked(index as u32, OCCUPIED_BIT | tag)
}
unsafe { SlotId::new_unchecked(index, OCCUPIED_BIT | tag) }
}

/// # Panics
Expand Down Expand Up @@ -1180,8 +1176,10 @@ impl<'a, T> Iterator for Iter<'a, T> {
if generation & OCCUPIED_BIT != 0 {
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = index as u32;

// SAFETY: We checked that the occupied bit is set.
let id = unsafe { SlotId::new_unchecked(index as u32, generation) };
let id = unsafe { SlotId::new_unchecked(index, generation) };

let guard = self.guard.clone();

Expand Down Expand Up @@ -1214,8 +1212,10 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
if generation & OCCUPIED_BIT != 0 {
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = index as u32;

// SAFETY: We checked that the occupied bit is set.
let id = unsafe { SlotId::new_unchecked(index as u32, generation) };
let id = unsafe { SlotId::new_unchecked(index, generation) };

let guard = self.guard.clone();

Expand Down Expand Up @@ -1257,8 +1257,10 @@ impl<'a, T> Iterator for IterUnprotected<'a, T> {
if generation & OCCUPIED_BIT != 0 {
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = index as u32;

// SAFETY: We checked that the occupied bit is set.
let id = unsafe { SlotId::new_unchecked(index as u32, generation) };
let id = unsafe { SlotId::new_unchecked(index, generation) };

// SAFETY:
// * The `Acquire` ordering when loading the slot's generation synchronizes with the
Expand Down Expand Up @@ -1292,8 +1294,10 @@ impl<'a, T> DoubleEndedIterator for IterUnprotected<'a, T> {
if generation & OCCUPIED_BIT != 0 {
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = index as u32;

// SAFETY: We checked that the occupied bit is set.
let id = unsafe { SlotId::new_unchecked(index as u32, generation) };
let id = unsafe { SlotId::new_unchecked(index, generation) };

// SAFETY:
// * The `Acquire` ordering when loading the slot's generation synchronizes with the
Expand Down Expand Up @@ -1336,8 +1340,10 @@ impl<'a, T> Iterator for IterMut<'a, T> {
if generation & OCCUPIED_BIT != 0 {
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = index as u32;

// SAFETY: We checked that the `OCCUPIED_BIT` is set.
let id = unsafe { SlotId::new_unchecked(index as u32, generation) };
let id = unsafe { SlotId::new_unchecked(index, generation) };

// SAFETY: We checked that the slot is occupied, which means that it must have been
// initialized in `SlotMap::insert[_mut]`.
Expand All @@ -1364,8 +1370,10 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
if generation & OCCUPIED_BIT != 0 {
// Our capacity can never exceed `u32::MAX`.
#[allow(clippy::cast_possible_truncation)]
let index = index as u32;

// SAFETY: We checked that the `OCCUPIED_BIT` is set.
let id = unsafe { SlotId::new_unchecked(index as u32, generation) };
let id = unsafe { SlotId::new_unchecked(index, generation) };

// SAFETY: We checked that the slot is occupied, which means that it must have been
// initialized in `SlotMap::insert[_mut]`.
Expand Down

0 comments on commit 2eeaa63

Please sign in to comment.