-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect build issue displayed: "found duplicate lang item panic_impl
"
#4490
Comments
This error is coming from |
I added a custom target and updated
and defined the target as follows:
This fixed the initial error from the issue. However, when I run
When I actually build the project I must use How does |
You can change the
In your case, maybe something like this will works:
(Not sure xcheck support --json-output) |
Yes, that looks like it has resolved it. Thanks so much for your reply and also for your work on rust-analyzer. It is a fantastic project! |
I'm a bit confused as to the solution. Where is this |
ctrl-shift-p > "Preferences: Open Settings (JSON)" for the global settings. ctrl-shift-p > "Preferences: Open Workspace Settings (JSON)" or |
I'm not on VSCode. I'm using coc-rust-analyzer. Is this an IDE specific thing? |
Yes, every IDE has it's own way to pass settings to a language server. |
You're using neovim yes?
Then copy and paste @edwin0cheng 's response :) |
Hi! I'm also getting this, but my
[build]
rustflags = ["-C", "link-arg=-nostdlib", "-C", "link-arg=-static"]
#![no_std]
#![no_main]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
fn _start() -> ! {
loop {}
}
[package]
name = "shellcode"
edition = "2018"
version = "0.0.0"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort" |
Does |
@bjorn3 you hit the nail right on the head! I just found this independently with bpftrace's execsnoop before looking at GitHub again 😅. Thanks! |
Does anyone know how to set |
Sorry to necro this issue, but I had the same issue as the OP and I think I solved it using
The function is then greyed-out within VSCode. |
It was displaying a "duplicate lang item" error on the panic handler. This was also displayed when running "cargo check --all-targets". The workaround to add #[cfg(not(test))] is from rust-lang/rust-analyzer#4490 (comment)
I recently had the same issue when using rust-analyzer (v0.3.1348) and CLion with a Rust plugin. I was targeting my MCU, so the solution was to set the target in [build]
target = "thumbv7em-none-eabihf" |
i did as you mentioned #![no_std]
#![no_main]
#![allow(unused_imports)]
use core::panic::PanicInfo;
#[no_mangle]
pub extern "C" fn _start() -> ! {
loop {}
}
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
} but i don't think its the best way to handle the warning |
Worked for me! Thanks! |
I am following the writing an OS in Rust tutorials and in the first section it describes creating a
no_std
binary and you must specify the panic handler. The following code compiles file but rust-analyzer believes there is an error and shows it in VSCode.I tried setting the target to one that doesn't link with the OS,
settings.json
:Rust-analyzer extension version: 0.2.166
The text was updated successfully, but these errors were encountered: