rust-analyzer: Unresolved import error for "ed25519_dalek::Keypair"

First of all: Thanks for creating rust-analyzer.

I’m using the VSCode extension version 0.2.449 and I’m running into the “rust-analyzer(unresolved-import)” issue which was already reported before.

I followed the advice to enable the following settings to no avail:

{
  "rust-analyzer.cargo.loadOutDirsFromCheck": true,
  "rust-analyzer.procMacro.enable": true
}

Here’s my full settings.json file (I’ve restarted VSCode as prompted after changing the extension settings):

{
  "editor.tabSize": 4,
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.formatOnType": true,
  "files.insertFinalNewline": true,
  "files.trimTrailingWhitespace": true,
  "[rust]": {
    "editor.defaultFormatter": "matklad.rust-analyzer"
  },
  "rust-analyzer.cargo.loadOutDirsFromCheck": true,
  "rust-analyzer.procMacro.enable": true
}

Here’s the code snippets which causes the error to pop up:

// Cargo.toml dependency: ed25519-dalek = "1.0.1"
use ed25519_dalek::Keypair; // <--

Let me know if you need anything else and thanks in advance for looking into this 👍

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

If you want a quick fix that works right now you can add this to your VSCode settings file:

"rust-analyzer.cargo.unsetTest": [
    "core",
    "ed25519-dalek"
  ],

This removes the cfg(test) flag from that crate while rust analyzer is building it. core probably isn’t necessary for this specific issue. I can’t remember why I had that in there, but it fixes it for me, and you can add any other crates that have similar problems to that list, too.

I guess what we actually want is to disable test when a crate is used as a dependency, but enable it when opening the crate in the editor (unless the user disables it there, as per #7225).

No idea if/how this would make sense to the user though.

Hm, but why do we enable test for a crates.io dependency at all? We should do this only for workspace members, right?

The problem is this line https://docs.rs/ed25519-dalek/1.0.1/src/ed25519_dalek/lib.rs.html#238 I believe. Rust analyzer checks with test enabled so the entire crate looks empty to it.

… and even then RA could only load the crate with test once you start browsing its source code. Wasn’t something like this planned a while ago?