rust-analyzer: unresolved import: `thiserror::Error`
In the latest version of rust-analyzer (on nvim+coc, but a coworker is reporting the same thing on VSCode), I’m getting the following error from rust-analyzer.
[rust-analyzer] [E] unresolved import
This happens even though a regular build of the project finishes just fine.
thiserror::Error is a derive macro without an accompanying trait (c.f. serde::Serialize, which is a derive macro and also a trait, which does not cause an error).
Could there be a regression with importing derive macro traits?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 41 (19 by maintainers)
You can enable proc-macro support using
They’re all working now 🎉 (the
procMacro.enablesetting can be kept off, we can now resolve proc macro in rust-analyzer itself without consulting Cargo)This is still happening to me with things like:
Is that a separate issue or should this be reopened?
Yes. Sorry, I should have posted my config:
This just started happening today when I updated to the latest nightly. (My previous comment has the version)
That already happens with
cargo check.I’m also getting this error in neovim with the built in lsp client but it’s happening on a trait from the std lib rather than an external library. The autocompeltion also seems to not be working for the
std::osmodule.My nvim_lsp config:
This worked for me! Is there any reason this isn’t enabled by default? It seems like this is a fairly common use case/language feature.
@Folaht your
rustprocMacrokey is misspelled (see the manual), but these should be enabled by default in recent versions.I worked around this issue thus:
use thiserror::*; // should be thiserror::Error, but https://github.com/rust-analyzer/rust-analyzer/issues/6053You can use
"rust-analyzer.diagnostics.disabled": ["unresolved-import"]to disable the errors for this. It is already disabled in the latest version by default I think. (https://github.com/rust-analyzer/rust-analyzer/pull/6085)