Rust-analyzer unable to resolve target-specific module

I have this in my editor config (neovim, coc):

// https://github.com/rust-analyzer/rust-analyzer/blob/master/editors/code/package.json
{
    "rust-analyzer.cargo.target": "wasm32-unknown-emscripten",

    // This is required as `cargo check --all-targets` doesn't seem to work well
    // on no-std crates, it generates false "duplicate lang item" errors.
    "rust-analyzer.checkOnSave.allTargets": false,
    "rust-analyzer.cargo.features": [...]
}

So the target is wasm32, but I'm getting "unresolved import" error in line use core::arch::wasm32;. Any tips? I tried removing this line completely, or trying other Wasm targets like wasm32-wasi, but no luck.

core::arch does not work in rust-analyzer, regardless of the target. This is tracked in Importing intrinsics gives "unresolved import" · Issue #6077 · rust-analyzer/rust-analyzer · GitHub

I don't think this is easy to fix, the problem is sadly pretty deep. The main issue is that core::arch module is defined in the standard library as a path inclusion of an stdarch crate:

And stdarch crate isn't actually included in rust-src component.

I feel like I probably should open an issue at the rust-lang/rust repo to have a central discussion point, as its pretty clear we want to fix this....

The relevant stdarch files can be found at ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/core_arch/*, I think it's a problem with how rust-analyzer collects source files

1 Like

Heh, there's no reason for this to now work then, fixed in fix: resolve core::arch module by matklad · Pull Request #9963 · rust-analyzer/rust-analyzer · GitHub.

3 Likes

That was fast, thanks :slight_smile:

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.