Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E1301: Checked reason required

CodeCategoryStability
E1301Unchecked codePermanent

Explanation

Under the checked_reasons preview feature, every checked block states the invariant it relies on as a string literal between checked and the block, and that reason must not be empty. The reason is part of the syntax tree and is carried into the compiler's emitted views, so a reviewer or a tool can read why each unchecked site is sound without reconstructing it.

Likely cause

A checked block was written without a reason, or with an empty string, while compiling with --preview checked_reasons. State the invariant the block relies on; there is no per-site opt-out.

Examples

Omit the reason under the preview

Requires --preview checked_reasons.

fn main() -> i32 {
    let value: i32 = 42;
    let p: ptr const i32 = checked { @raw(value) };
    checked "p points at value, which outlives this read" { @ptr_read(p) }
}

State the invariant the block relies on

Requires --preview checked_reasons.

fn main() -> i32 {
    let value: i32 = 42;
    let p: ptr const i32 = checked "value is a live local for the whole call" { @raw(value) };
    checked "p points at value, which outlives this read" { @ptr_read(p) }
}

References