From the Rust Tidbits: What Is a Lang Item?, there is a piece of code, I copied and put in the
src/main.rs
#![feature(no_core)]
#![feature(lang_items)]
// Look at me.
// Look at me.
// I'm the libcore now.
#![no_core]
// Tell the compiler to link to appropriate runtime libs
// (This way I don't have to specify `-l` flags explicitly)
#[cfg(target_os = "linux")]
#[link(name = "c")]
extern {}
#[cfg(target_os = "macos")]
#[link(name = "System")]
extern {}
// Compiler needs these to proceed
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
// `main` isn't the actual entry point, `start` is.
#[lang = "start"]
fn start(_main: *const u8, _argc: isize, _argv: *const *const u8) -> isize {
// we can't really do much in this benighted hellhole of
// an environment without bringing in more libraries.
// We can make syscalls, segfault, and set the exit code.
// To be sure that this actually ran, let's set the exit code.
42
}
// still need a main unless we want to use `#![no_main]`
// won't actually get called; `start()` is supposed to call it
fn main() {}
The Cargo.toml is:
[package]
name = "no_core_code"
version = "0.1.0"
edition = "2021"
[dependencies]
I run at the Dir of Cargo.toml:
cargo +nightly build -Z unstable-options
The Error:
error[E0718]: `start` language item must be applied to a function with 1 generic argument
--> no_core_code/src/main.rs:25:1
|
25 | #[lang = "start"]
| ^^^^^^^^^^^^^^^^^
26 | fn start(_main: *const u8, _argc: isize, _argv: *const *const u8) -> isize {
| - this function has 0 generic arguments
How to solve it?