Manishearth / elsa

Append-only collections for Rust where borrows to entries can outlive insertions
Apache License 2.0
228 stars 33 forks source link

Address clippy lints #75

Closed caass closed 5 months ago

caass commented 5 months ago

Clippy threw some lints, so I just fixed them. In most cases, this was pretty straightforward. One lint was a little more involved: in LockFreeFrozenVec, I added a // ## Safety comment that mirrored the comments elsewhere in the codebase:

/// Load an element (if it exists). This operation is lock-free and
/// performs no synchronized atomic operations. This is a useful primitive to
/// implement your own data structure with newtypes around the index.
///
/// ## Safety
///
/// `index` must be in bounds, i.e. it must be less than `self.len()`
#[inline]
pub unsafe fn get_unchecked(&self, index: usize) -> T {
    let buffer_idx = buffer_index(index);
    let buffer_ptr = self.data[buffer_idx].load(Ordering::Relaxed);
    let local_index = index - prior_total_buffer_size(buffer_idx);
    unsafe { *buffer_ptr.add(local_index) }
}

However, a LockFreeFrozenVec::len method didn't exist, so I wrapped the existing calls to self.len.load(Ordering::Acquire):

#[inline(always)]
pub fn len(&self) -> usize {
    self.len.load(Ordering::Acquire)
}

This modified the code in LockFreeFrozenVec::is_empty, which previously used Ordering::Relaxed. However, since stores always use Ordering::Release, there is no visible behavior change.

caass commented 5 months ago

It looks like the GHA runners don't have Rust 1.79 installed yet. Maybe adding a rust-version.toml that pins to stable?