Skip to content

Commit af69f72

Browse files
committed
feat: add missing Default implementations (#509)
Thanks, clippy!
1 parent acdccd8 commit af69f72

File tree

11 files changed

+63
-1
lines changed

11 files changed

+63
-1
lines changed

alloc/src/bump.rs

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ impl<const SIZE: usize> Alloc<SIZE> {
5151
}
5252
}
5353

54+
impl<const SIZE: usize> Default for Alloc<SIZE> {
55+
fn default() -> Self {
56+
Self::new()
57+
}
58+
}
59+
5460
unsafe impl<const SIZE: usize> GlobalAlloc for Alloc<SIZE> {
5561
/// # Safety
5662
///

bitfield/src/bitfield.rs

+4
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ macro_rules! bitfield {
419419
/// Constructs a new instance of `Self` with all bits set to 0.
420420
#[inline]
421421
#[must_use]
422+
// Allow "new without default", as the user may wish to derive
423+
// default or provide their own implementation with different values
424+
// from `new`.
425+
#[allow(clippy::new_without_default)]
422426
$vis const fn new() -> Self {
423427
Self(0)
424428
}

hal-x86_64/src/cpu/entropy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn seed_rng<R: SeedableRng>() -> R {
6969
#[derive(Debug, Copy, Clone)]
7070
pub struct Rdrand(());
7171

72-
#[derive(Debug, Copy, Clone)]
72+
#[derive(Debug, Copy, Clone, Default)]
7373
pub struct PitEntropy(());
7474

7575
// === impl Rdrand ===

hal-x86_64/src/interrupt/idt.rs

+6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ impl Idt {
237237
}
238238
}
239239

240+
impl Default for Idt {
241+
fn default() -> Self {
242+
Self::new()
243+
}
244+
}
245+
240246
impl fmt::Debug for Idt {
241247
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
242248
let Self { descriptors } = self;

hal-x86_64/src/segment.rs

+6
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ impl<const SIZE: usize> Gdt<SIZE> {
396396
}
397397
}
398398

399+
impl<const SIZE: usize> Default for Gdt<SIZE> {
400+
fn default() -> Self {
401+
Self::new()
402+
}
403+
}
404+
399405
impl<const SIZE: usize> fmt::Debug for Gdt<SIZE> {
400406
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
401407
struct GdtEntries<'a, const SIZE: usize>(&'a Gdt<SIZE>);

maitake-sync/src/wait_cell.rs

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ impl WaitCell {
103103
}
104104
}
105105

106+
impl Default for WaitCell {
107+
fn default() -> Self {
108+
Self::new()
109+
}
110+
}
111+
106112
impl WaitCell {
107113
/// Poll to wait on this `WaitCell`, consuming a stored wakeup or
108114
/// registering the [`Waker`] from the provided [`Context`] to be woken by

maitake-sync/src/wait_map.rs

+10
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,16 @@ impl<K: PartialEq, V> WaitMap<K, V> {
465465
}
466466
}
467467

468+
impl<K, V, Lock> Default for WaitMap<K, V, Lock>
469+
where
470+
K: PartialEq,
471+
Lock: ScopedRawMutex + Default,
472+
{
473+
fn default() -> Self {
474+
Self::new_with_raw_mutex(Lock::default())
475+
}
476+
}
477+
468478
impl<K, V, Lock> WaitMap<K, V, Lock>
469479
where
470480
K: PartialEq,

maitake-sync/src/wait_queue.rs

+9
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@ impl WaitQueue {
379379
}
380380
}
381381

382+
impl<Lock> Default for WaitQueue<Lock>
383+
where
384+
Lock: ScopedRawMutex + Default,
385+
{
386+
fn default() -> Self {
387+
Self::new_with_raw_mutex(Lock::default())
388+
}
389+
}
390+
382391
impl<Lock> WaitQueue<Lock>
383392
where
384393
Lock: ScopedRawMutex,

maitake/src/scheduler.rs

+3
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ struct Core {
528528
impl TaskStub {
529529
loom_const_fn! {
530530
/// Create a new unique stub [`Task`].
531+
// Thee whole point of this thing is to be const-initialized, so a
532+
// non-const-fn `Default` impl is basically useless.
533+
#[allow(clippy::new_without_default)]
531534
pub fn new() -> Self {
532535
Self {
533536
hdr: Header::new_static_stub(),

pci/src/addr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ impl Address {
109109
}
110110
}
111111

112+
impl Default for Address {
113+
fn default() -> Self {
114+
Self::new()
115+
}
116+
}
117+
112118
impl fmt::Display for Address {
113119
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114120
fmt::LowerHex::fmt(self, f)

src/allocator.rs

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ impl Allocator {
8484
}
8585
}
8686

87+
impl Default for Allocator {
88+
fn default() -> Self {
89+
Self::new()
90+
}
91+
}
92+
8793
unsafe impl GlobalAlloc for Allocator {
8894
#[inline]
8995
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {

0 commit comments

Comments
 (0)