I think neither comptime nor codegen are great approaches to implement this kind of check, because implementations seem to require too much awkward complexity.
I am not sure if it would work, but if it did, it may make sense to implement using techniques like clr:
I think ideally Zig would gain something like Lint/Validation-time, which can be configured via the build system and sort of runs like a compiler plugin. I think it would already be possible to do as a run step that re-does some of the things the compiler has already done, or looks at some of the intermediary outputs of the compiler, but having this as a validation-time feature, might make these sorts of checks easier to write.
Another possibility might be that something like this could be implemented via the compiler-protocol, once it is implemented.
related: