Why is anyhow not working in the stable version?

2k Views Asked by At

I have a clean project to which I include anyhow 1.0.66. Installed the latest version of rust. I'm getting an error saying that anyhow requires a nightly version. Perhaps this is due to the use of backtrace, but it is supported in rust version 1.65. I don't understand how to solve the problem.

Cargo.toml

[package]
name = "libfs"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = {version = "1.22", features = ["full"]}
anyhow = {version = "1.0.66", features = ["default"]}

src/lib.rs

#[tokio::test]
async fn run_test() {
    println!("test");
}

output

$ cargo build
   Compiling anyhow v1.0.66
error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/dima/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.66/src/lib.rs:214:32
    |
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/dima/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.66/src/lib.rs:214:61
    |
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
    |                                                             ^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `anyhow` due to 2 previous errors

1

There are 1 best solutions below

0
Genius Merely On

The problem was solved by:

rm -rf target
cargo check

This seems to be related to dtolnay/anyhow/issues/250 and rust-lang/rust-analyzer/issues/12973.