How to conditionally include/exclude functions from a namespace without usingnamespace?

void is not a suitable replacement for @compileError() for the purposes of indicating to the user that a decl (not the result of calling a function) is not/no longer usable. It results in nondescriptive compile errors like expected type 'usize', found 'void', without any compile error trace that can help the user find the file and line where the decl was declared.

Unusable("some error"[0..10]) is cute and an improvement over void but it still has the same problem in that it doesn’t show you the file and line it came from. I also think it would be awkward and highly unintuitive if users were expected to use some obscure type from std just so that they can emit compile error messages that don’t suck complete ass, when @compileError() sits right there.

I understand why @TypeOf(@compileError("")) can’t just yield noreturn, because handling compile-time errors differently in this context would complicate the language and there are also situations where you wouldn’t want the error to get swallowed. But maybe std.builtin.Type.Declaration could get extended with an is_noreturn: bool field? That way you would still be able to iterate over decls without risking compile errors:

inline for (@typeInfo(T).@"struct".decls) |decl| {
    if (!decl.is_noreturn) {
        const value = @field(T, decl.name);
    }
}
1 Like