Rust is a memory-safe programming language that disallows undefined behavior. Its safety guarantees have been extensively examined by the community through empirical studies, which has led to its remarkable success. However, unsafe code remains a critical concern in Rust. By reviewing the safety design of Rust and analyzing real-world Rust projects, this paper establishes a systematic framework for understanding unsafe code and undefined behavior, and summarizes the soundness criteria for Rust code. It further derives actionable guidance for achieving sound encapsulation.
翻译:Rust 是一种内存安全的编程语言,禁止未定义行为。其安全性保证已通过实证研究得到社区的广泛检验,这促成了其显著的成功。然而,不安全代码在 Rust 中仍然是一个关键问题。本文通过回顾 Rust 的安全性设计并分析现实世界中的 Rust 项目,建立了一个用于理解不安全代码和未定义行为的系统框架,并总结了 Rust 代码的可靠性准则。本文进一步推导出实现可靠封装的可操作指导。