Skip to content
← All Rust tracks

Unsafe and Soundness

Rust

Work through raw pointers, memory invariants and undefined behavior. Learn what an unsafe operation requires and how a safe interface must uphold those requirements.

This track uses Rust. You can make it your practice mode to browse related content across the site.

19 exercises

5 articles

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Safe and unsafe Rust: obligations and soundness Read
  2. 2 Not solved yet. What unsafe allows, and what it does not change Practice · Easy
  3. 3 Not solved yet. unsafe {} vs unsafe fn: edition 2024 splits the two meanings Practice · Easy
  4. 4 Not solved yet. Safety comments as a discipline: // SAFETY: and # Safety Practice · Easy
  5. 5 Not solved yet. Raw pointers: *const T and *mut T Practice · Easy
  6. 6 Not solved yet. &raw const / &raw mut: a pointer without a reference Practice · Medium
  7. 7 Not solved yet. Pointer arithmetic: offset, add, sub, wrapping_* Practice · Medium
  8. 8 Not solved yet. ptr::read, write, copy, copy_nonoverlapping, drop_in_place Practice · Medium
  9. 9 Not solved yet. NonNull<T>, null, and dangling-but-aligned Practice · Medium
  10. 10 Not solved yet. Provenance: a pointer is not an integer Practice · Hard
  11. 11 What is Undefined Behaviour? The complete list Read
  12. 12 Not solved yet. Validity invariants vs safety invariants Practice · Medium
  13. 13 Aliasing, mutable references and unsafe code Read
  14. 14 Stacked Borrows, Tree Borrows and Miri Read
  15. 15 Not solved yet. UnsafeCell: the only legal path to interior mutability Practice · Medium
  16. 16 Not solved yet. Build a vector with allocation, push and pop Practice · Hard
  17. 17 Not solved yet. Extend a vector with insertion and consuming iteration Practice · Hard
  18. 18 Not solved yet. Implementing a reference-counted pointer Practice · Hard
  19. 19 Not solved yet. PhantomData, variance and drop-check Practice · Hard
  20. 20 Safety invariants and privacy: unsafe contaminates the module Read
  21. 21 Not solved yet. Keep a vector valid when its drain is forgotten Practice · Hard
  22. 22 Not solved yet. Build a safe mutable-slice split Practice · Medium
  23. 23 Not solved yet. union, transmute and MaybeUninit Practice · Hard
  24. 24 Not solved yet. Build a ring buffer with MaybeUninit Practice · Hard

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

What does the unsafe block permit in this program?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

fn main() {
    let value = 42u32;
    let pointer = &value as *const u32;
    // SAFETY: pointer refers to the live, aligned, initialized value above.
    // Nothing mutates value while this shared read occurs.
    let copied = unsafe { *pointer };
    println!("{copied}");
}
Question 1 of 4