Z029: Redundant @as in call argument
Detects @as(T, expr) in function call arguments or array/struct initializers where the parameter type already matches, making the cast redundant.
Examples
Bad
fn foo(x: u32) void {
_ = x;
}
// expect: Z029
pub fn main() void {
foo(@as(u32, 1));
}// expect: Z029
pub fn main() void {
const xs = [_]u32{@as(u32, 1)};
_ = xs;
}Good
Omit the redundant cast:
fn foo(x: u32) void {
_ = x;
}
pub fn main() void {
foo(1);
}
@as is appropriate when the types differ:
fn takeWide(x: u64) void {
_ = x;
}
pub fn main() void {
takeWide(@as(u32, 1));
}Rationale
When passing a value to a function or initializer where the expected type matches the value's type, @as does nothing. Removing these redundant casts reduces noise and makes intentional type conversions stand out.
Note: This rule requires semantic analysis to know parameter types. It won't flag calls where type information is unavailable.