Fix multiple Default implementation caveats

This commit is contained in:
Zhang Junyang
2024-06-20 16:04:01 +00:00
committed by Tate, Hongliang Tian
parent 8633893bb9
commit d6714c4b47
7 changed files with 35 additions and 6 deletions

View File

@ -236,6 +236,7 @@ impl UserPreemption {
const PREEMPTION_INTERVAL: u32 = 100;
/// Creates a new instance of `UserPreemption`.
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
UserPreemption { count: 0 }
}

View File

@ -146,6 +146,12 @@ impl WaitQueue {
}
}
impl Default for WaitQueue {
fn default() -> Self {
Self::new()
}
}
/// A waiter that can put the current thread to sleep until it is woken up by the associated
/// [`Waker`].
///

View File

@ -73,6 +73,12 @@ impl TtyDriver {
}
}
impl Default for TtyDriver {
fn default() -> Self {
Self::new()
}
}
fn console_input_callback(mut reader: VmReader) {
let tty_driver = get_tty_driver();
while reader.remain() > 0 {

View File

@ -85,3 +85,9 @@ impl<E: Events, F: EventsFilter<E>> Subject<E, F> {
});
}
}
impl<E: Events> Default for Subject<E> {
fn default() -> Self {
Self::new()
}
}

View File

@ -198,6 +198,12 @@ impl FileTable {
}
}
impl Default for FileTable {
fn default() -> Self {
Self::new()
}
}
impl Clone for FileTable {
fn clone(&self) -> Self {
Self {

View File

@ -97,3 +97,9 @@ impl Clone for Heap {
}
}
}
impl Default for Heap {
fn default() -> Self {
Self::new()
}
}

View File

@ -5,6 +5,7 @@ use alloc::vec::Vec;
/// SlotVec is the variant of Vector.
/// It guarantees that the index of one item remains unchanged during adding
/// or deleting other items of the vector.
#[derive(Debug, Clone)]
pub struct SlotVec<T> {
// The slots to store items.
slots: Vec<Option<T>>,
@ -118,11 +119,8 @@ impl<T> SlotVec<T> {
}
}
impl<T: Clone> Clone for SlotVec<T> {
fn clone(&self) -> Self {
Self {
slots: self.slots.clone(),
num_occupied: self.num_occupied,
}
impl Default for SlotVec<()> {
fn default() -> Self {
Self::new()
}
}