Troubleshooting Unresolved Import in rust-analyzer


I'm trying to troubleshoot rust-analyzer reporting "unresolved import".

In the past, it's reported that heapless doesn't exist. Now it sometimes reports num_traits doesn't exist. Both of these crates exist in the Cargo.toml, and the crate builds fine, but somehow rust-analyzer isn't reflecting that.

To make things even weirder, I decided to try cloning the repo so I could post this question, and I get different behavior. Namely, my unmodified working copy can't find num_traits, while the freshly-cloned one can't find heapless (fresh clone on the left, working one on the right):

The command I'm using to clone is:

git clone -b xous-ipc-refactor

Right now the failing crate is in services/xous-names, however I've had various failures over the past few months.

Some things to note:

  • There is a .vscode/settings.json that sets the default target to riscv32imac-unknown-none-elf
  • My global settings don't have anything related to Rust
  • Sometimes I see different results when using WSL. For example, right now Windows is showing num_traits as being unresolved, whereas WSL is showing heapless as being unresolved.

What causes "unresolved import" and how can I track down what the issue is?

Are you on the current rust-analyzer release? This should be working now. Make sure the "run build scripts" setting is enabled.

The extension identifies itself as nightly if I run rust-analyzer-x86_64-pc-windows-msvc.exe --version. However, in the output console it identifies itself as 0.2.538.

If I remove that file, it gives me an error saying "Language server version 0.2.538 for rust-analyzer is not installed." and offers to download it again. Upon downloading it, it still shows heapless::consts::* as being an unresolved import.

I may be running into loadOutDirsFromCheck / proc macro ergonomics · Issue #6448 · rust-analyzer/rust-analyzer · GitHub however adding this to my settings doesn't fix things, so I'm not sure if that's the issue:

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

The setting for build scripts / OUR_DIRs is now called rust-analyzer.cargo.runBuildScripts. It should be on by default though.

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.