Something equivalent to Ada's pragma Restrictions?

Related to this: Zig has @setRuntimeSafety(bool), which turns safety checks for undefined behavior on and off on a per-scope basis. I hope that, eventually, a built-in is added to make this more fine-grained, so that each case of undefined behavior which is detectable can be turned on and off.

Ideally, this would come in a dynamic-bind form as well, so that if I enable, say, bounds-checking, that anything in the entire call stack of the function will also use bounds checking. The current behavior is lexical, which is the correct default: if you turn on runtime safety, that applies to any scope which inherits from the scope with the declaration, unless one of those scopes explicitly turns it off. But this means that if I enable bounds checking and make a slice, and hand it off to a function, the function is going to do what its scope dictates. A dynamic bind would mean that the function call inherits safety checks from its call scope, not its definition/lexical scope. There are times when that would be pretty useful.

This is easier said than done, there’s a fair amount of complexity in how runtime safety is actually handled, see this thread about what happens when safety-checks are disabled at the definition site of a bare union.

But it would come with some considerable advantages. It would be great to be in a position to define a buffer array on the stack, and then turn on bounds checks in a way which applies to every down-stack function call. That would prevent stack-smashing attacks, which are one of the most common security vulnerabilities.