This is taken from DIP 1035: struct S { private union { int x; int* y; } private int tag; // x if 0, y if 1 // public @trusted interface follows void set(int rhs) @trusted { if (tag == 0) x = rhs; else *y = rhs; } .... } Allowing safe code to modify tag from @safe code, followed by calling set(), results in unsafe code from safe functions. This could be relaxed to restrict access only for types that have @trusted functions.
For clarity, you mean modifying `tag` like so? void unsafe() @safe { S s; __traits(getMember, s, "tag") = 2; // should be error s.set(42); }