Skip to content

Commit 790ecdd

Browse files
authored
Implement core::error::Error for all error types (#1462)
* implement core::error::Error for all error types This way we no longer have to conditionally compile for `std`. * apply rustfmt
1 parent bd63b69 commit 790ecdd

File tree

17 files changed

+56
-44
lines changed

17 files changed

+56
-44
lines changed

crates/core/src/untyped.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#[cfg(feature = "simd")]
22
use crate::V128;
33
use crate::{F32, F64};
4-
use core::fmt::{self, Display};
4+
use core::{
5+
error::Error,
6+
fmt::{self, Display},
7+
};
58

69
/// An untyped value.
710
///
@@ -300,8 +303,7 @@ impl UntypedError {
300303
}
301304
}
302305

303-
#[cfg(feature = "std")]
304-
impl std::error::Error for UntypedError {}
306+
impl Error for UntypedError {}
305307

306308
impl Display for UntypedError {
307309
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

crates/ir/src/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ impl fmt::Display for Error {
2424
}
2525
}
2626

27-
#[cfg(feature = "std")]
28-
impl std::error::Error for Error {}
27+
impl core::error::Error for Error {}

crates/wasmi/src/engine/executor/instrs/call.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ pub struct ResumableHostError {
7474
caller_results: RegSpan,
7575
}
7676

77-
#[cfg(feature = "std")]
78-
impl std::error::Error for ResumableHostError {}
77+
impl core::error::Error for ResumableHostError {}
7978

8079
impl fmt::Display for ResumableHostError {
8180
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/wasmi/src/engine/limits/engine.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use core::fmt::{self, Display};
1+
use core::{
2+
error::Error,
3+
fmt::{self, Display},
4+
};
25

36
/// An error that can occur upon parsing or compiling a Wasm module when [`EnforcedLimits`] are set.
47
#[derive(Debug, Copy, Clone)]
@@ -23,8 +26,7 @@ pub enum EnforcedLimitsError {
2326
MinAvgBytesPerFunction { limit: u32, avg: u32 },
2427
}
2528

26-
#[cfg(feature = "std")]
27-
impl std::error::Error for EnforcedLimitsError {}
29+
impl Error for EnforcedLimitsError {}
2830

2931
impl Display for EnforcedLimitsError {
3032
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/wasmi/src/engine/limits/stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::core::UntypedVal;
22
use core::{
3+
error::Error,
34
fmt::{self, Display},
45
mem::size_of,
56
};
@@ -31,8 +32,7 @@ pub enum LimitsError {
3132
InitialValueStackExceedsMaximum,
3233
}
3334

34-
#[cfg(feature = "std")]
35-
impl std::error::Error for LimitsError {}
35+
impl Error for LimitsError {}
3636

3737
impl Display for LimitsError {
3838
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/wasmi/src/engine/translator/error.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use core::fmt::{self, Display};
1+
use core::{
2+
error::Error,
3+
fmt::{self, Display},
4+
};
25

36
/// An error that may occur upon parsing, validating and translating Wasm.
47
#[derive(Debug)]
@@ -43,8 +46,7 @@ impl TranslationError {
4346
}
4447
}
4548

46-
#[cfg(feature = "std")]
47-
impl std::error::Error for TranslationError {}
49+
impl Error for TranslationError {}
4850

4951
impl Display for TranslationError {
5052
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/wasmi/src/engine/translator/labels.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ pub enum LabelError {
6161
Unpinned { label: LabelRef },
6262
}
6363

64-
#[cfg(feature = "std")]
65-
impl std::error::Error for LabelError {}
64+
impl core::error::Error for LabelError {}
6665

6766
impl Display for LabelError {
6867
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/wasmi/src/error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ impl Error {
141141
}
142142
}
143143

144-
#[cfg(feature = "std")]
145-
impl std::error::Error for Error {}
144+
impl core::error::Error for Error {}
146145

147146
impl Display for Error {
148147
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -242,8 +241,7 @@ impl ErrorKind {
242241
}
243242
}
244243

245-
#[cfg(feature = "std")]
246-
impl std::error::Error for ErrorKind {}
244+
impl core::error::Error for ErrorKind {}
247245

248246
impl Display for ErrorKind {
249247
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

crates/wasmi/src/func/error.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::core::FuncTypeError as CoreFuncTypeError;
2-
use core::{fmt, fmt::Display};
2+
use core::{
3+
error::Error,
4+
fmt::{self, Display},
5+
};
36

47
/// Errors that can occur upon type checking function signatures.
58
#[derive(Debug)]
@@ -28,8 +31,7 @@ impl From<CoreFuncTypeError> for FuncError {
2831
}
2932
}
3033

31-
#[cfg(feature = "std")]
32-
impl std::error::Error for FuncError {}
34+
impl Error for FuncError {}
3335

3436
impl Display for FuncError {
3537
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/wasmi/src/global.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use crate::{
55
value::WithType,
66
Val,
77
};
8-
use core::{fmt, fmt::Display, ptr::NonNull};
8+
use core::{
9+
error::Error,
10+
fmt::{self, Display},
11+
ptr::NonNull,
12+
};
913

1014
/// A raw index to a global variable entity.
1115
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
@@ -46,8 +50,7 @@ pub enum GlobalError {
4650
},
4751
}
4852

49-
#[cfg(feature = "std")]
50-
impl std::error::Error for GlobalError {}
53+
impl Error for GlobalError {}
5154

5255
impl Display for GlobalError {
5356
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

0 commit comments

Comments
 (0)