13

RLS is giving the following error message when working on a project with an ARM target:

E0463: can't find crate for test can't find crate

Reproduction:

cargo new --bin app
cd app
mkdir .cargo
echo '[build]' > .cargo/config
echo 'target = "thumbv7m-none-eabi"' >> .cargo/config
echo '#![no_std]' > src/main.rs
rls --cli

I believe this is because there is no test crate for the ARM target.

Is there a way to avoid this error?

There are several other SO posts on E0463 but appears those are configuration errors. The above is purely an RLS question. It's causing my editor to display errors and not do code complete, etc.

7
  • Issues with running RLS in no_std projects is what pushed me to switch over to Rust Analyzer. I also want to note that RLS isn't being actively developed and is poised to be superceded by RA.
    – Ivan C
    Commented Jan 14, 2021 at 16:21
  • 3
    @IvanC I am getting the same error with rust-analyzer.
    – puritii
    Commented Jan 14, 2021 at 16:41
  • I checked and I also have to add [unstable] build-std = ["core"] to .cargo/config.
    – Ivan C
    Commented Jan 14, 2021 at 17:42
  • @IvanC Does this mean you have to use unstable?
    – puritii
    Commented Jan 14, 2021 at 17:51
  • 1
    In general you have to use nightly if you want to cross-compile.
    – Ivan C
    Commented Jan 14, 2021 at 17:55

5 Answers 5

2

If you include:

{
  "rust-analyzer.cargo.target": "<your target architecture>",
  "rust-analyzer.check.allTargets": false,
}

and you are still getting the can't find crate for 'test' error on vscode, see if you have the Cargo extension by panicbit installed (https://marketplace.visualstudio.com/items?itemName=panicbit.cargo). It also uses cargo check on save without regards to the target architecture.

2

This is because of Cargo trying to build test&benchs for your binary targets when you pass --all-targets(which is done by default by rust-analyzer)

To solve this, you can try rewrote your main target, disable it's tests by adding this to Cargo.toml:

[[bin]]
name = "your_crate_name"
path = "src/main.rs"
test = false
doctest = false
bench = false
1
  • Thanks for your contribution! You may consider extending your answer by the information, on where the configuration snippet you provided should be placed, e.g. add a fragment like: "... by adding the following block to the <path/filename> file:" to the last sentence before the code block.
    – otterrisk
    Commented May 7 at 7:45
0

Found this in a github issue:

In the file .vscode/settings.json:

{
    "rust-analyzer.check.allTargets": false,
    "rust-analyzer.check.extraArgs": [
        "--target",
        "<your target architecture>"
    ]
}

Replace <your target architecture> with the right target.

1
  • I'm not sure when this changed but VS Code now seems to expect check instead of checkOnSave
    – will-hart
    Commented Feb 26, 2023 at 8:28
0

For Helix it is

# .helix/languages.toml
[[language]]
name = "rust"

[language-server.rust-analyzer.config.check]
targets = ["x86_64-unknown-linux-gnu"]
#allTargets = false
0

For VS Code workspaces

I you're wondering why the "rust-analyzer.*" properties in your .vscode folder are all grayed out even when you have the extension installed chances are you're using a workspace with multiple rust projects open, in which case you want to change the workspace settings under: File -> Preferences -> Settings -> Workspace tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.