You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a value is assigned, returned, or otherwise has a RLS with a static type, disallow re-specifying that type. This mostly means changing struct literals to anonymous struct literals, removing redundant @as, or using a decl literal over a namespace.
constx: u32=@as(u32, @intCast(y)); // remove as expressionpubfnf1(a: u64) u32 {
return@as(u32, @intCast(a)); // remove as expression
}
constT=struct {
field: u32,
constx: T= .{ .field=2 };
};
pubfnhello(a: T) void {
_=a;
}
constEnum=enum { a };
constz: Enum=z: {
hello(T{ // remove `T`
.field=@as(u32, @intCast(y)), // remove as expression
});
hello(T.x); // Remove `T`break :zEnum.z; // remove `Enum`
};
fnother(comptimehello: type, n: u64) SomeComplex(hello) {
returnSomeComplex(hello).init(n);
// use decl literal `.init(n)`// can realize that the literal text `SomeComplex(hello)` is re-used
}
Examples that would not be flagged.
constx=@as(u32, @intCast(y)); // destination has no typepubfngoodbye(a: anytype) void {
_=a;
}
comptime {
goodbye(T{ // cannot remove T as argument is `anytype`
.field=@as(u32, @intCast(y)), // `.field` has no type
});
}
fnother(n: u64) u32 {
// when the types are not the same, it should not apply.// the extra coercion does somethingreturn@as(u16, @truncate(n));
}
The text was updated successfully, but these errors were encountered:
Description
When a value is assigned, returned, or otherwise has a RLS with a static type, disallow re-specifying that type. This mostly means changing struct literals to anonymous struct literals, removing redundant
@as
, or using a decl literal over a namespace.Motivating example:
Examples
Examples of incorrect code for this rule
Examples that would not be flagged.
The text was updated successfully, but these errors were encountered: