Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[derive(Error)] doesn't work with no-std #299

Closed
KSXGitHub opened this issue Aug 31, 2023 · 2 comments
Closed

#[derive(Error)] doesn't work with no-std #299

KSXGitHub opened this issue Aug 31, 2023 · 2 comments

Comments

@KSXGitHub
Copy link

KSXGitHub commented Aug 31, 2023

Code

#![no_std]
use derive_more::{Display, Error};

#[derive(Debug, Display, Error)]
#[display(fmt = "This is an error message")]
pub struct MyError;

Repo: https://github.com/KSXGitHub/bug-report-derive-more-error-no-std

Expected behavior

It compiles without error

Actual behavior

error[E0433]: failed to resolve: could not find `std` in the list of imported crates
 --> src/lib.rs:4:26
  |
4 | #[derive(Debug, Display, Error)]
  |                          ^^^^^ could not find `std` in the list of imported crates
  |
  = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0433`.
error: could not compile `test-derive-error` (lib) due to previous error
@tyranron
Copy link
Collaborator

tyranron commented Sep 1, 2023

@KSXGitHub yes, because error module is only present in std, to have it in core a nightly feature(error_in_core) is required.

We're not going to support this unless it lands into core on stable Rust.

@tyranron tyranron closed this as completed Sep 1, 2023
@JelteF
Copy link
Owner

JelteF commented Sep 1, 2023

To be clear you need to use the current beta release of derive_more together with feature(error_in_core) to have the Error derive working on no_std.

[dependencies]
derive_more = "=1.0.0-beta.3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants