Skip to content

Commit 1d4fa05

Browse files
committed
fixup: recommended changes for Error enum
1 parent d88a373 commit 1d4fa05

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

riscv/src/register/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ macro_rules! set_pmp {
552552
value |= byte << (8 * index);
553553
_try_write(value)
554554
} else {
555-
Err($crate::result::Error::OutOfBounds {
555+
Err($crate::result::Error::IndexOutOfBounds {
556556
index,
557557
min: 0,
558558
max: max - 1,
@@ -591,7 +591,7 @@ macro_rules! clear_pmp {
591591
value &= !(0xFF << (8 * index)); // clear previous value
592592
_try_write(value)
593593
} else {
594-
Err($crate::result::Error::OutOfBounds {
594+
Err($crate::result::Error::IndexOutOfBounds {
595595
index,
596596
min: 0,
597597
max: max - 1,

riscv/src/register/mcounteren.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Mcounteren {
6767
if (3..32).contains(&index) {
6868
Ok(bf_extract(self.bits, index, 1) != 0)
6969
} else {
70-
Err(Error::OutOfBounds {
70+
Err(Error::IndexOutOfBounds {
7171
index,
7272
min: 3,
7373
max: 31,
@@ -95,7 +95,7 @@ impl Mcounteren {
9595
self.bits = bf_insert(self.bits, index, 1, hpm as usize);
9696
Ok(())
9797
} else {
98-
Err(Error::OutOfBounds {
98+
Err(Error::IndexOutOfBounds {
9999
index,
100100
min: 3,
101101
max: 31,
@@ -132,7 +132,7 @@ pub unsafe fn try_set_hpm(index: usize) -> Result<()> {
132132
if (3..32).contains(&index) {
133133
_try_set(1 << index)
134134
} else {
135-
Err(Error::OutOfBounds {
135+
Err(Error::IndexOutOfBounds {
136136
index,
137137
min: 3,
138138
max: 31,
@@ -151,7 +151,7 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
151151
if (3..32).contains(&index) {
152152
_try_clear(1 << index)
153153
} else {
154-
Err(Error::OutOfBounds {
154+
Err(Error::IndexOutOfBounds {
155155
index,
156156
min: 3,
157157
max: 31,
@@ -207,15 +207,15 @@ mod tests {
207207
(0..3).chain(32..64).for_each(|index| {
208208
assert_eq!(
209209
m.try_hpm(index),
210-
Err(Error::OutOfBounds {
210+
Err(Error::IndexOutOfBounds {
211211
index,
212212
min: 3,
213213
max: 31
214214
})
215215
);
216216
assert_eq!(
217217
m.try_set_hpm(index, false),
218-
Err(Error::OutOfBounds {
218+
Err(Error::IndexOutOfBounds {
219219
index,
220220
min: 3,
221221
max: 31

riscv/src/register/mcountinhibit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Mcountinhibit {
5353
if (3..32).contains(&index) {
5454
Ok(bf_extract(self.bits, index, 1) != 0)
5555
} else {
56-
Err(Error::OutOfBounds {
56+
Err(Error::IndexOutOfBounds {
5757
index,
5858
min: 3,
5959
max: 31,
@@ -81,7 +81,7 @@ impl Mcountinhibit {
8181
self.bits = bf_insert(self.bits, index, 1, hpm as usize);
8282
Ok(())
8383
} else {
84-
Err(Error::OutOfBounds {
84+
Err(Error::IndexOutOfBounds {
8585
index,
8686
min: 3,
8787
max: 31,
@@ -114,7 +114,7 @@ pub unsafe fn try_set_hpm(index: usize) -> Result<()> {
114114
if (3..32).contains(&index) {
115115
_try_set(1 << index)
116116
} else {
117-
Err(Error::OutOfBounds {
117+
Err(Error::IndexOutOfBounds {
118118
index,
119119
min: 3,
120120
max: 31,
@@ -133,7 +133,7 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
133133
if (3..32).contains(&index) {
134134
_try_clear(1 << index)
135135
} else {
136-
Err(Error::OutOfBounds {
136+
Err(Error::IndexOutOfBounds {
137137
index,
138138
min: 3,
139139
max: 31,
@@ -180,15 +180,15 @@ mod tests {
180180
(0..2).chain(32..64).for_each(|index| {
181181
assert_eq!(
182182
m.try_hpm(index),
183-
Err(Error::OutOfBounds {
183+
Err(Error::IndexOutOfBounds {
184184
index,
185185
min: 3,
186186
max: 31
187187
})
188188
);
189189
assert_eq!(
190190
m.try_set_hpm(index, false),
191-
Err(Error::OutOfBounds {
191+
Err(Error::IndexOutOfBounds {
192192
index,
193193
min: 3,
194194
max: 31

riscv/src/register/pmpcfgx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Pmpcsr {
119119
locked: (byte & (1 << 7)) != 0,
120120
})
121121
} else {
122-
Err(Error::OutOfBounds {
122+
Err(Error::IndexOutOfBounds {
123123
index,
124124
min: 0,
125125
max: max - 1,

riscv/src/register/scounteren.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Scounteren {
4242
if (3..32).contains(&index) {
4343
Ok(self.bits & (1 << index) != 0)
4444
} else {
45-
Err(Error::OutOfBounds {
45+
Err(Error::IndexOutOfBounds {
4646
index,
4747
min: 3,
4848
max: 31,
@@ -79,7 +79,7 @@ pub unsafe fn try_set_hpm(index: usize) -> Result<()> {
7979
if (3..32).contains(&index) {
8080
_try_set(1 << index)
8181
} else {
82-
Err(Error::OutOfBounds {
82+
Err(Error::IndexOutOfBounds {
8383
index,
8484
min: 3,
8585
max: 31,
@@ -98,7 +98,7 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
9898
if (3..32).contains(&index) {
9999
_try_clear(1 << index)
100100
} else {
101-
Err(Error::OutOfBounds {
101+
Err(Error::IndexOutOfBounds {
102102
index,
103103
min: 3,
104104
max: 31,

riscv/src/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub type Result<T> = core::result::Result<T, Error>;
88
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
99
pub enum Error {
1010
/// Attempted out-of-bounds access.
11-
OutOfBounds {
11+
IndexOutOfBounds {
1212
index: usize,
1313
min: usize,
1414
max: usize,
@@ -26,7 +26,7 @@ pub enum Error {
2626
impl fmt::Display for Error {
2727
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2828
match self {
29-
Self::OutOfBounds { index, min, max } => write!(
29+
Self::IndexOutOfBounds { index, min, max } => write!(
3030
f,
3131
"out-of-bounds access, index: {index}, min: {min}, max: {max}"
3232
),

0 commit comments

Comments
 (0)