Skip to content

Commit

Permalink
fix: solve issues caused by removing const traits
Browse files Browse the repository at this point in the history
According to rust-lang/rust#110395, const traits cannot be used anymore.
  • Loading branch information
Celve committed Mar 12, 2024
1 parent dd95657 commit daa0436
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
6 changes: 5 additions & 1 deletion allocator/src/buddy_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ impl BuddyAllocatorInner {
user: 0,
allocated: 0,
total: 0,
gran: max(gran, size_of::<usize>()),
gran: if gran > size_of::<usize>() {
gran
} else {
size_of::<usize>()
},
}
}

Expand Down
1 change: 0 additions & 1 deletion allocator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]
#![feature(const_cmp)]

pub mod buddy_allocator;
pub mod linked_list;
Expand Down
2 changes: 0 additions & 2 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
const_trait_impl,
const_for,
const_mut_refs,
const_convert,
const_default_impls,
sync_unsafe_cell
)]

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/mem/normal/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct FrameAllocatorInner {
recycled: Vec<PhyPageNum>,
}

impl const Default for FrameAllocatorInner {
impl Default for FrameAllocatorInner {
fn default() -> Self {
Self {
start: PhyPageNum(0),
Expand All @@ -24,7 +24,7 @@ impl const Default for FrameAllocatorInner {
}
}

impl const Default for FrameAllocator {
impl Default for FrameAllocator {
fn default() -> Self {
Self {
inner: Spin::new(FrameAllocatorInner::default()),
Expand Down
7 changes: 5 additions & 2 deletions kernel/src/mem/normal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::{config::MEMORY_END, mem::allocator::PageAllocator};
use lazy_static::lazy_static;

use self::allocator::FrameAllocator;
use crate::{config::MEMORY_END, mem::allocator::PageAllocator};

pub mod allocator;
pub mod page;

pub static FRAME_ALLOCATOR: FrameAllocator = FrameAllocator::default();
lazy_static! {
pub static ref FRAME_ALLOCATOR: FrameAllocator = FrameAllocator::default();
}

pub fn init_frame_allocator() {
extern "C" {
Expand Down
6 changes: 5 additions & 1 deletion kernel/src/mem/slab/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ impl BuddyAllocatorInner {
user: 0,
allocated: 0,
total: 0,
gran: max(gran, size_of::<usize>()),
gran: if gran > size_of::<usize>() {
gran
} else {
size_of::<usize>()
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/mem/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl MemTable {
}
}

impl const Default for MemTable {
impl Default for MemTable {
fn default() -> Self {
Self {
units: Default::default(),
Expand All @@ -59,7 +59,7 @@ impl MemUnit {
}
}

impl const Default for MemUnit {
impl Default for MemUnit {
fn default() -> Self {
Self {
start_ppn: PhyPageNum(0),
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/mm/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl From<usize> for VirAddr {
}
}

impl const From<usize> for PhyPageNum {
impl From<usize> for PhyPageNum {
fn from(value: usize) -> Self {
Self(truncate_page_num!(truncate_phy_addr!(value)) >> PAGE_SIZE_BITS)
}
Expand All @@ -91,7 +91,7 @@ impl From<usize> for GenOffset {

// from any to usize

impl const From<PhyAddr> for usize {
impl From<PhyAddr> for usize {
fn from(value: PhyAddr) -> Self {
value.0
}
Expand Down Expand Up @@ -372,7 +372,7 @@ impl ops::Sub<usize> for PhyPageNum {
}
}

impl const ops::Sub<PhyPageNum> for PhyPageNum {
impl ops::Sub<PhyPageNum> for PhyPageNum {
type Output = usize;

fn sub(self, rhs: PhyPageNum) -> Self::Output {
Expand Down

0 comments on commit daa0436

Please sign in to comment.