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

Unresolved import and unstable library feature errors on Rust 1.68.2 #228

Closed
vincent-herlemont opened this issue Apr 12, 2023 · 2 comments
Closed

Comments

@vincent-herlemont
Copy link

vincent-herlemont commented Apr 12, 2023

I am using stable version Rust 1.68.2 and the thiserror crate, but I am encountering errors related to an unresolved import and the use of an unstable library feature.

I try to activate Backtrace like described in the documentation: latest/thiserror/.

A From impl is generated for each variant containing a #[from] attribute.

Note that the variant must not contain any other fields beyond the source error and possibly a backtrace. > A backtrace is captured from within the From impl if there is a field for it.

#[derive(Error, Debug)]
pub enum MyError {
   Io {
       #[from]
        source: io::Error,
        backtrace: Backtrace,
    },
}

Here's the code I am using with the thiserror crate:

use thiserror::Error;
use std::backtrace::Backtrace;

#[derive(Error, Debug)]
pub enum Error {
    Io {
        #[from]
        source: std::io::Error,
        backtrace: Backtrace,
    }
}

And my function:

pub fn open_file(path: &Path) -> Result<File> {
    let file = File::open(path)?;
    Ok(file)
}

And my test:

let file = struct_db::open_file("my_path").unwrap();

Output logs:

error[E0432]: unresolved import `thiserror`
 --> src/error.rs:4:10
  |
4 | #[derive(Error, Debug)]
  |          ^^^^^ no `ThiserrorProvide` in `__private`
  |
  = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'error_generic_member_access'
 --> src/error.rs:4:10
  |
4 | #[derive(Error, Debug)]
  |          ^^^^^
  |
  = note: see issue #99301 <https://github.com/rust-lang/rust/issues/99301> for more information
  = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `error::Error` doesn't implement `std::fmt::Display`
  --> src/error.rs:5:10
   |
5  | pub enum Error {
   |          ^^^^^ `error::Error` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `error::Error`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `std::error::Error`
  --> /home/user/.rustup/toolchains/1.68.2-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/error.rs:31:26
   |
31 | pub trait Error: Debug + Display {
   |                          ^^^^^^^ required by this bound in `Error`

Any suggestions on how to resolve this issue would be greatly appreciated.


Related topics that I read to try to resolve this issue:

@dtolnay
Copy link
Owner

dtolnay commented Apr 12, 2023

This is a duplicate of #204.

@dzmitry-lahoda
Copy link

Currenly anyhow uses some rust nightly features https://github.com/dtolnay/anyhow/blob/master/build.rs if I am not wrong.

So would be PR thiserror accepted to have similar solution to enable errors in core in rust?

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

No branches or pull requests

3 participants