We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Unsafe and Soundness
RustWork 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.
Your learning sequence
- 1 Safe and unsafe Rust: obligations and soundness Read
-
2
Not solved yet.
What
unsafeallows, and what it does not change Practice · Easy -
3
Not solved yet.
unsafe {}vsunsafe fn: edition 2024 splits the two meanings Practice · Easy -
4
Not solved yet.
Safety comments as a discipline:
// SAFETY:and# SafetyPractice · Easy -
5
Not solved yet.
Raw pointers:
*const Tand*mut TPractice · Easy -
6
Not solved yet.
&raw const/&raw mut: a pointer without a reference Practice · Medium -
7
Not solved yet.
Pointer arithmetic:
offset,add,sub,wrapping_*Practice · Medium -
8
Not solved yet.
ptr::read,write,copy,copy_nonoverlapping,drop_in_placePractice · Medium -
9
Not solved yet.
NonNull<T>, null, and dangling-but-aligned Practice · Medium - 10 Not solved yet. Provenance: a pointer is not an integer Practice · Hard
- 11 What is Undefined Behaviour? The complete list Read
- 12 Not solved yet. Validity invariants vs safety invariants Practice · Medium
- 13 Aliasing, mutable references and unsafe code Read
- 14 Stacked Borrows, Tree Borrows and Miri Read
-
15
Not solved yet.
UnsafeCell: the only legal path to interior mutability Practice · Medium - 16 Not solved yet. Build a vector with allocation, push and pop Practice · Hard
- 17 Not solved yet. Extend a vector with insertion and consuming iteration Practice · Hard
- 18 Not solved yet. Implementing a reference-counted pointer Practice · Hard
-
19
Not solved yet.
PhantomData, variance and drop-check Practice · Hard - 20 Safety invariants and privacy: unsafe contaminates the module Read
- 21 Not solved yet. Keep a vector valid when its drain is forgotten Practice · Hard
- 22 Not solved yet. Build a safe mutable-slice split Practice · Medium
-
23
Not solved yet.
union,transmuteandMaybeUninitPractice · Hard - 24 Not solved yet. Build a ring buffer with MaybeUninit Practice · Hard
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
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}");
}