Z016: Split compound assert
Detects std.debug.assert(a and b) which should be split into separate assertions for better error diagnostics. Project-defined functions and methods named assert are not rewritten because calling them twice could change behavior.
Examples
Bad
const std = @import("std");
// expect: Z016
fn check() void {
std.debug.assert(a and b);
}Good
Split into separate assertions:
const std = @import("std");
fn check() void {
std.debug.assert(a);
std.debug.assert(b);
}
Note: assert(a or b) is not flagged because it has different semantics—it passes if either condition is true.
Rationale
When assert(a and b) fails, you don't know which condition failed. Splitting into separate assertions gives you precise failure information:
// With assert(a and b):
// "assertion failed" - which one?
// With separate asserts:
// "assertion failed: x > 0" - clear!
This is especially valuable in tests and invariant checks where quick diagnosis matters.