Lune

OOPSLA2020Top-tier venue

How do programmers use unsafe rust?

Vytautas Astrauskas, Christoph Matheja, Federico Poli, Peter Müller, Alexander J. Summers

Abstract

Rust’s ownership type system enforces a strict discipline on how memory locations are accessed and shared. This discipline allows the compiler to statically prevent memory errors, data races, inadvertent side effects through aliasing, and other errors that frequently occur in conventional imperative programs. However, the restrictions imposed by Rust’s type system make it difficult or impossible to implement certain designs, such as data structures that require aliasing (e.g. doubly-linked lists and shared caches). To work around this limitation, Rust allows code blocks to be declared as unsafe and thereby exempted from certain restrictions of the type system, for instance, to manipulate C-style raw pointers. Ensuring the safety of unsafe code is the responsibility of the programmer. However, an important assumption of the Rust language, which we dub the Rust hypothesis , is that programmers use Rust by following three main principles: use unsafe code sparingly, make it easy to review, and hide it behind a safe abstraction such that client code can be written in safe Rust. Understanding how Rust programmers use unsafe code and, in particular, whether the Rust hypothesis holds is essential for Rust developers and testers, language and library designers, as well as tool developers. This paper studies empirically how unsafe code is used in practice by analysing a large corpus of Rust projects to assess the validity of the Rust hypothesis and to classify the purpose of unsafe code. We identify queries that can be answered by automatically inspecting the program’s source code, its intermediate representation MIR, as well as type information provided by the Rust compiler; we complement the results by manual code inspection. Our study supports the Rust hypothesis partially: While most unsafe code is simple and well-encapsulated, unsafe features are used extensively, especially for interoperability with other languages.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

27 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise cites Rudra: Finding Memory Safety Bugs in Rust at the Ecosystem Scale
  • An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise cites Understanding memory and thread safety practices and issues in real-world Rust programs
  • An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise cites Is rust used safely by software developers?
  • An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise cites Learning and Programming Challenges of Rust: A Mixed-Methods Study
  • Rudra: Finding Memory Safety Bugs in Rust at the Ecosystem Scale cites Understanding memory and thread safety practices and issues in real-world Rust programs
  • Rudra: Finding Memory Safety Bugs in Rust at the Ecosystem Scale cites Is rust used safely by software developers?
  • Learning and Programming Challenges of Rust: A Mixed-Methods Study cites Understanding memory and thread safety practices and issues in real-world Rust programs
  • Learning and Programming Challenges of Rust: A Mixed-Methods Study cites Is rust used safely by software developers?
  • Translating C to safer Rust cites Understanding memory and thread safety practices and issues in real-world Rust programs
  • Translating C to safer Rust cites Is rust used safely by software developers?
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers27

  1. Using Lightweight Formal Methods to Validate a Key-Value Storage Node in Amazon S3James Bornholt, Rajeev Joshi, Vytautas Astrauskas, Brendan Cully et al.SOSP 2021 · 63 citations
  2. Rudra: Finding Memory Safety Bugs in Rust at the Ecosystem ScaleYechan Bae, Youngsuk Kim, Ammar Askar, Jungwon Lim et al.SOSP 2021 · 61 citations
  3. Translating C to safer RustMehmet Emre, Ryan Schroeder, Kyle Dewey, Ben HardekopfOOPSLA 2021 · 60 citations
  4. An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and CompromiseHongyu Li, Liwei Guo, Yexuan Yang, Shangguang Wang et al.USENIX ATC 2024 · 29 citations
  5. Learning and Programming Challenges of Rust: A Mixed-Methods StudyShuofei Zhu, Ziyi Zhang, Boqin Qin, Aiping Xiong et al.ICSE 2022 · 27 citations

Builds on2

  1. Understanding memory and thread safety practices and issues in real-world Rust programsBoqin Qin, Yilun Chen, Zeming Yu, Linhai Song et al.PLDI 2020 · 112 citations
  2. Is rust used safely by software developers?Ana Nora Evans, Bradford Campbell, Mary Lou SoffaICSE 2020 · 57 citations

Related papers

  1. "I wouldn't want my unsafe code to run my pacemaker": An Interview Study on the Use, Comprehension, and Perceived Risks of Unsafe RustSandra Höltervennhoff, Philip Klostermeyer, Noah Wöhler, Yasemin Acar et al.USENIX Security 2023
  2. Aliasing Limits on Translating C to Safe RustMehmet Emre, Peter Boyland, Aesha Parekh, Ryan Schroeder et al.OOPSLA 2023 · 32 citations
  3. RustSan: Retrofitting AddressSanitizer for Efficient Sanitization of RustKyuwon Cho, Jongyoon Kim, Kha Dinh Duy, Hajeong Lim et al.USENIX Security 2024 · 7 citations
  4. Tree BorrowsNeven Villani, Johannes Hostert, Derek Dreyer, Ralf JungPLDI 2025 · 8 citations
  5. TRust: A Compilation Framework for In-process Isolation to Protect Safe Rust against Untrusted CodeInyoung Bang, Martin Kayondo, Hyungon Moon, Yunheung PaekUSENIX Security 2023
Dusk over the sea between two cliffs drawn in fine vertical lines