Skip to content

Commit 91cf7e1

Browse files
committed
implement core::error::Error
this trait has been stabilised in Rust 1.81.0. the existing custom `Error` types cannot be removed / replaced as that'd be a breaking change. for the same reason it's not possible for them to require `core::error::Error` being implemented. however, we can already implement the new trait for all cases where the custom trait has been implemented so far. existing `std` feature-gated implementations of `std::error::Error` have also been moved to `core::error::Error` and the feature gate removed. this raises the MSRV to 1.81.0 for most crates, but based on the MSRV policy this should not be an issue.
1 parent 0c31d81 commit 91cf7e1

File tree

24 files changed

+50
-41
lines changed

24 files changed

+50
-41
lines changed

.github/workflows/test.yml

+2-16
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,9 @@ jobs:
3838
--target thumbv7m-none-eabi
3939
--features async,defmt-03
4040
41-
msrv-1-60:
41+
msrv-1-81:
4242
runs-on: ubuntu-latest
4343
steps:
4444
- uses: actions/checkout@v4
45-
- uses: dtolnay/[email protected]
46-
- run: >
47-
cargo test
48-
-p embedded-hal:1.0.0
49-
-p embedded-hal-bus
50-
-p embedded-hal-nb
51-
-p embedded-io
52-
-p embedded-io-adapters
53-
-p embedded-can
54-
55-
msrv-1-75:
56-
runs-on: ubuntu-latest
57-
steps:
58-
- uses: actions/checkout@v4
59-
- uses: dtolnay/[email protected]
45+
- uses: dtolnay/[email protected]
6046
- run: cargo test --workspace --all-features

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ on crates.io.
6464

6565
## Minimum Supported Rust Version (MSRV)
6666

67-
This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
67+
This crate is guaranteed to compile on stable Rust 1.81 and up. It *might*
6868
compile with older versions but that may change in any new patch release.
6969

7070
See [here](docs/msrv.md) for details on how the MSRV may be upgraded.

embedded-can/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
...
10+
- Added `core::error::Error` implementations for every custom `impl Error`
11+
- Increased MSRV to 1.81 due to `core::error::Error`
1112

1213
## [v0.4.1] - 2022-09-28
1314

embedded-can/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "embedded-can"
33
version = "0.4.1"
44
edition = "2021"
5-
rust-version = "1.56"
5+
rust-version = "1.81"
66

77
description = "HAL traits for Controller Area Network (CAN) devices."
88
categories = ["embedded", "hardware-support", "no-std"]

embedded-can/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ impl Error for ErrorKind {
110110
}
111111
}
112112

113+
impl core::error::Error for ErrorKind {}
114+
113115
impl core::fmt::Display for ErrorKind {
114116
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
115117
match self {

embedded-hal-bus/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
- Added the `alloc` feature.
1111
- Added a new `RcDevice` for I2C and SPI, a reference-counting equivalent to `RefCellDevice`.
12+
- Migrated `std` feature-gated `std::error::Error` implementations to `core::error::Error`
13+
- Increased MSRV to 1.81 due to `core::error::Error`
1214

1315
## [v0.2.0] - 2024-04-23
1416

embedded-hal-bus/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ categories = ["embedded", "hardware-support", "no-std"]
66
description = "Bus/Device connection mechanisms for embedded-hal, a Hardware Abstraction Layer (HAL) for embedded systems"
77
documentation = "https://docs.rs/embedded-hal-bus"
88
edition = "2021"
9-
rust-version = "1.60"
9+
rust-version = "1.81"
1010
keywords = ["hal", "IO"]
1111
license = "MIT OR Apache-2.0"
1212
name = "embedded-hal-bus"
@@ -15,7 +15,7 @@ repository = "https://github.com/rust-embedded/embedded-hal"
1515
version = "0.2.0"
1616

1717
[features]
18-
# Enable shared bus implementations using `std::sync::Mutex`, and implement `std::error::Error` for `DeviceError`
18+
# Enable shared bus implementations using `std::sync::Mutex`
1919
std = ["alloc"]
2020
# Use `portable-atomic` to enable `atomic-device` on devices without native atomic CAS
2121
#

embedded-hal-bus/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ provides mechanisms to obtain multiple `I2c` instances out of a single `I2c` ins
3939
that does not natively support atomic CAS. If you enable this, you must also add `portable-atomic` to your crate with
4040
a feature flag such as `unsafe-assume-single-core` or `critical-section` to choose how atomic CAS is implemented.
4141
See <https://docs.rs/portable-atomic/1.7.0/portable_atomic/#optional-features> for more info.
42-
- **`std`**: enable shared bus implementations using `std::sync::Mutex`, and implement
43-
`std::error::Error` for `DeviceError`.
42+
- **`std`**: enable shared bus implementations using `std::sync::Mutex`.
4443

4544
## Minimum Supported Rust Version (MSRV)
4645

embedded-hal-bus/src/spi/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ impl<BUS: Display, CS: Display> Display for DeviceError<BUS, CS> {
4747
}
4848
}
4949

50-
#[cfg(feature = "std")]
51-
impl<BUS: Debug + Display, CS: Debug + Display> std::error::Error for DeviceError<BUS, CS> {}
50+
impl<BUS: Debug + Display, CS: Debug + Display> core::error::Error for DeviceError<BUS, CS> {}
5251

5352
impl<BUS, CS> Error for DeviceError<BUS, CS>
5453
where

embedded-hal-nb/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
No unreleased changes
10+
- Added `core::error::Error` implementations for every custom `impl Error`
11+
- Increased MSRV to 1.81 due to `core::error::Error`
1112

1213
## [v1.0.0] - 2023-12-28
1314

embedded-hal-nb/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "embedded-hal-nb"
33
version = "1.0.0"
44
edition = "2021"
5-
rust-version = "1.56"
5+
rust-version = "1.81"
66

77
categories = ["embedded", "hardware-support", "no-std"]
88
description = "Non-blocking Hardware Abstraction Layer (HAL) for embedded systems using the `nb` crate."

embedded-hal-nb/src/serial.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ impl Error for ErrorKind {
4545
}
4646
}
4747

48+
impl core::error::Error for ErrorKind {}
49+
4850
impl core::fmt::Display for ErrorKind {
4951
#[inline]
5052
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

embedded-hal/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
No unreleased changes yet.
10+
- Added `core::error::Error` implementations for every custom `impl Error`
11+
- Increased MSRV to 1.81 due to `core::error::Error`
1112

1213
## [v1.0.0] - 2023-12-28
1314

embedded-hal/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ categories = ["asynchronous", "embedded", "hardware-support", "no-std"]
88
description = " A Hardware Abstraction Layer (HAL) for embedded systems "
99
documentation = "https://docs.rs/embedded-hal"
1010
edition = "2021"
11-
rust-version = "1.60"
11+
rust-version = "1.81"
1212
keywords = ["hal", "IO"]
1313
license = "MIT OR Apache-2.0"
1414
name = "embedded-hal"

embedded-hal/src/digital.rs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ impl Error for ErrorKind {
4141
}
4242
}
4343

44+
impl core::error::Error for ErrorKind {}
45+
4446
impl core::fmt::Display for ErrorKind {
4547
#[inline]
4648
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

embedded-hal/src/i2c.rs

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ impl Error for ErrorKind {
232232
}
233233
}
234234

235+
impl core::error::Error for ErrorKind {}
236+
235237
impl core::fmt::Display for ErrorKind {
236238
#[inline]
237239
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

embedded-hal/src/pwm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ impl Error for ErrorKind {
4040
}
4141
}
4242

43+
impl core::error::Error for ErrorKind {}
44+
4345
impl core::fmt::Display for ErrorKind {
4446
#[inline]
4547
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

embedded-hal/src/spi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ impl Error for ErrorKind {
275275
}
276276
}
277277

278+
impl core::error::Error for ErrorKind {}
279+
278280
impl core::fmt::Display for ErrorKind {
279281
#[inline]
280282
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

embedded-io-async/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This project is developed and maintained by the [HAL team](https://github.com/ru
1212

1313
## Optional Cargo features
1414

15-
- **`std`**: Adds `From` impls to convert to/from `std::io` structs, adds `std::error::Error` impls.
15+
- **`std`**: Adds `From` impls to convert to/from `std::io` structs.
1616
- **`alloc`**: Adds blanket impls for `Box`, adds `Write` impl to `Vec`.
1717
- **`defmt-03`**: Derive `defmt::Format` from `defmt` 0.3 for enums and structs.
1818

embedded-io/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
- Added `core::error::Error` implementations for every custom `impl Error`
11+
- Migrated `std` feature-gated `std::error::Error` implementations to `core::error::Error`
12+
- Increased MSRV to 1.81 due to `core::error::Error`
13+
814
## 0.6.1 - 2023-10-22
915

1016
- Make `SliceWriteError` publicly available.

embedded-io/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "embedded-io"
33
version = "0.6.1"
44
edition = "2021"
5-
rust-version = "1.60"
5+
rust-version = "1.81"
66
description = "Embedded IO traits"
77
repository = "https://github.com/rust-embedded/embedded-hal"
88
readme = "README.md"

embedded-io/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ targets.
2121

2222
## Optional Cargo features
2323

24-
- **`std`**: Adds `From` impls to convert to/from `std::io` structs, adds `std::error::Error` impls.
24+
- **`std`**: Adds `From` impls to convert to/from `std::io` structs.
2525
- **`alloc`**: Adds blanket impls for `Box`, adds `Write` impl to `Vec`.
2626
- **`defmt-03`**: Derive `defmt::Format` from `defmt` 0.3 for enums and structs.
2727

embedded-io/src/impls/slice_mut.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ impl core::fmt::Display for SliceWriteError {
1919
}
2020
}
2121

22-
#[cfg(feature = "std")]
23-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
24-
impl std::error::Error for SliceWriteError {}
22+
impl core::error::Error for SliceWriteError {}
2523

2624
/// Write is implemented for `&mut [u8]` by copying into the slice, overwriting
2725
/// its data.

embedded-io/src/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ impl Error for ErrorKind {
193193
}
194194
}
195195

196+
impl core::error::Error for ErrorKind {}
197+
198+
impl fmt::Display for ErrorKind {
199+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
200+
write!(f, "{:?}", self)
201+
}
202+
}
203+
196204
#[cfg(feature = "std")]
197205
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
198206
impl Error for std::io::Error {
@@ -255,9 +263,7 @@ impl<E: fmt::Debug> fmt::Display for ReadExactError<E> {
255263
}
256264
}
257265

258-
#[cfg(feature = "std")]
259-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
260-
impl<E: fmt::Debug> std::error::Error for ReadExactError<E> {}
266+
impl<E: fmt::Debug> core::error::Error for ReadExactError<E> {}
261267

262268
/// Errors that could be returned by `Write` on `&mut [u8]`.
263269
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
@@ -290,9 +296,7 @@ impl<E: fmt::Debug> fmt::Display for WriteFmtError<E> {
290296
}
291297
}
292298

293-
#[cfg(feature = "std")]
294-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
295-
impl<E: fmt::Debug> std::error::Error for WriteFmtError<E> {}
299+
impl<E: fmt::Debug> core::error::Error for WriteFmtError<E> {}
296300

297301
/// Blocking reader.
298302
///

0 commit comments

Comments
 (0)