E0418: Duplicate constant
| Code | Category | Stability |
|---|---|---|
E0418 | Struct and enum | Permanent |
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 }