Skip to content

Commit e74adfe

Browse files
committed
Remove const_fn macro
Signed-off-by: Joe Richey <[email protected]>
1 parent 12fd073 commit e74adfe

File tree

2 files changed

+35
-68
lines changed

2 files changed

+35
-68
lines changed

src/lib.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,6 @@
1212

1313
pub use crate::addr::{align_down, align_up, PhysAddr, VirtAddr};
1414

15-
/// Makes a function const only when `feature = "const_fn"` is enabled.
16-
///
17-
/// This is needed for const functions with bounds on their generic parameters,
18-
/// such as those in `Page` and `PhysFrame` and many more.
19-
macro_rules! const_fn {
20-
(
21-
$(#[$attr:meta])*
22-
$sv:vis fn $($fn:tt)*
23-
) => {
24-
$(#[$attr])*
25-
#[cfg(feature = "const_fn")]
26-
$sv const fn $($fn)*
27-
28-
$(#[$attr])*
29-
#[cfg(not(feature = "const_fn"))]
30-
$sv fn $($fn)*
31-
};
32-
(
33-
$(#[$attr:meta])*
34-
$sv:vis unsafe fn $($fn:tt)*
35-
) => {
36-
$(#[$attr])*
37-
#[cfg(feature = "const_fn")]
38-
$sv const unsafe fn $($fn)*
39-
40-
$(#[$attr])*
41-
#[cfg(not(feature = "const_fn"))]
42-
$sv unsafe fn $($fn)*
43-
};
44-
}
45-
4615
pub mod addr;
4716
pub mod instructions;
4817
pub mod registers;

src/structures/gdt.rs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,34 @@ impl GlobalDescriptorTable {
9393
&self.table[..self.next_free]
9494
}
9595

96-
const_fn! {
97-
/// Adds the given segment descriptor to the GDT, returning the segment selector.
98-
///
99-
/// Panics if the GDT has no free entries left.
100-
#[inline]
101-
pub fn add_entry(&mut self, entry: Descriptor) -> SegmentSelector {
102-
let index = match entry {
103-
Descriptor::UserSegment(value) => self.push(value),
104-
Descriptor::SystemSegment(value_low, value_high) => {
105-
let index = self.push(value_low);
106-
self.push(value_high);
107-
index
108-
}
109-
};
96+
/// Adds the given segment descriptor to the GDT, returning the segment selector.
97+
///
98+
/// Panics if the GDT has no free entries left.
99+
#[inline]
100+
#[cfg_attr(feature = "const_fn", rustversion::attr(all(), const))]
101+
pub fn add_entry(&mut self, entry: Descriptor) -> SegmentSelector {
102+
let index = match entry {
103+
Descriptor::UserSegment(value) => self.push(value),
104+
Descriptor::SystemSegment(value_low, value_high) => {
105+
let index = self.push(value_low);
106+
self.push(value_high);
107+
index
108+
}
109+
};
110110

111-
let rpl = match entry {
112-
Descriptor::UserSegment(value) => {
113-
if DescriptorFlags::from_bits_truncate(value).contains(DescriptorFlags::DPL_RING_3)
114-
{
115-
PrivilegeLevel::Ring3
116-
} else {
117-
PrivilegeLevel::Ring0
118-
}
111+
let rpl = match entry {
112+
Descriptor::UserSegment(value) => {
113+
if DescriptorFlags::from_bits_truncate(value).contains(DescriptorFlags::DPL_RING_3)
114+
{
115+
PrivilegeLevel::Ring3
116+
} else {
117+
PrivilegeLevel::Ring0
119118
}
120-
Descriptor::SystemSegment(_, _) => PrivilegeLevel::Ring0,
121-
};
119+
}
120+
Descriptor::SystemSegment(_, _) => PrivilegeLevel::Ring0,
121+
};
122122

123-
SegmentSelector::new(index as u16, rpl)
124-
}
123+
SegmentSelector::new(index as u16, rpl)
125124
}
126125

127126
/// Loads the GDT in the CPU using the `lgdt` instruction. This does **not** alter any of the
@@ -155,17 +154,16 @@ impl GlobalDescriptorTable {
155154
}
156155
}
157156

158-
const_fn! {
159-
#[inline]
160-
fn push(&mut self, value: u64) -> usize {
161-
if self.next_free < self.table.len() {
162-
let index = self.next_free;
163-
self.table[index] = value;
164-
self.next_free += 1;
165-
index
166-
} else {
167-
panic!("GDT full");
168-
}
157+
#[inline]
158+
#[cfg_attr(feature = "const_fn", rustversion::attr(all(), const))]
159+
fn push(&mut self, value: u64) -> usize {
160+
if self.next_free < self.table.len() {
161+
let index = self.next_free;
162+
self.table[index] = value;
163+
self.next_free += 1;
164+
index
165+
} else {
166+
panic!("GDT full");
169167
}
170168
}
171169

0 commit comments

Comments
 (0)