How to activate unstable feature restricted_std in rust-analyzer?

Moderators’ note:
This question was also asked on stack overflow. Keep an eye out for additional discussions or solutions posted over there.


I'm trying to compile for esp32c6 (riscv32imac-unknown-none-elf). Actually, cargo build runs, but when I save the file rust analyzer checks it ans complains:

error[E0658]: use of unstable library feature 'restricted_std'
   --> /home/lz/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/formatters/json.rs:225:55
    |
225 |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> ::std::fmt::Result {
    |                                                       ^^^^^^^^^^^^^^^^^^
    |
    = help: add `#![feature(restricted_std)]` to the crate attributes to enable

As you see, it's complaining about a feature in the std lib, which is strange. I added #![feature(restricted_std)] to main.rs but the error is in the standard library where I cannot add this feature.

I also tried

{
    "rust-analyzer.cargo.cfgs": {
        "build-std": ["core", "std", "alloc", "panic_abort"],
        "restricted_std": true
    },
    "rust-analyzer.check.allTargets": false,
    "rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf",
}

and other variations without success. Also tried

[unstable]
features=["restricted_std"]

in rust-analyzer.toml.

Also

~/project1$ rustup toolchain install riscv32imac-unknown-none-elf
error: invalid toolchain name: 'riscv32imac-unknown-none-elf'