diagnostic codes / Types
E0207 implicit-conversion-denied
The operation is not defined for this type, and no cast creates the definition.
E0207implicit-conversion-deniedno implicit conversions exist; use cast<T>(x) for exact or explicit lossy casts
| severity | error |
|---|---|
| band | Types |
| in the v0 bootstrap | emitted |
| explain | ralt explain E0207 |
The table uses E0207 for type-directed refusals that are not a mismatch between two sides: composite equality, array equality, and casts that are not in the conversion table. The message names the operation and the type; the hint says what to write instead.
What it looks like
e0207.tp
use tier core; struct P { x: i32; y: i32; } fn main() -> i32 { let a = P { x: 1, y: 2 }; let b = P { x: 1, y: 2 }; if a == b { print_str("eq"); } return 0; }
ralt check e0207.tp e0207.tp:8:8: error: composite equality on P is not defined; no cast exists for it [E0207 implicit-conversion-denied] no implicit conversions exist; use cast<T>(x) for exact or explicit lossy casts e0207.tp:8:8: error: condition must be bool [E0202 type-mismatch] types must match exactly; no implicit conversion exists; use cast<T>(x)
The second line is cascade: the failed `==` produced no type, and `if` then reports that its condition is not `bool`. The first line is the one to fix.
What to do
- Compare composites field by field: `a.x == b.x && a.y == b.y`.
- Arrays compare element by element too; there is no builtin slice comparison in v0.
- `str` and `bool` do support `==` and `!=` directly.
- Only integer↔integer, float↔float, integer↔float casts are defined; `cast<i32>(someBool)` is this code.
Why the code exists
Equality is not free: it is a generated function with a cost, and a language that hides it makes `if bigStruct == other` look like a comparison of two words. Requiring the loop makes the cost visible.
What ralt explain says
ralt explain E0207 E0207 severity: error name: implicit-conversion-denied hint: no implicit conversions exist; use cast<T>(x) for exact or explicit lossy casts
Related
- Operators /docs/reference/operators
- Types and inference /docs/language/types
- Structs, enums, match /docs/language/data