Skip to content

Commit 96c6624

Browse files
committed
跟随上游 PR #477 更新
1 parent 47c9d65 commit 96c6624

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

src/beneath-std.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,11 @@ libc = { version = "0.2.146", default-features = false }
1919

2020
我们可能需要编译器的 nightly 版本来生成 `#![no_std]` 可执行文件,因为在许多平台上,我们必须提供不稳定的 `eh_personality` [lang item]
2121

22-
可以通过两种方式控制入口点:`#[start]` 属性,或者用您自己的函数覆盖 C 语言 `main` 函数的默认实现。此外,还需要定义一个 [panic handler function](panic-handler.html)
22+
你需要为你的目标平台定义一个适合的入口点符号,例如 `main``_start``WinMain` 或任何与你的目标平台相关的入口点名称
2323

24-
标记为 `#[start]` 的函数会以与 C 语言相同的格式传递命令行参数(除了使用的确切整数类型):
24+
此外,你需要使用 `#![no_main]` 属性,以防止编译器尝试自动生成入口点。
2525

26-
```rust
27-
#![feature(start, lang_items, core_intrinsics, rustc_private)]
28-
#![allow(internal_features)]
29-
#![no_std]
30-
31-
// 在 cfg(unix) 平台上,对于 `panic = "unwind"` 构建来说是必要的。
32-
#![feature(panic_unwind)]
33-
extern crate unwind;
34-
35-
// 导入 crt0.o 可能需要的系统 libc 库。
36-
#[cfg(not(windows))]
37-
extern crate libc;
38-
39-
use core::panic::PanicInfo;
40-
41-
// 本程序的入口点。
42-
#[start]
43-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
44-
0
45-
}
46-
47-
// 编译器使用这些函数,但对于像这样的空程序来说并不需要。
48-
// 它们通常由 `std` 提供。
49-
#[lang = "eh_personality"]
50-
fn rust_eh_personality() {}
51-
#[panic_handler]
52-
fn panic_handler(_info: &PanicInfo) -> ! { core::intrinsics::abort() }
53-
```
54-
55-
要覆盖编译器插入的 `main` shim,我们必须使用 `#![no_main]` 禁用它,然后使用正确的 ABI 和正确的名称创建适当的符号,这需要覆盖编译器的名称改编:
26+
另外,还需要定义一个[panic 处理函数](panic-handler.html)
5627

5728
```rust
5829
#![feature(lang_items, core_intrinsics, rustc_private)]

src/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
>
1616
> 如果大家对于翻译有更好的建议或者想法,欢迎直接 PR~
1717
>
18-
> 目前翻译基于 commit:d2c1d5cf8a296a481284252ddbb74211cc5782db,基于时间:2025/01/20
18+
> 目前翻译基于 commit:bc2298865544695c63454fc1f9f98a3dc22e9948,基于时间:2025/01/24
1919
>
2020
> Q:为什么不基于之前已有的中文版进行改进?
2121
>

0 commit comments

Comments
 (0)