Skip to content

Commit 224cfd7

Browse files
committed
refactor: replace pattern matching with Option::{is_none, is_some}
These methods were added by [1] and are still unstable. [1]: <rust-lang/rust#73930>
1 parent 06fa07a commit 224cfd7

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

src/constance/src/kernel/cfg/interrupt.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ impl<System: Port> CfgInterruptLineBuilder<System> {
4242

4343
/// [**Required**] Specify the interrupt line to confiigure.
4444
pub const fn line(self, line: interrupt::InterruptNum) -> Self {
45-
// FIXME: `Option::is_some` is not `const fn` yet
46-
if let Some(_) = self.line {
45+
if self.line.is_some() {
4746
panic!("`line` is specified twice");
4847
}
4948
Self {
@@ -54,8 +53,7 @@ impl<System: Port> CfgInterruptLineBuilder<System> {
5453

5554
/// Specify the initial priority.
5655
pub const fn priority(self, priority: interrupt::InterruptPriority) -> Self {
57-
// FIXME: `Option::is_some` is not `const fn` yet
58-
if let Some(_) = self.priority {
56+
if self.priority.is_some() {
5957
panic!("`priority` is specified twice");
6058
}
6159
Self {
@@ -98,8 +96,7 @@ impl<System: Port> CfgInterruptLineBuilder<System> {
9896
let cfg_interrupt_line = inner.interrupt_lines.get_mut(i);
9997

10098
if let Some(priority) = self.priority {
101-
// FIXME: `Option::is_some` is not `const fn` yet
102-
if let Some(_) = cfg_interrupt_line.priority {
99+
if cfg_interrupt_line.priority.is_some() {
103100
panic!("`priority` is already specified for this interrupt line");
104101
}
105102
cfg_interrupt_line.priority = Some(priority);
@@ -140,8 +137,7 @@ impl CfgBuilderInterruptLine {
140137
priority: if let Some(i) = self.priority { i } else { 0 },
141138
flags: {
142139
let mut f = 0;
143-
// FIXME: `Option::is_some` is not `const fn` yet
144-
if let Some(_) = self.priority {
140+
if self.priority.is_some() {
145141
f |= interrupt::InterruptLineInitFlags::SET_PRIORITY.bits();
146142
}
147143
if self.enabled {
@@ -201,8 +197,7 @@ impl<System: Port> CfgInterruptHandlerBuilder<System> {
201197
/// [**Required**] Specify the interrupt line to attach the interrupt
202198
/// handler to.
203199
pub const fn line(self, line: interrupt::InterruptNum) -> Self {
204-
// FIXME: `Option::is_some` is not `const fn` yet
205-
if let Some(_) = self.line {
200+
if self.line.is_some() {
206201
panic!("`line` is specified twice");
207202
}
208203
Self {
@@ -302,14 +297,11 @@ pub(super) const fn panic_if_unmanaged_safety_is_violated<System: Port>(
302297
continue;
303298
}
304299

305-
// FIXME: Work-around for `Option::is_none` not being `const fn`
306-
let line_unmanaged = matches!(
307-
vec_position!(interrupt_lines, |line| line.num == handler.line
308-
&& line.is_initially_managed::<System>()),
309-
None
310-
);
300+
let managed_line_i = vec_position!(interrupt_lines, |line| line.num == handler.line
301+
&& line.is_initially_managed::<System>());
302+
let is_line_unmanaged = managed_line_i.is_none();
311303

312-
if line_unmanaged {
304+
if is_line_unmanaged {
313305
panic!(
314306
"An interrupt handler that is not marked with `unmanaged` \
315307
is attached to an interrupt line whose priority value is \
@@ -578,10 +570,9 @@ pub const unsafe fn new_interrupt_handler_table<
578570
// Return the combined handler
579571
let handler = T::COMBINED_HANDLERS[i];
580572

581-
// FIXME: Work-around for `Option::is_none` not being `const fn`
582573
// FIXME: Work-around for `Option::unwrap` not being `const fn`
583574
// FIXME: Work-around for `assert!` not being allowed in `const fn`
584-
if let None = handler {
575+
if handler.is_none() {
585576
panic!("assertion failed: T::COMBINED_HANDLERS[i] should be Some but got None");
586577
}
587578

src/constance/src/kernel/cfg/task.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ impl<System: Port> CfgTaskBuilder<System> {
6060

6161
/// Specify the task's stack size.
6262
pub const fn stack_size(self, stack_size: usize) -> Self {
63-
// FIXME: `Option::is_some` is not `const fn` yet
64-
if let Some(_) = self.stack {
63+
if self.stack.is_some() {
6564
panic!("the task's stack is already specified");
6665
}
6766

@@ -73,8 +72,7 @@ impl<System: Port> CfgTaskBuilder<System> {
7372

7473
/// Specify the task's hunk.
7574
pub const fn stack_hunk(self, stack_hunk: task::StackHunk<System>) -> Self {
76-
// FIXME: `Option::is_some` is not `const fn` yet
77-
if let Some(_) = self.stack {
75+
if self.stack.is_some() {
7876
panic!("the task's stack is already specified");
7977
}
8078

src/constance/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(const_slice_from_raw_parts)]
99
#![feature(const_raw_ptr_deref)]
1010
#![feature(const_checked_int_methods)]
11+
#![feature(const_option)]
1112
#![feature(ptr_wrapping_offset_from)]
1213
#![feature(cfg_target_has_atomic)] // `#[cfg(target_has_atomic_load_store)]`
1314
#![feature(unsafe_block_in_unsafe_fn)] // `unsafe fn` doesn't imply `unsafe {}`

src/constance_port_arm_m/src/threading.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,9 @@ where
566566
// FIXME: Work-around for `for` being unsupported in `const fn`
567567
while i < 16 {
568568
if i != INTERRUPT_SYSTICK {
569-
// FIXME: `Option::is_some` is not `const fn` yet
570569
// TODO: This check trips even if no handler is registered at `i`
571570
#[cfg(any())]
572-
if let Some(_) = System::INTERRUPT_HANDLERS.get(i) {
571+
if System::INTERRUPT_HANDLERS.get(i).is_some() {
573572
panic!(
574573
"registering a handler for a non-internal exception is \
575574
disallowed except for SysTick"

0 commit comments

Comments
 (0)