# Rust: error[E0133]: call to unsafe function `foo` is unsafe and requires unsafe function or block

**Code:** `E0133: call to unsafe function requires unsafe block` · **Category:** Rust · **Seen on:** Rust

You called an `unsafe` function (or dereferenced a raw pointer / accessed a `static mut`) outside `unsafe`.

## Meaning

Wrap in `unsafe { ... }` only after verifying the safety contract in the docs, or use a safe wrapper. For `static mut` prefer `AtomicUsize`, `Mutex`, `OnceLock`. In edition 2024 `unsafe_op_in_unsafe_fn` requires unsafe blocks inside unsafe fns too.

## Common causes

- FFI function call without unsafe block
- Raw pointer dereference
- `static mut` access
- Calling `get_unchecked`, `transmute`, etc.
- Edition 2024 requiring blocks inside unsafe fns

## Quick fix

1. Wrap the call in `unsafe { }` with a `// SAFETY:` comment
2. Replace `static mut` with atomics/Mutex
3. Use safe abstractions (bindgen wrappers, std APIs)

## Detailed fix by platform

### Rust

1. 

```rust
// SAFETY: ptr is valid and aligned per the caller contract
unsafe { *ptr }
```


## How to diagnose

1. **Function** — Unsafe contract?
2. **Alternative** — Safe API?
3. **static mut** — Replace?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/rust/e0133-call-to-unsafe-function-requires-unsafe-block)
