Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

no_std Can't find crate for 'test' #729

Closed
rubberduck203 opened this issue Jan 15, 2020 · 19 comments
Closed

no_std Can't find crate for 'test' #729

rubberduck203 opened this issue Jan 15, 2020 · 19 comments

Comments

@rubberduck203
Copy link

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).

@imjasonmiller
Copy link

imjasonmiller commented Feb 9, 2020

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.

@rubberduck203
Copy link
Author

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

@imjasonmiller
Copy link

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

@rubberduck203
Copy link
Author

rubberduck203 commented Feb 26, 2020

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

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

@trown
Copy link

trown commented May 29, 2020

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

@JohnDowson
Copy link

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

@andy-preston
Copy link

{
    "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.

@duskmoon314
Copy link

{
    "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.

@YoshieraHuang
Copy link

{
    "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 wonder that it may need another equivelant settings to this in rust-analyzer:

{
    "rust-analyzer.checkOnSave.extraArgs": [
        "--bins"
    ],
}

@asukiaaa
Copy link

I cannot resolve error can't find crate for test`` on rust plugin on VSCode.

Screenshot from 2021-12-25 18-34-09

However I could resolve it with using rust-analyzer plugin on VSCode.
Ref rust-lang/rust-analyzer#3801

Screenshot from 2021-12-25 18-34-43

I think that configuration for rust-analyzer via the rust-plugin.
Is there any option to resolve the error on the rust-plugin plugin?
(For each actions, I reload the window of VSCode.)

@lnicola
Copy link
Member

lnicola commented Dec 25, 2021

@asukiaaa if rust-analyzer works, do you have any reason to avoid it?

@asukiaaa
Copy link

I can use rust-analyzer plugin with disabling rust-plugin (this plugin) but what the meaning of presence for rust-plugin?

@lnicola
Copy link
Member

lnicola commented Dec 25, 2021

rust-analyzer will sooner or later replace RLS (and the Rust extension), see also #927.

@asukiaaa
Copy link

I see, thank you for the information.

@rishadbaniya
Copy link

For people using rust analyzer with coc and neovim, look for coc-settings.json in google for rust analyzer and fill those attributes

@shenshouer
Copy link

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

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

not worked for me ~

@pluveto
Copy link

pluveto commented Mar 6, 2022

Not working

{
    "rust.target": "riscv64gc-unknown-none-elf",
    "rust.all_targets": false,
}

@cjm571
Copy link

cjm571 commented Apr 19, 2022

Ran into this same issue and was able to fix it by adding the following to my Cargo.toml:

[[bin]]
name = "app"
test = false
bench = false

@BRA1L0R
Copy link

BRA1L0R commented May 24, 2022

Solution for rust-analyzer

Add these lines in .vscode/settings.json:

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests