Skip to content

Commit

Permalink
fixup: recommended changes for Error enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsyn committed Jun 30, 2024
1 parent d88a373 commit 1d4fa05
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions riscv/src/register/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ macro_rules! set_pmp {
value |= byte << (8 * index);
_try_write(value)
} else {
Err($crate::result::Error::OutOfBounds {
Err($crate::result::Error::IndexOutOfBounds {
index,
min: 0,
max: max - 1,
Expand Down Expand Up @@ -591,7 +591,7 @@ macro_rules! clear_pmp {
value &= !(0xFF << (8 * index)); // clear previous value
_try_write(value)
} else {
Err($crate::result::Error::OutOfBounds {
Err($crate::result::Error::IndexOutOfBounds {
index,
min: 0,
max: max - 1,
Expand Down
12 changes: 6 additions & 6 deletions riscv/src/register/mcounteren.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Mcounteren {
if (3..32).contains(&index) {
Ok(bf_extract(self.bits, index, 1) != 0)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Mcounteren {
self.bits = bf_insert(self.bits, index, 1, hpm as usize);
Ok(())
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -132,7 +132,7 @@ pub unsafe fn try_set_hpm(index: usize) -> Result<()> {
if (3..32).contains(&index) {
_try_set(1 << index)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand All @@ -151,7 +151,7 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
if (3..32).contains(&index) {
_try_clear(1 << index)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -207,15 +207,15 @@ mod tests {
(0..3).chain(32..64).for_each(|index| {
assert_eq!(
m.try_hpm(index),
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31
})
);
assert_eq!(
m.try_set_hpm(index, false),
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31
Expand Down
12 changes: 6 additions & 6 deletions riscv/src/register/mcountinhibit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Mcountinhibit {
if (3..32).contains(&index) {
Ok(bf_extract(self.bits, index, 1) != 0)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -81,7 +81,7 @@ impl Mcountinhibit {
self.bits = bf_insert(self.bits, index, 1, hpm as usize);
Ok(())
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -114,7 +114,7 @@ pub unsafe fn try_set_hpm(index: usize) -> Result<()> {
if (3..32).contains(&index) {
_try_set(1 << index)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand All @@ -133,7 +133,7 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
if (3..32).contains(&index) {
_try_clear(1 << index)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -180,15 +180,15 @@ mod tests {
(0..2).chain(32..64).for_each(|index| {
assert_eq!(
m.try_hpm(index),
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31
})
);
assert_eq!(
m.try_set_hpm(index, false),
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31
Expand Down
2 changes: 1 addition & 1 deletion riscv/src/register/pmpcfgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Pmpcsr {
locked: (byte & (1 << 7)) != 0,
})
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 0,
max: max - 1,
Expand Down
6 changes: 3 additions & 3 deletions riscv/src/register/scounteren.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Scounteren {
if (3..32).contains(&index) {
Ok(self.bits & (1 << index) != 0)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub unsafe fn try_set_hpm(index: usize) -> Result<()> {
if (3..32).contains(&index) {
_try_set(1 << index)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand All @@ -98,7 +98,7 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
if (3..32).contains(&index) {
_try_clear(1 << index)
} else {
Err(Error::OutOfBounds {
Err(Error::IndexOutOfBounds {
index,
min: 3,
max: 31,
Expand Down
4 changes: 2 additions & 2 deletions riscv/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub type Result<T> = core::result::Result<T, Error>;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {
/// Attempted out-of-bounds access.
OutOfBounds {
IndexOutOfBounds {
index: usize,
min: usize,
max: usize,
Expand All @@ -26,7 +26,7 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::OutOfBounds { index, min, max } => write!(
Self::IndexOutOfBounds { index, min, max } => write!(
f,
"out-of-bounds access, index: {index}, min: {min}, max: {max}"
),
Expand Down

0 comments on commit 1d4fa05

Please sign in to comment.