Skip to content

Commit

Permalink
feat: add missing Default implementations
Browse files Browse the repository at this point in the history
Thanks, clippy!
  • Loading branch information
hawkw committed Jan 11, 2025
1 parent a22e4ea commit 6ae5e2e
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions alloc/src/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ impl<const SIZE: usize> Alloc<SIZE> {
}
}

impl<const SIZE: usize> Default for Alloc<SIZE> {
fn default() -> Self {
Self::new()
}
}

unsafe impl<const SIZE: usize> GlobalAlloc for Alloc<SIZE> {
/// # Safety
///
Expand Down
4 changes: 4 additions & 0 deletions bitfield/src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ macro_rules! bitfield {
/// Constructs a new instance of `Self` with all bits set to 0.
#[inline]
#[must_use]
// Allow "new without default", as the user may wish to derive
// default or provide their own implementation with different values
// from `new`.
#[allow(clippy::new_without_default)]
$vis const fn new() -> Self {
Self(0)
}
Expand Down
2 changes: 1 addition & 1 deletion hal-x86_64/src/cpu/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn seed_rng<R: SeedableRng>() -> R {
#[derive(Debug, Copy, Clone)]
pub struct Rdrand(());

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default)]
pub struct PitEntropy(());

// === impl Rdrand ===
Expand Down
6 changes: 6 additions & 0 deletions hal-x86_64/src/interrupt/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ impl Idt {
}
}

impl Default for Idt {
fn default() -> Self {
Self::new()
}
}

impl fmt::Debug for Idt {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let Self { descriptors } = self;
Expand Down
6 changes: 6 additions & 0 deletions hal-x86_64/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ impl<const SIZE: usize> Gdt<SIZE> {
}
}

impl<const SIZE: usize> Default for Gdt<SIZE> {
fn default() -> Self {
Self::new()
}
}

impl<const SIZE: usize> fmt::Debug for Gdt<SIZE> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct GdtEntries<'a, const SIZE: usize>(&'a Gdt<SIZE>);
Expand Down
6 changes: 6 additions & 0 deletions maitake-sync/src/wait_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ impl WaitCell {
}
}

impl Default for WaitCell {
fn default() -> Self {
Self::new()
}
}

impl WaitCell {
/// Poll to wait on this `WaitCell`, consuming a stored wakeup or
/// registering the [`Waker`] from the provided [`Context`] to be woken by
Expand Down
10 changes: 10 additions & 0 deletions maitake-sync/src/wait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ impl<K: PartialEq, V> WaitMap<K, V> {
}
}

impl<K, V, Lock> Default for WaitMap<K, V, Lock>
where
K: PartialEq,
Lock: ScopedRawMutex + Default,
{
fn default() -> Self {
Self::new_with_raw_mutex(Lock::default())
}
}

impl<K, V, Lock> WaitMap<K, V, Lock>
where
K: PartialEq,
Expand Down
9 changes: 9 additions & 0 deletions maitake-sync/src/wait_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ impl WaitQueue {
}
}

impl<Lock> Default for WaitQueue<Lock>
where
Lock: ScopedRawMutex + Default,
{
fn default() -> Self {
Self::new_with_raw_mutex(Lock::default())
}
}

impl<Lock> WaitQueue<Lock>
where
Lock: ScopedRawMutex,
Expand Down
3 changes: 3 additions & 0 deletions maitake/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ struct Core {
impl TaskStub {
loom_const_fn! {
/// Create a new unique stub [`Task`].
// Thee whole point of this thing is to be const-initialized, so a
// non-const-fn `Default` impl is basically useless.
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
hdr: Header::new_static_stub(),
Expand Down
6 changes: 6 additions & 0 deletions pci/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ impl Address {
}
}

impl Default for Address {
fn default() -> Self {
Self::new()
}
}

impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
Expand Down
6 changes: 6 additions & 0 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ impl Allocator {
}
}

impl Default for Allocator {
fn default() -> Self {
Self::new()
}
}

unsafe impl GlobalAlloc for Allocator {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
Expand Down

0 comments on commit 6ae5e2e

Please sign in to comment.