01-unsafe 关键字
unsafe 关键字 — The Rust Reference
1分钟内可阅读完
译文 · 基于 The Rust Reference
r[safety]
r[safety.intro] 不安全操作是那些可能违反 Rust 静态语义所保证的内存安全的操作。
r[safety.unsafe-ops] 下列语言级特性不能在 Rust 的安全子集中使用:
r[safety.unsafe-deref]
r[safety.unsafe-static]
r[safety.unsafe-union-access]
union 的字段(赋值除外)。r[safety.unsafe-call]
r[safety.unsafe-target-feature-call]
target_feature 属性的函数中,调用带有 [target_feature][attributes.codegen.target_feature] 标记的安全函数(参见 [attributes.codegen.target_feature.safety-restrictions])。r[safety.unsafe-impl]
r[safety.unsafe-extern]
r[safety.unsafe-attribute]
在 2024 edition 之前,允许在没有 unsafe 的情况下声明 extern 块。 ↩︎
unsafe 关键字 — The Rust Reference
视为未定义行为 — The Rust Reference
不视为不安全的行为 — The Rust Reference