Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaJewson committed Jan 10, 2025
1 parent 84df4ce commit 7da4998
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
21 changes: 7 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@
// I export all the types at the crate root, so this lint is pointless.
clippy::module_name_repetitions,
// `ǃ` (latin letter retroflex click) is used in the tests for a never type
uncommon_codepoints,
)]
#![no_std]

Expand Down Expand Up @@ -208,10 +205,6 @@ mod tests {
use std::process::abort;
use std::ptr;

// Never type, but it's actually latin letter retroflex click
#[derive(Debug, PartialEq)]
enum ǃ {}

type PinListTypes = dyn crate::Types<
Id = id::Checked,
// Use boxes because they better detect double-frees, type mismatches and other errors.
Expand Down Expand Up @@ -496,31 +489,31 @@ mod tests {
}

// node before; node after; unlink
unlink(&mut list, &mut *nodes, 6);
unlink(&mut list, &mut nodes, 6);
assert_order(&mut list, [2, 5, 1, 0, 3, 4]);

// node before; node after; remove
remove(&mut list, &mut *nodes, 5);
remove(&mut list, &mut nodes, 5);
assert_order(&mut list, [2, 1, 0, 3, 4]);

// node before; ghost after; unlink
unlink(&mut list, &mut *nodes, 4);
unlink(&mut list, &mut nodes, 4);
assert_order(&mut list, [2, 1, 0, 3]);

// node before; ghost after; remove
remove(&mut list, &mut *nodes, 3);
remove(&mut list, &mut nodes, 3);
assert_order(&mut list, [2, 1, 0]);

// ghost before; node after; unlink
unlink(&mut list, &mut *nodes, 2);
unlink(&mut list, &mut nodes, 2);
assert_order(&mut list, [1, 0]);

// ghost before; node after; remove
remove(&mut list, &mut *nodes, 1);
remove(&mut list, &mut nodes, 1);
assert_order(&mut list, [0]);

// ghost before; ghost after; unlink
unlink(&mut list, &mut *nodes, 0);
unlink(&mut list, &mut nodes, 0);
assert_order(&mut list, []);
}
}
3 changes: 2 additions & 1 deletion src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<T: ?Sized + Types> PinList<T> {
///
/// - The node must be present in the list.
/// - This cursor must not be used to invalidate any other cursors in the list (by e.g.
/// removing nodes out from under them).
/// removing nodes out from under them).
pub(crate) unsafe fn cursor_mut(
&mut self,
current: Option<NonNull<NodeShared<T>>>,
Expand Down Expand Up @@ -308,6 +308,7 @@ impl<T: ?Sized + Types> PinList<T> {
}
}

#[allow(clippy::missing_fields_in_debug)]
impl<T: ?Sized + Types> Debug for PinList<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("PinList").field("id", &self.id).finish()
Expand Down
17 changes: 13 additions & 4 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ pin_project! {
/// The node has been removed from a [`PinList`]. It holds a `Removed` and an
/// `Unprotected`. Similar to the "linked" state, proof of access to the [`PinList`] is
/// required for most operations. Dropping a node in this state will abort.
pub struct Node<T: ?Sized>
pub struct Node<T>
where
T: ?Sized,
T: Types,
{
// `None` if initial, `Some` if initialized
#[pin]
inner: Option<NodeInner<T>>,
}

impl<T: ?Sized> PinnedDrop for Node<T>
impl<T> PinnedDrop for Node<T>
where
T: ?Sized,
T: Types,
{
fn drop(this: Pin<&mut Self>) {
Expand All @@ -63,8 +65,9 @@ pin_project! {
}

pin_project! {
struct NodeInner<T: ?Sized>
struct NodeInner<T>
where
T: ?Sized,
T: Types,
{
// The ID of the list this node is/was registered in, used for checking whether access to
Expand Down Expand Up @@ -149,6 +152,12 @@ where
}
}

impl<T: ?Sized + Types> Default for Node<T> {
fn default() -> Self {
Self::new()
}
}

impl<T: ?Sized + Types> Node<T> {
/// Check whether the node is in its initial state.
#[must_use]
Expand Down Expand Up @@ -542,7 +551,7 @@ impl<'node, T: ?Sized + Types> InitializedNode<'node, T> {
// pinned.
let this = unsafe { &mut Pin::into_inner_unchecked(self).node };

let old_node = mem::replace(&mut this.inner, None);
let old_node = this.inner.take();
// SAFETY: In order for this type to exist, the node must be initialized.
let old_inner = unsafe { unwrap_unchecked(old_node) };
let old_shared = old_inner.shared.into_inner();
Expand Down

0 comments on commit 7da4998

Please sign in to comment.