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

Issue when defining a panic function with #![no_std] #904

Open
GRVYDEV opened this issue Apr 7, 2021 · 6 comments
Open

Issue when defining a panic function with #![no_std] #904

GRVYDEV opened this issue Apr 7, 2021 · 6 comments

Comments

@GRVYDEV
Copy link

GRVYDEV commented Apr 7, 2021

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 {}
}```
@lnicola
Copy link
Member

lnicola commented Apr 7, 2021

Looks like the compiler might end up using the equivalent of --all-targets. Amusingly, rust-analyzer has the same "problem" by default.

@wooster0
Copy link

wooster0 commented Apr 8, 2021

Yes, I am having the same issue. #![no_std] gives me this false error:
image
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].

@lnicola
Copy link
Member

lnicola commented Apr 8, 2021

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

@GRVYDEV
Copy link
Author

GRVYDEV commented Apr 9, 2021

Unfortunately neither of these fixes works for me so I guess Ill just have to deal with it for now

@ryanfuji
Copy link

I am also having this same issue with no luck fixing it

@udik-chudik
Copy link

Guys please fix it! This really annoying (((

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

5 participants