VSCode with rust-analyzer reports error for usage of Bencher

Whenever I try to use Bencherfrom the test crate, my IDE reports an error for the not existing crate test.

The Code snippet is (the allow clause proved to be useless, #[cfg(test)] is required for not getting a warning in regular builds)

// required for `Bencher`, see https://doc.rust-lang.org/unstable-book/library-features/test.html
#![feature(test)]

// see https://github.com/rust-lang/rust/issues/21784
#[allow(unresolved_extern_crate)]
#[cfg(test)] extern crate test;

This is how it looks like:


The problem reported is: unresolved extern crate; rust-analyzer (unresolved-extern-crate)

The code builds and benches fine without a single warning but I cannot get rid of the error in the IDE.
Is there some setting I missed in cargo, VSCode, rust-analyzer?

(toolchain is set to nightly to have access to the test-feature)

This is a known bug in rust-analyzer: `unresolved extern crate` for test crate · Issue #6714 · rust-analyzer/rust-analyzer · GitHub

To disable the diagnostic, you can check the manual chapter here: User Manual

1 Like

Thanks a lot! Somehow my search terms missed that bug.

Workaround: go to workspace settings (Ctrl + ,) and add unresolved-extern-crate to analyzer.diagnostics.disabled


That fixed it for me for the time being.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.