Skip to content

Unresolved import error for "ed25519_dalek::Keypair" #7243

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

Closed
pmuens opened this issue Jan 11, 2021 · 16 comments
Closed

Unresolved import error for "ed25519_dalek::Keypair" #7243

pmuens opened this issue Jan 11, 2021 · 16 comments
Labels
A-nameres name, path and module resolution S-actionable Someone could pick this issue up and work on it right now

Comments

@pmuens
Copy link

pmuens commented Jan 11, 2021

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 👍

@Veykril
Copy link
Member

Veykril commented Jan 11, 2021

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.

@lnicola
Copy link
Member

lnicola commented Jan 11, 2021

CC #7225

@jonas-schievink
Copy link
Contributor

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.

@lnicola
Copy link
Member

lnicola commented Jan 11, 2021

I suppose there's no chance of having something like "assume --cfg test while editing code gated by #[cfg(test)]", right?

@jonas-schievink
Copy link
Contributor

That would actually be my preferred solution. Not sure how feasible it is to implement though.

@flodiebold
Copy link
Member

I think both things you wrote are basically the same 😄 I.e. we need to have each crate (or at least each leaf crate) in a test and non-test version in the crate graph. Then hopefully the "assume --cfg test while editing code gated by #[cfg(test)]" would happen automatically as long as our "selecting the crate from the cursor position" logic is smart enough?

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Jan 18, 2021
@mieubrisse
Copy link

Adding a datapoint that I'm getting the exact same error:

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

@jplatte
Copy link
Contributor

jplatte commented Jul 2, 2021

dalek_ed25519 issue: dalek-cryptography/ed25519-dalek#173

@jonas-schievink
Copy link
Contributor

We should make this work by default

@matklad
Copy link
Member

matklad commented Nov 25, 2021

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

@jonas-schievink
Copy link
Contributor

Presumably to make IDE work when you browse unit tests

@bjorn3
Copy link
Member

bjorn3 commented Nov 25, 2021

You rarely need to browse unit tests of a crates.io dependency.

@jplatte
Copy link
Contributor

jplatte commented Nov 25, 2021

… 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?

@Veykril Veykril added the A-nameres name, path and module resolution label Nov 27, 2021
@zicklag
Copy link

zicklag commented Feb 15, 2022

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.

@g00nix
Copy link

g00nix commented Mar 18, 2022

Did anybody figure out the fix for neovim? I tried this but it doesn't work:

require'lspconfig'.rust_analyzer.setup({
    settings = {
        ["rust-analyzer"] = {
            cargo = {
              unsetTest = {
                  "core", "ed25519-dalek", "curve25519-dalek"
                }
            }
        }
    }
})

@flodiebold
Copy link
Member

flodiebold commented Jun 28, 2022

This works now (unless you have ed25519-dalek as a path dependency instead of from crates.io).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-nameres name, path and module resolution S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests