Back to Comprehensive Rust

Why learn unsafe Rust?

src/unsafe-deep-dive/motivations.md

latest738 B
Original Source
<!-- Copyright 2025 Google LLC SPDX-License-Identifier: CC-BY-4.0 -->

Why learn unsafe Rust?

We know that writing code without the guarantees that Rust provides ...

“Use-after-free (UAF), integer overflows, and out of bounds (OOB) reads/writes comprise 90% of vulnerabilities with OOB being the most common.”

Jeff Vander Stoep and Chong Zhang, Google. "Queue the Hardening Enhancements"

... so why is unsafe part of the language?

Outline

{{%segment outline}}

<details>

The unsafe keyword exists because there is no compiler technology available today that makes it obsolete. Compilers cannot verify everything.

</details>