Skip to content

Commit 023cd44

Browse files
committed
memory_encryption: rewrite const_fn calls to re-use old feature
1 parent 29e9466 commit 023cd44

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bit_field = "0.10.1"
2424
bitflags = "2.3.2"
2525
volatile = "0.4.4"
2626
rustversion = "1.0.5"
27-
const_fn = "0.4.11"
27+
const_fn = { optional = true, version = "0.4.11" }
2828

2929
[features]
3030
default = ["nightly", "instructions"]
@@ -33,7 +33,6 @@ memory_encryption = []
3333
nightly = ["const_fn", "step_trait", "abi_x86_interrupt", "asm_const"]
3434
abi_x86_interrupt = []
3535
# deprecated, no longer needed
36-
const_fn = []
3736
asm_const = []
3837
step_trait = []
3938
doc_auto_cfg = []

src/addr.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::structures::mem_encrypt::ENC_BIT_MASK;
55
use crate::structures::paging::page_table::PageTableLevel;
66
use crate::structures::paging::{PageOffset, PageTableIndex};
77
use bit_field::BitField;
8-
use const_fn::const_fn;
98
use core::convert::TryFrom;
109
use core::fmt;
1110
#[cfg(feature = "step_trait")]
@@ -446,8 +445,8 @@ impl PhysAddr {
446445
/// If the `memory_encryption` feature is available and has been enabled, this function also
447446
/// panics fails if the encryption bit is manually set in the address.
448447
#[inline]
449-
#[const_fn(cfg(not(feature = "memory_encryption")))]
450-
pub const fn new(addr: u64) -> Self {
448+
#[cfg_attr(all(not(feature = "memory_encryption"), feature = "const_fn"), const_fn::const_fn)]
449+
pub fn new(addr: u64) -> Self {
451450
// TODO: Replace with .ok().expect(msg) when that works on stable.
452451
match Self::try_new(addr) {
453452
Ok(p) => p,
@@ -471,8 +470,8 @@ impl PhysAddr {
471470
/// If the `memory_encryption` feature is available and has been enabled, this also fails if the
472471
/// encryption bit is manually set in the address.
473472
#[inline]
474-
#[const_fn(cfg(not(feature = "memory_encryption")))]
475-
pub const fn try_new(addr: u64) -> Result<Self, PhysAddrNotValid> {
473+
#[cfg_attr(all(not(feature = "memory_encryption"), feature = "const_fn"), const_fn::const_fn)]
474+
pub fn try_new(addr: u64) -> Result<Self, PhysAddrNotValid> {
476475
let p = Self::new_truncate(addr);
477476
if p.0 == addr {
478477
Ok(p)

src/structures/paging/page_table.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use super::{PageSize, PhysFrame, Size4KiB};
44
use crate::addr::PhysAddr;
55
use bitflags::bitflags;
6-
use const_fn::const_fn;
76
use core::fmt;
87
#[cfg(feature = "step_trait")]
98
use core::iter::Step;
@@ -53,8 +52,8 @@ impl PageTableEntry {
5352

5453
/// Returns the flags of this entry.
5554
#[inline]
56-
#[const_fn(cfg(not(feature = "memory_encryption")))]
57-
pub const fn flags(&self) -> PageTableFlags {
55+
#[cfg_attr(all(not(feature = "memory_encryption"), feature = "const_fn"), const_fn::const_fn)]
56+
pub fn flags(&self) -> PageTableFlags {
5857
PageTableFlags::from_bits_retain(self.entry & !Self::physical_address_mask())
5958
}
6059

0 commit comments

Comments
 (0)