## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

[safety]

# Unsafety

[safety.intro]

Unsafe operations are those that can potentially violate the memory-safety guarantees of Rust’s static semantics.

[safety.unsafe-ops]

The following language level features cannot be used in the safe subset of Rust:

[safety.unsafe-deref]

- Dereferencing a raw pointer.

[safety.unsafe-static]

- Reading or writing a mutable or external static variable.

[safety.unsafe-union-access]

- Accessing a field of a `union`, other than to assign to it.

[safety.unsafe-call]

- Calling an unsafe function (including an intrinsic or foreign function).

[safety.unsafe-target-feature-call]

- Calling a safe function marked with a `target_feature` from a function that does not have a `target_feature` attribute enabling the same features (see attributes.codegen.target_feature.safety-restrictions).

[safety.unsafe-impl]

- Implementing an unsafe trait.

[safety.unsafe-extern]

- Declaring an `extern` block1.

[safety.unsafe-attribute]

- Applying an unsafe attribute to an item.

1. Prior to the 2024 edition, extern blocks were allowed to be declared without `unsafe`. ↩