rust-analyzer: `#![no_std]` can't find crate for `test` in vs code
Hi,
Same issue as #3297 but the solution there (for vim) does not seem to work for vs code on windows unfortunately.
Here is my setup:
.cargo\config file:
[build]
target = "thumbv7m-none-eabi"
.vscode\settings.json file:
{
"rust.target": "thumbv7m-none-eabi",
"rust.all_targets": false
}
src\main.rs file:
#![no_std]
#![no_main]
#[entry]
fn main() -> ! {
loop {}
}
rust-analyzer version: 0.2.108 vs code version: 1.43.2 operating system: Windows 10 rustc 1.42.0 (b8cedc004 2020-03-09) stable
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 47 (8 by maintainers)
Commits related to this issue
- Add proper cargo/rust-analyzer scan settings for vscode, solves https://github.com/rust-analyzer/rust-analyzer/issues/3801#issuecomment-681923193 for me — committed to brainstorm/bbtrackball-rs by brainstorm 6 years ago
- fix #![no_std] can't find crate for test in vs code https://github.com/rust-analyzer/rust-analyzer/issues/3801 — committed to Wazzaps/bold by Raz-B 5 years ago
- Fix a problem with VSCode rust-analyzer extension You need to specify the target platform or you get some errors. https://github.com/rust-lang/rust-analyzer/issues/3801 — committed to dcaponi/raw-dog by bcr 4 years ago
- Auto merge of #3801 - RalfJung:rustup, r=RalfJung Rustup — committed to lnicola/rust-analyzer by bors 2 years ago
- Fix vscode reporting non-existent issues: https://github.com/rust-lang/rust-analyzer/issues/3801 — committed to jacsjs/embedded-rs-lora by jacsjs 2 years ago
Looks like these keys keep changing. In the latest rust analyzer, it is this one for me
Thanks for the update @lnicola. Yes it broke but your new settings work, cheers!
Thank you @lnicola, that worked! Here is the required settings file if anyone else comes across this post:
.vscode\settings.json file:
Weirdly this issue occurred for me when simply copying a directory with an existing sample project, no issue in the original one but
can't find crate for 'test'in the new one. Since rust-analyzer changed over the years, and this thread is currently 4 years old, here is a currently working solution (VSCode 1.90, rust-analyzer v0.3.1995) on Linux: File.vscode/settings.json:Generally, when you try this or any other solution in
settings.json, pay attention that the lines you’ve pasted aren’t grayed out. You can always start typing and follow the auto-completion to check for changed syntax. This error message appears because by default the extension hasPass --all-targets to cargo invocation, and (probably) since we are#![no_std]in this case, we must set it to a specific target. This probably could be resolved with a fix in rust-analyzer.Please reopen issue
Not working for me either. Config:
I was having the same issue and after a little poking around I don’t think this is an issue with the rust-analyzer extension, but actually the
panicbit.cargoextension. It appears to runcargo checkon its own, which is running into issues with not properly knowing the target (I think), so it complains about not being able to find thetestcrate. If you’re having the same problem but the fixes here aren’t working, I’d check if that extension is installed, try disabling it, and see if the error persists.I am getting this error again. Is anyone else? I didn’t use to get it with
Well, it’s in the manual: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc#vs-code.
I cloned your repo and got the error message to go away by adding a .vscode/settings.json file in your project root with
VS Code needed a restart for rust-analyzer to pick it up.
So the file structure is (I’ve included the important files):
You were missing the settings.json file.
Thanks ❤️ ,
rustup updatefixed it ! It sure feels like a hack though…ok, sounds like the issue is now resolved, at least there’s a documentation trail for this here now 😃
Well done all of the above and checked the global settings config and can’t spot anything obviously wrong so I’ll just keep it broken.
below is my global vscode settings file.
It seems to not be working for me.
still results in the test error in vscode.