How to avoid "E0463: can't find crate for `test` can't find crate" when building for thumbv7m-none-eabi?

5.3k Views Asked by At

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.

2

There are 2 best solutions below

1
On

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.

0
On

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.