Why this fires¶
A const declaration has an explicit type annotation, but the value's inferred type is not assignable to it.
const MAX: int = "one hundred"
// ^^^^^^^^^^^^^ error[TE002]: type mismatch in const: expected int, found strconst bindings are checked the same way let bindings are (see TE001) — the only difference is that the value must also be a compile-time constant expression (that separate rule is TE003).
Fix it¶
1. Fix the value¶
const MAX: int = 100 // ok2. Fix the annotation¶
If the annotation was wrong and the value is the one you want to keep:
const LABEL: str = "one hundred" // ok3. Drop the annotation and let it infer¶
const MAX = 100 // ok — type is inferred as intSee also¶
TE001— the same check forletbindings.TE003—const's value must also be a compile-time constant.- /docs/variables-and-types —
let/var/constsemantics.