Skip to content

Commit 87fa2d5

Browse files
committed
Update documentation about Error in no_std
1 parent 55b9bb1 commit 87fa2d5

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8585
should prevent code style linters from attempting to modify the generated
8686
code.
8787
- Upgrade to `syn` 2.0.
88-
- The `Error` derive now works in nightly `no_std` environments when enabling
89-
`#![feature(error_in_core)]`.
88+
- The `Error` derive now works in nightly `no_std` environments
9089

9190
### Fixed
9291

impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ features = ["full"]
4444
rustdoc-args = ["--cfg", "docsrs"]
4545

4646
[lints.rust]
47-
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(ci)", "cfg(nighthly)"] }
47+
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(ci)", "cfg(nightly)"] }
4848

4949
[features]
5050
default = []

impl/doc/error.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ ignored for one of these methods by using `#[error(not(backtrace))]` or
4444

4545
### What works in `no_std`?
4646

47-
If you want to use the `Error` derive on `no_std` environments, then you need to
48-
compile with nightly and enable this feature:
49-
```ignore
50-
#![feature(error_in_core)]
51-
```
47+
If you want to use the `Error` derive on `no_std` environments, then
48+
you need to compile with nightly, or wait until Rust 1.81 when `Error`
49+
in `core` is expected to be stabilized.
5250

5351
Backtraces don't work though, because the `Backtrace` type is only available in
5452
`std`.
@@ -59,9 +57,9 @@ Backtraces don't work though, because the `Backtrace` type is only available in
5957
## Example usage
6058

6159
```rust
62-
# #![cfg_attr(nightly, feature(error_generic_member_access, error_in_core))]
63-
// Nightly requires enabling these features:
64-
// #![feature(error_generic_member_access, error_in_core)]
60+
# #![cfg_attr(nightly, feature(error_generic_member_access))]
61+
// Nightly requires enabling this feature:
62+
// #![feature(error_generic_member_access)]
6563
# #[cfg(not(nightly))] fn main() {}
6664
# #[cfg(nightly)] fn main() {
6765
# use core::error::{request_ref, request_value, Error as __};

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
doc = include_str!("../README.md")
4343
)]
4444
#![cfg_attr(not(feature = "std"), no_std)]
45-
#![cfg_attr(all(not(feature = "std"), feature = "error"), feature(error_in_core))]
4645
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4746
#![cfg_attr(any(not(docsrs), ci), deny(rustdoc::all))]
4847
#![forbid(non_ascii_idents, unsafe_code)]

tests/no_std.rs

+55
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,58 @@ enum EnumWithUnit {
7474
SmallInt(i32),
7575
Unit,
7676
}
77+
78+
#[rustversion::nightly]
79+
mod error {
80+
use derive_more::{Display, Error, From};
81+
#[derive(Default, Debug, Display, Error)]
82+
struct Simple;
83+
84+
#[derive(Default, Debug, Display, Error)]
85+
struct WithSource {
86+
source: Simple,
87+
}
88+
#[derive(Default, Debug, Display, Error)]
89+
struct WithExplicitSource {
90+
#[error(source)]
91+
explicit_source: Simple,
92+
}
93+
94+
#[derive(Default, Debug, Display, Error)]
95+
struct Tuple(Simple);
96+
97+
#[derive(Default, Debug, Display, Error)]
98+
struct WithoutSource(#[error(not(source))] i32);
99+
#[derive(Debug, Display, Error, From)]
100+
enum CompoundError {
101+
Simple,
102+
WithSource {
103+
source: Simple,
104+
},
105+
WithExplicitSource {
106+
#[error(source)]
107+
explicit_source: WithSource,
108+
},
109+
Tuple(WithExplicitSource),
110+
WithoutSource(#[error(not(source))] Tuple),
111+
}
112+
113+
#[test]
114+
fn assert() {
115+
assert!(Simple.source().is_none());
116+
assert!(WithSource::default().source().is_some());
117+
assert!(WithExplicitSource::default().source().is_some());
118+
assert!(Tuple::default().source().is_some());
119+
assert!(Tuple::default().source().is_some());
120+
assert!(WithoutSource::default().source().is_none());
121+
assert!(CompoundError::Simple.source().is_none());
122+
assert!(CompoundError::from(Simple).source().is_some());
123+
assert!(CompoundError::from(WithSource::default())
124+
.source()
125+
.is_some());
126+
assert!(CompoundError::from(WithExplicitSource::default())
127+
.source()
128+
.is_some());
129+
assert!(CompoundError::from(Tuple::default()).source().is_none());
130+
}
131+
}

0 commit comments

Comments
 (0)