diff --git a/crates/axerrno/src/lib.rs b/crates/axerrno/src/lib.rs index 1d9ba13a5e..a5d6af5861 100644 --- a/crates/axerrno/src/lib.rs +++ b/crates/axerrno/src/lib.rs @@ -10,7 +10,6 @@ //! [`std::io::ErrorKind`]: https://doc.rust-lang.org/std/io/enum.ErrorKind.html #![no_std] -#![feature(const_trait_impl)] mod linux_errno { include!(concat!(env!("OUT_DIR"), "/linux_errno.rs")); @@ -167,7 +166,7 @@ impl AxError { } } -impl const From for LinuxError { +impl From for LinuxError { fn from(e: AxError) -> Self { use AxError::*; match e { diff --git a/crates/capability/src/lib.rs b/crates/capability/src/lib.rs index 85f40ab712..6ac23247e2 100644 --- a/crates/capability/src/lib.rs +++ b/crates/capability/src/lib.rs @@ -27,7 +27,6 @@ //! #![no_std] -#![feature(const_trait_impl)] bitflags::bitflags! { /// Capabilities (access rights). @@ -132,7 +131,8 @@ impl WithCap { } } -impl const From for axerrno::AxError { +impl From for axerrno::AxError { + #[inline] fn from(_: CapError) -> Self { Self::PermissionDenied } diff --git a/crates/driver_block/src/lib.rs b/crates/driver_block/src/lib.rs index 6a3983c5e3..02aa5e3f31 100644 --- a/crates/driver_block/src/lib.rs +++ b/crates/driver_block/src/lib.rs @@ -2,6 +2,7 @@ #![no_std] #![feature(doc_auto_cfg)] +#![feature(const_trait_impl)] #[cfg(feature = "ramdisk")] pub mod ramdisk; diff --git a/crates/driver_block/src/ramdisk.rs b/crates/driver_block/src/ramdisk.rs index 9a385ca594..3df556829c 100644 --- a/crates/driver_block/src/ramdisk.rs +++ b/crates/driver_block/src/ramdisk.rs @@ -44,7 +44,7 @@ impl RamDisk { } } -impl BaseDriverOps for RamDisk { +impl const BaseDriverOps for RamDisk { fn device_type(&self) -> DeviceType { DeviceType::Block } diff --git a/crates/linked_list/src/lib.rs b/crates/linked_list/src/lib.rs index add6d5a225..9fb264ea05 100644 --- a/crates/linked_list/src/lib.rs +++ b/crates/linked_list/src/lib.rs @@ -5,7 +5,6 @@ //! [1]: https://github.com/Rust-for-Linux/linux/blob/rust/rust/kernel/linked_list.rs #![no_std] -#![feature(const_trait_impl)] mod linked_list; diff --git a/crates/linked_list/src/linked_list.rs b/crates/linked_list/src/linked_list.rs index 5b2448974c..0c188038a2 100644 --- a/crates/linked_list/src/linked_list.rs +++ b/crates/linked_list/src/linked_list.rs @@ -207,7 +207,7 @@ impl List { } } -impl const Default for List { +impl Default for List { fn default() -> Self { Self::new() } diff --git a/crates/memory_addr/src/lib.rs b/crates/memory_addr/src/lib.rs index 2b65630a5b..bce51aa2a9 100644 --- a/crates/memory_addr/src/lib.rs +++ b/crates/memory_addr/src/lib.rs @@ -2,7 +2,6 @@ #![no_std] #![feature(const_mut_refs)] -#![feature(const_trait_impl)] use core::fmt; use core::ops::{Add, AddAssign, Sub, SubAssign}; @@ -16,11 +15,8 @@ pub const PAGE_SIZE_4K: usize = 0x1000; /// /// The alignment must be a power of two. #[inline] -pub const fn align_down(addr: usize, align: U) -> usize -where - U: ~const Into, -{ - addr & !(align.into() - 1) +pub const fn align_down(addr: usize, align: usize) -> usize { + addr & !(align - 1) } /// Align address upwards. @@ -29,11 +25,7 @@ where /// /// The alignment must be a power of two. #[inline] -pub const fn align_up(addr: usize, align: U) -> usize -where - U: ~const Into, -{ - let align = align.into(); +pub const fn align_up(addr: usize, align: usize) -> usize { (addr + align - 1) & !(align - 1) } @@ -41,21 +33,15 @@ where /// /// Equivalent to `addr % align`, but the alignment must be a power of two. #[inline] -pub const fn align_offset(addr: usize, align: U) -> usize -where - U: ~const Into, -{ - addr & (align.into() - 1) +pub const fn align_offset(addr: usize, align: usize) -> usize { + addr & (align - 1) } /// Checks whether the address has the demanded alignment. /// /// Equivalent to `addr % align == 0`, but the alignment must be a power of two. #[inline] -pub const fn is_aligned(addr: usize, align: U) -> bool -where - U: ~const Into, -{ +pub const fn is_aligned(addr: usize, align: usize) -> bool { align_offset(addr, align) == 0 } @@ -98,6 +84,12 @@ pub struct PhysAddr(usize); pub struct VirtAddr(usize); impl PhysAddr { + /// Converts an `usize` to a physical address. + #[inline] + pub const fn from(addr: usize) -> Self { + Self(addr) + } + /// Converts the address to an `usize`. #[inline] pub const fn as_usize(self) -> usize { @@ -108,72 +100,78 @@ impl PhysAddr { /// /// See the [`align_down`] function for more information. #[inline] - pub const fn align_down(self, align: U) -> Self + pub fn align_down(self, align: U) -> Self where - U: ~const Into, + U: Into, { - Self(align_down(self.0, align)) + Self(align_down(self.0, align.into())) } /// Aligns the address upwards to the given alignment. /// /// See the [`align_up`] function for more information. #[inline] - pub const fn align_up(self, align: U) -> Self + pub fn align_up(self, align: U) -> Self where - U: ~const Into, + U: Into, { - Self(align_up(self.0, align)) + Self(align_up(self.0, align.into())) } /// Returns the offset of the address within the given alignment. /// /// See the [`align_offset`] function for more information. #[inline] - pub const fn align_offset(self, align: U) -> usize + pub fn align_offset(self, align: U) -> usize where - U: ~const Into, + U: Into, { - align_offset(self.0, align) + align_offset(self.0, align.into()) } /// Checks whether the address has the demanded alignment. /// /// See the [`is_aligned`] function for more information. #[inline] - pub const fn is_aligned(self, align: U) -> bool + pub fn is_aligned(self, align: U) -> bool where - U: ~const Into, + U: Into, { - is_aligned(self.0, align) + is_aligned(self.0, align.into()) } /// Aligns the address downwards to 4096 (bytes). #[inline] - pub const fn align_down_4k(self) -> Self { + pub fn align_down_4k(self) -> Self { self.align_down(PAGE_SIZE_4K) } /// Aligns the address upwards to 4096 (bytes). #[inline] - pub const fn align_up_4k(self) -> Self { + pub fn align_up_4k(self) -> Self { self.align_up(PAGE_SIZE_4K) } /// Returns the offset of the address within a 4K-sized page. #[inline] - pub const fn align_offset_4k(self) -> usize { + pub fn align_offset_4k(self) -> usize { self.align_offset(PAGE_SIZE_4K) } /// Checks whether the address is 4K-aligned. #[inline] - pub const fn is_aligned_4k(self) -> bool { + pub fn is_aligned_4k(self) -> bool { self.is_aligned(PAGE_SIZE_4K) } } impl VirtAddr { + /// Converts an `usize` to a virtual address. + #[inline] + pub const fn from(addr: usize) -> Self { + Self(addr) + } + /// Converts the address to an `usize`. #[inline] pub const fn as_usize(self) -> usize { @@ -196,100 +194,100 @@ impl VirtAddr { /// /// See the [`align_down`] function for more information. #[inline] - pub const fn align_down(self, align: U) -> Self + pub fn align_down(self, align: U) -> Self where - U: ~const Into, + U: Into, { - Self(align_down(self.0, align)) + Self(align_down(self.0, align.into())) } /// Aligns the address upwards to the given alignment. /// /// See the [`align_up`] function for more information. #[inline] - pub const fn align_up(self, align: U) -> Self + pub fn align_up(self, align: U) -> Self where - U: ~const Into, + U: Into, { - Self(align_up(self.0, align)) + Self(align_up(self.0, align.into())) } /// Returns the offset of the address within the given alignment. /// /// See the [`align_offset`] function for more information. #[inline] - pub const fn align_offset(self, align: U) -> usize + pub fn align_offset(self, align: U) -> usize where - U: ~const Into, + U: Into, { - align_offset(self.0, align) + align_offset(self.0, align.into()) } ///Checks whether the address has the demanded alignment. /// /// See the [`is_aligned`] function for more information. #[inline] - pub const fn is_aligned(self, align: U) -> bool + pub fn is_aligned(self, align: U) -> bool where - U: ~const Into, + U: Into, { - is_aligned(self.0, align) + is_aligned(self.0, align.into()) } /// Aligns the address downwards to 4096 (bytes). #[inline] - pub const fn align_down_4k(self) -> Self { + pub fn align_down_4k(self) -> Self { self.align_down(PAGE_SIZE_4K) } /// Aligns the address upwards to 4096 (bytes). #[inline] - pub const fn align_up_4k(self) -> Self { + pub fn align_up_4k(self) -> Self { self.align_up(PAGE_SIZE_4K) } /// Returns the offset of the address within a 4K-sized page. #[inline] - pub const fn align_offset_4k(self) -> usize { + pub fn align_offset_4k(self) -> usize { self.align_offset(PAGE_SIZE_4K) } /// Checks whether the address is 4K-aligned. #[inline] - pub const fn is_aligned_4k(self) -> bool { + pub fn is_aligned_4k(self) -> bool { self.is_aligned(PAGE_SIZE_4K) } } -impl const From for PhysAddr { +impl From for PhysAddr { #[inline] fn from(addr: usize) -> Self { Self(addr) } } -impl const From for VirtAddr { +impl From for VirtAddr { #[inline] fn from(addr: usize) -> Self { Self(addr) } } -impl const From for usize { +impl From for usize { #[inline] fn from(addr: PhysAddr) -> usize { addr.0 } } -impl const From for usize { +impl From for usize { #[inline] fn from(addr: VirtAddr) -> usize { addr.0 } } -impl const Add for PhysAddr { +impl Add for PhysAddr { type Output = Self; #[inline] fn add(self, rhs: usize) -> Self { @@ -297,14 +295,14 @@ impl const Add for PhysAddr { } } -impl const AddAssign for PhysAddr { +impl AddAssign for PhysAddr { #[inline] fn add_assign(&mut self, rhs: usize) { *self = *self + rhs; } } -impl const Sub for PhysAddr { +impl Sub for PhysAddr { type Output = Self; #[inline] fn sub(self, rhs: usize) -> Self { @@ -312,14 +310,14 @@ impl const Sub for PhysAddr { } } -impl const SubAssign for PhysAddr { +impl SubAssign for PhysAddr { #[inline] fn sub_assign(&mut self, rhs: usize) { *self = *self - rhs; } } -impl const Add for VirtAddr { +impl Add for VirtAddr { type Output = Self; #[inline] fn add(self, rhs: usize) -> Self { @@ -327,14 +325,14 @@ impl const Add for VirtAddr { } } -impl const AddAssign for VirtAddr { +impl AddAssign for VirtAddr { #[inline] fn add_assign(&mut self, rhs: usize) { *self = *self + rhs; } } -impl const Sub for VirtAddr { +impl Sub for VirtAddr { type Output = Self; #[inline] fn sub(self, rhs: usize) -> Self { diff --git a/crates/page_table/src/bits64.rs b/crates/page_table/src/bits64.rs index c5cbbccda8..6b9e8eaa9b 100644 --- a/crates/page_table/src/bits64.rs +++ b/crates/page_table/src/bits64.rs @@ -129,7 +129,7 @@ impl PageTable64 { ) -> PagingResult { if !vaddr.is_aligned(PageSize::Size4K) || !paddr.is_aligned(PageSize::Size4K) - || !memory_addr::is_aligned(size, PageSize::Size4K) + || !memory_addr::is_aligned(size, PageSize::Size4K.into()) { return Err(PagingError::NotAligned); } diff --git a/crates/page_table/src/lib.rs b/crates/page_table/src/lib.rs index 2175d83b8e..0af6649941 100644 --- a/crates/page_table/src/lib.rs +++ b/crates/page_table/src/lib.rs @@ -116,7 +116,8 @@ impl PageSize { } } -impl const From for usize { +impl From for usize { + #[inline] fn from(size: PageSize) -> usize { size as usize } diff --git a/crates/page_table_entry/src/lib.rs b/crates/page_table_entry/src/lib.rs index d7005958f7..57e70a4583 100644 --- a/crates/page_table_entry/src/lib.rs +++ b/crates/page_table_entry/src/lib.rs @@ -11,7 +11,6 @@ //! methods for manipulating various page table entries. #![no_std] -#![feature(const_trait_impl)] #![feature(doc_auto_cfg)] #![feature(doc_cfg)] diff --git a/crates/ratio/src/lib.rs b/crates/ratio/src/lib.rs index 8ce605cc2a..5ae5383b05 100644 --- a/crates/ratio/src/lib.rs +++ b/crates/ratio/src/lib.rs @@ -15,7 +15,6 @@ //! ``` #![cfg_attr(not(test), no_std)] -#![feature(const_trait_impl)] use core::{cmp::PartialEq, fmt}; @@ -139,7 +138,8 @@ impl fmt::Debug for Ratio { } } -impl const PartialEq for Ratio { +impl PartialEq for Ratio { + #[inline] fn eq(&self, other: &Ratio) -> bool { self.mult == other.mult && self.shift == other.shift } diff --git a/crates/scheduler/src/fifo.rs b/crates/scheduler/src/fifo.rs index 1e5bfbeb96..7d56acaaf5 100644 --- a/crates/scheduler/src/fifo.rs +++ b/crates/scheduler/src/fifo.rs @@ -37,8 +37,9 @@ impl FifoTask { } } -impl const Deref for FifoTask { +impl Deref for FifoTask { type Target = T; + #[inline] fn deref(&self) -> &Self::Target { &self.inner } diff --git a/crates/scheduler/src/lib.rs b/crates/scheduler/src/lib.rs index 7b19b0b843..8040fd9575 100644 --- a/crates/scheduler/src/lib.rs +++ b/crates/scheduler/src/lib.rs @@ -6,7 +6,6 @@ //! - [`RRScheduler`]: Round-robin scheduler (preemptive). #![cfg_attr(not(test), no_std)] -#![feature(const_trait_impl)] #![feature(const_mut_refs)] mod fifo; diff --git a/crates/scheduler/src/round_robin.rs b/crates/scheduler/src/round_robin.rs index 5d2c4d61e5..c35167f1ca 100644 --- a/crates/scheduler/src/round_robin.rs +++ b/crates/scheduler/src/round_robin.rs @@ -35,8 +35,9 @@ impl RRTask { } } -impl const Deref for RRTask { +impl Deref for RRTask { type Target = T; + #[inline] fn deref(&self) -> &Self::Target { &self.inner } diff --git a/crates/spinlock/src/base.rs b/crates/spinlock/src/base.rs index ee06858c39..dc00880f74 100644 --- a/crates/spinlock/src/base.rs +++ b/crates/spinlock/src/base.rs @@ -174,7 +174,7 @@ impl BaseSpinLock { } } -impl const Default for BaseSpinLock { +impl Default for BaseSpinLock { #[inline(always)] fn default() -> Self { Self::new(Default::default()) diff --git a/crates/spinlock/src/lib.rs b/crates/spinlock/src/lib.rs index af8742b2de..ad961d570e 100644 --- a/crates/spinlock/src/lib.rs +++ b/crates/spinlock/src/lib.rs @@ -9,7 +9,6 @@ //! in use. By default, this feature is disabled. #![cfg_attr(not(test), no_std)] -#![feature(const_trait_impl)] mod base; diff --git a/modules/axhal/src/arch/x86_64/context.rs b/modules/axhal/src/arch/x86_64/context.rs index f591725819..9eb18d4670 100644 --- a/modules/axhal/src/arch/x86_64/context.rs +++ b/modules/axhal/src/arch/x86_64/context.rs @@ -71,16 +71,6 @@ pub struct FxsaveArea { static_assertions::const_assert_eq!(core::mem::size_of::(), 512); -impl const Default for FxsaveArea { - fn default() -> Self { - let mut area: FxsaveArea = unsafe { core::mem::MaybeUninit::zeroed().assume_init() }; - area.fcw = 0x37f; - area.ftw = 0xffff; - area.mxcsr = 0x1f80; - area - } -} - /// Extended state of a task, such as FP/SIMD states. pub struct ExtendedState { /// Memory region for the FXSAVE/FXRSTOR instruction. @@ -98,6 +88,14 @@ impl ExtendedState { fn restore(&self) { unsafe { core::arch::x86_64::_fxrstor64(&self.fxsave_area as *const _ as *const u8) } } + + const fn default() -> Self { + let mut area: FxsaveArea = unsafe { core::mem::MaybeUninit::zeroed().assume_init() }; + area.fcw = 0x37f; + area.ftw = 0xffff; + area.mxcsr = 0x1f80; + Self { fxsave_area: area } + } } impl fmt::Debug for ExtendedState { @@ -145,9 +143,7 @@ impl TaskContext { kstack_top: VirtAddr::from(0), rsp: 0, #[cfg(feature = "fp_simd")] - ext_state: ExtendedState { - fxsave_area: FxsaveArea::default(), - }, + ext_state: ExtendedState::default(), } } diff --git a/modules/axhal/src/lib.rs b/modules/axhal/src/lib.rs index e8b684f4ef..9b07a0a5a0 100644 --- a/modules/axhal/src/lib.rs +++ b/modules/axhal/src/lib.rs @@ -26,7 +26,6 @@ #![no_std] #![feature(asm_const)] #![feature(naked_functions)] -#![feature(const_trait_impl)] #![feature(const_maybe_uninit_zeroed)] #![feature(doc_auto_cfg)] diff --git a/modules/axsync/src/lib.rs b/modules/axsync/src/lib.rs index 875534963f..dfb43e3a83 100644 --- a/modules/axsync/src/lib.rs +++ b/modules/axsync/src/lib.rs @@ -12,7 +12,6 @@ //! feature is enabled by default. #![cfg_attr(all(not(test), not(doc)), no_std)] -#![feature(const_trait_impl)] #![feature(doc_cfg)] pub use spinlock as spin; diff --git a/modules/axsync/src/mutex.rs b/modules/axsync/src/mutex.rs index 4359797228..f71b332fcd 100644 --- a/modules/axsync/src/mutex.rs +++ b/modules/axsync/src/mutex.rs @@ -131,7 +131,7 @@ impl Mutex { } } -impl const Default for Mutex { +impl Default for Mutex { #[inline(always)] fn default() -> Self { Self::new(Default::default()) diff --git a/modules/axtask/src/lib.rs b/modules/axtask/src/lib.rs index 63e7219182..e8ede0ea11 100644 --- a/modules/axtask/src/lib.rs +++ b/modules/axtask/src/lib.rs @@ -19,7 +19,6 @@ //! [2]: scheduler::RRScheduler #![cfg_attr(not(test), no_std)] -#![feature(const_trait_impl)] #![feature(doc_cfg)] cfg_if::cfg_if! { diff --git a/modules/axtask/src/task.rs b/modules/axtask/src/task.rs index 0042268d25..22dae075b5 100644 --- a/modules/axtask/src/task.rs +++ b/modules/axtask/src/task.rs @@ -59,7 +59,8 @@ impl TaskId { } } -impl const From for TaskState { +impl From for TaskState { + #[inline] fn from(state: u8) -> Self { match state { 1 => Self::Running,