Vscode-rust: no_std Can't find crate for 'test'

Created on 15 Jan 2020  Â·  8Comments  Â·  Source: rust-lang/vscode-rust

I have a no_std crate that is returning this single error message.
The code builds fine.

{
    "resource": "/Users/rubberduck/src/stm32f3-discovery/src/lib.rs",
    "owner": "rust",
    "code": "E0463",
    "severity": 8,
    "message": "can't find crate for `test`\n\ncan't find crate",
    "source": "rustc",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1,
    "relatedInformation": [
        {
            "startLineNumber": 1,
            "startColumn": 1,
            "endLineNumber": 1,
            "endColumn": 1,
            "message": "can't find crate",
            "resource": "/Users/rubberduck/src/stm32f3-discovery/src/lib.rs"
        }
    ]
}

This is the contents of the lib.rs file that is causing the error message.

#![no_std]

pub use stm32f3xx_hal::*;
pub mod leds;

I found these possibly related issues (but I'm doubtful they're actually related).

Most helpful comment

And for anyone using rust-analyzer + vscode, the .vscode/settings.json is:

{
    "rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
    "rust-analyzer.checkOnSave.allTargets": false
}

Thanks @imjasonmiller

All 8 comments

Did you manage to solve this? I'm experiencing the same :-) I do notice I'm also using the stm32f3xx_hal crate for what it's worth, although I'm using rust-analyzer with neovim.

No luck so far @imjasonmiller, but I haven’t dug into it.

@rubberduck203 I solved it in my case — see the linked issue. Hopefully it is of use to you. :-)

Confirmed works. Thanks @imjasonmiller.
Adding the following to .vscode/settings.json fixed it.

{
    "rust.target": "thumbv7em-none-eabihf",
    "rust.all_targets": false
}

And for anyone using rust-analyzer + vscode, the .vscode/settings.json is:

{
    "rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
    "rust-analyzer.checkOnSave.allTargets": false
}

Thanks @imjasonmiller

This solution fixes "can't find crate for 'core'" but not "for 'test'".

{
    "rust.target": "thumbv7em-none-eabihf",
    "rust.all_targets": false
}

Sadly, this is not working for me. I'm using RLS not rust-analyzer. I'm still getting "can't find crate for test" on my main lib.rs file.

{
    "rust.target": "thumbv7em-none-eabihf",
    "rust.all_targets": false
}

Sadly, this is not working for me. I'm using RLS not rust-analyzer. I'm still getting "can't find crate for test" on my main lib.rs file.

Me too. I'm getting this on my main.rs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tape-Worm picture Tape-Worm  Â·  4Comments

harrier-lcc picture harrier-lcc  Â·  4Comments

sfackler picture sfackler  Â·  6Comments

rpeshkov picture rpeshkov  Â·  5Comments

simobiggs picture simobiggs  Â·  4Comments