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

E0418: Duplicate constant

CodeCategoryStability
E0418Struct and enumPermanent

Explanation

A source file declares two top-level constants with the same name. Constant names are module-scoped, and a const/const collision within one file is ambiguous.

Likely cause

A constant declaration was copied, generated twice, or renamed to an existing constant's name. Remove one declaration or give each constant in the file a distinct name; another module may independently use the same name.

Examples

Duplicate constant name

const LIMIT: i32 = 40;
const LIMIT: i32 = 42;
fn main() -> i32 { LIMIT }

Use distinct constant names

const BASE: i32 = 40;
const LIMIT: i32 = 42;
fn main() -> i32 { LIMIT - BASE }

References