!#[no_std] Can’t find crate for ‘test’ エラーが表示されたときの対処法

Rust
Sponsored

Rustによる組込み開発用のコードをVSCodeで書いているとき、no_std Can't find crate for 'test'というエラーメッセージが表示されることがあります。

ビルドは通るので無視しても問題ないのですが、rust-analyzerによる文法チェックが機能しなくなるのは不便です。

この記事では、エラーメッセージを消すために、設定ファイルを作成する方法について解説します

解決法

※該当するファイルやディレクトリが存在しない場合は新規作成してください

プロジェクト(クレート)のディレクトリの直下にある .vscodeというディレクトリの、

setting.jsonというファイルに以下のように記述します。

{
    "rust.target": "thumbv6m-none-eabi",
    "rust.all_targets": false,
    "rust-analyzer.cargo.target": "thumbv6m-none-eabi",
    "rust-analyzer.checkOnSave": false
}

thumbv6m-none-eabiは、Raspberry Pi Pico (RP2040)の場合の例です。

ここの記述を、プロジェクトで開発を行っているターゲットのものに変更してください。

謝辞

この解決法は、艮電算術研究所が作成したRaspberry Pi Pico (RP2040)用の爆速開発テンプレート

rp_pico_templateのIssuesで教えていただきました。

[solved] no_std Can't find crate for 'test' · Issue #1 · doraneko94/rp_pico_template
I'm using rust-analyzer extension in VSCode. I had an error of no_std Can't find crate for 'test' in the top of line when I opened src/led.rs. So I add some pro...

Comments