vscode-rust
vscode-rust copied to clipboard
Issue when defining a panic function with #![no_std]
Hello,
I am currently trying to write an operating system in Rust. Obviously I can't link to the std lib and I need to write my own panic function. As of right now the plugin is giving me an error saying that it found a duplicate panic_impl item however it compiles fine. Is there a way you could check for #![no_std] and prevent this error from showing up? Or is there any way I can configure the plugin to ignore this error?
Error:
found duplicate lang item `panic_impl` the lang item is first defined in crate `std` (which `test` depends on) first definition in `std` loaded from /home/grvy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-93cbfed54dd1bac8.rlib second definition in the local crate (`grvy_os`)rustc(E0152)
Code:
#![no_std] // don't link to the Rust std library
#![no_main] // disable all Rust-level entry points
use core::panic::PanicInfo;
#[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
// this function is the entry point, since the linker looks for a function
// named '_start' by default
loop {}
}
// this function is called on panic
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}```
Looks like the compiler might end up using the equivalent of --all-targets. Amusingly, rust-analyzer has the same "problem" by default.
Yes, I am having the same issue. #![no_std] gives me this false error:
There is #729 which was closed with this fix:
{
"rust.target": "thumbv7em-none-eabihf",
"rust.all_targets": false
}
That issue should not have been closed because this doesn't work for me (probably because I use rust-analyzer). It says Unknown Configuration Setting.
Another fix that was mentioned in that issue that does work for me is this:
{
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
"rust-analyzer.checkOnSave.allTargets": false
}
However, this does not only disable the error for #![non_std], but all errors and warnings.
Also, it looks like a dirty hack to me. Most of the time the thumbv7em-none-eabihf target isn't what you are actually working with.
I hope vscode-rust/rust-analyzer will properly fix this issue and support #![non_std].
@r00ster91 matklad.rust-analyzer is independent of this extension (rust-lang.rust), so don't mix them -- and feel free to file any rust-analyzer specific issues over there.
In your case I think "rust-analyzer.checkOnSave.allTargets": false should suffice.
Unfortunately neither of these fixes works for me so I guess Ill just have to deal with it for now
I am also having this same issue with no luck fixing it
Guys please fix it! This really annoying (((