ziglint Changelog View on GitHub

Z018: Redundant @as cast

Detects @as(T, expr) where the expression is already of type T, making the cast redundant.

Examples

Bad

// expect: Z018
const x: u32 = 42;
const y: u32 = @as(u32, x);

Good

const x: u32 = 42;
const y: u32 = x;

@as is useful when type inference needs help and there's no type annotation:

const items = .{ @as(u32, 1), @as(u32, 2) };

Rationale

@as is for explicit type coercion. When the expression already has the target type, the cast does nothing and adds noise. Removing redundant casts makes the code clearer and highlights where actual type conversions occur.