Skip to content

Commit 55db93f

Browse files
committed
fix: solve issues caused by removing const traits
According to rust-lang/rust#110395, const traits cannot be used anymore.
1 parent dd95657 commit 55db93f

File tree

8 files changed

+22
-14
lines changed

8 files changed

+22
-14
lines changed

allocator/src/buddy_allocator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ impl BuddyAllocatorInner {
6464
user: 0,
6565
allocated: 0,
6666
total: 0,
67-
gran: max(gran, size_of::<usize>()),
67+
gran: if gran > size_of::<usize>() {
68+
gran
69+
} else {
70+
size_of::<usize>()
71+
},
6872
}
6973
}
7074

allocator/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![feature(const_cmp)]
32

43
pub mod buddy_allocator;
54
pub mod linked_list;

kernel/src/main.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
const_trait_impl,
1212
const_for,
1313
const_mut_refs,
14-
const_convert,
15-
const_default_impls,
1614
sync_unsafe_cell
1715
)]
1816

kernel/src/mem/normal/allocator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct FrameAllocatorInner {
1414
recycled: Vec<PhyPageNum>,
1515
}
1616

17-
impl const Default for FrameAllocatorInner {
17+
impl Default for FrameAllocatorInner {
1818
fn default() -> Self {
1919
Self {
2020
start: PhyPageNum(0),
@@ -24,7 +24,7 @@ impl const Default for FrameAllocatorInner {
2424
}
2525
}
2626

27-
impl const Default for FrameAllocator {
27+
impl Default for FrameAllocator {
2828
fn default() -> Self {
2929
Self {
3030
inner: Spin::new(FrameAllocatorInner::default()),

kernel/src/mem/normal/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use crate::{config::MEMORY_END, mem::allocator::PageAllocator};
1+
use lazy_static::lazy_static;
22

33
use self::allocator::FrameAllocator;
4+
use crate::{config::MEMORY_END, mem::allocator::PageAllocator};
45

56
pub mod allocator;
67
pub mod page;
78

8-
pub static FRAME_ALLOCATOR: FrameAllocator = FrameAllocator::default();
9+
lazy_static! {
10+
pub static ref FRAME_ALLOCATOR: FrameAllocator = FrameAllocator::default();
11+
}
912

1013
pub fn init_frame_allocator() {
1114
extern "C" {

kernel/src/mem/slab/allocator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ impl BuddyAllocatorInner {
8888
user: 0,
8989
allocated: 0,
9090
total: 0,
91-
gran: max(gran, size_of::<usize>()),
91+
gran: if gran > size_of::<usize>() {
92+
gran
93+
} else {
94+
size_of::<usize>()
95+
},
9296
}
9397
}
9498

kernel/src/mem/table.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl MemTable {
3636
}
3737
}
3838

39-
impl const Default for MemTable {
39+
impl Default for MemTable {
4040
fn default() -> Self {
4141
Self {
4242
units: Default::default(),
@@ -59,7 +59,7 @@ impl MemUnit {
5959
}
6060
}
6161

62-
impl const Default for MemUnit {
62+
impl Default for MemUnit {
6363
fn default() -> Self {
6464
Self {
6565
start_ppn: PhyPageNum(0),

kernel/src/mm/address.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl From<usize> for VirAddr {
7171
}
7272
}
7373

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

9292
// from any to usize
9393

94-
impl const From<PhyAddr> for usize {
94+
impl From<PhyAddr> for usize {
9595
fn from(value: PhyAddr) -> Self {
9696
value.0
9797
}
@@ -372,7 +372,7 @@ impl ops::Sub<usize> for PhyPageNum {
372372
}
373373
}
374374

375-
impl const ops::Sub<PhyPageNum> for PhyPageNum {
375+
impl ops::Sub<PhyPageNum> for PhyPageNum {
376376
type Output = usize;
377377

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

0 commit comments

Comments
 (0)