Docs menu

E130: Raw pointers can only be used inside unsafe

What compiler error E130 means, and how to fix it.

A raw pointer (ptr, or int*, Point*, …) is a memory address with none of Turf’s safety checks: it can be null, it can point at something that has been freed, and it can be read past its end. Turf only lets you use one inside an unsafe { } block, where you are saying “I am taking responsibility for this”.

Example
fn main(): int {    mut p: ptr = null;            // not allowed out here    return 0;}

Put the code that needs it inside unsafe:

Example
fn main(): int {    unsafe {        mut p: ptr = null;        ...    }    return 0;}

Or avoid raw pointers altogether. A safe reference, &T, covers almost everything a beginner needs a pointer for, and &?T is the version that may be null.

A raw pointer also can’t appear in an ordinary function’s signature – not even inside unsafe. Use &T for parameters and return values; only extern fn declarations (bindings to C) may use raw pointers there.

A to cast between a reference and something that is not a reference to the same type needs unsafe too: making a reference (0 to &N, s to &N, r to &M) may point it at nothing, and r to string reads the referenced bytes as text instead of formatting the value. Convert a field instead: r.x to string.

Run turf --explain E130 in a terminal to read this again.

Last updated: Oct 15, 2026Edit this page on GitHub

Esc

Type to search.