-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address clippy lints #75
Conversation
src/sync.rs
Outdated
@@ -704,15 +704,18 @@ impl<T: Copy> Default for LockFreeFrozenVec<T> { | |||
/// any heap allocations until the first time data is pushed to it. | |||
fn default() -> Self { | |||
Self { | |||
data: [Self::NULL; NUM_BUFFERS], | |||
data: std::array::from_fn(|_| Self::null()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can just use [Self::null(); NUM_BUFFERS]
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, we can't use [Self::null; NUM_BUFFERS]
because AtomicPtr
doesn't impl Copy
. The workaround is to define some const
(i.e., what happened before clippy said anything). With the new const context syntax it's possible to do [const { Self::null() }; NUM_BUFFERS]
instead, which is what I did in the second commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I'd just allow the lint? I think the const is fine, and from_fn
isn't guaranteed const so I'd rather not use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative is to do
impl<T: Copy> LockFreeFrozenVec<T> {
const fn null() -> [AtomicPtr<T>; NUM_BUFFERS] {
[const { AtomicPtr::new(std::ptr::null_mut()) }; NUM_BUFFERS]
}
}
And replace calls to [Self::NULL; NUM_BUFFERS]
with Self::null()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works for me!
It looks like the GHA runners don't have Rust 1.79 installed yet. Maybe adding a |
This reverts commit d22485f.
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:However, a
LockFreeFrozenVec::len
method didn't exist, so I wrapped the existing calls toself.len.load(Ordering::Acquire)
:This modified the code in
LockFreeFrozenVec::is_empty
, which previously usedOrdering::Relaxed
. However, since stores always useOrdering::Release
, there is no visible behavior change.