cat > main.d << EOF void main() @safe { struct ThrowingElement { int i; ~this() { assert(1); } } ThrowingElement[int] aa; aa[0] = ThrowingElement(0); } EOF The problem is that the generated opAssign is @system: ref return @system ThrowingElement opAssign(ThrowingElement p) { (ThrowingElement __swap2 = void;) , __swap2 = this , this = p , __swap2.~this(); return this; }
The solution is likely the same as for https://github.com/dlang/dmd/pull/8011
The example compiles successfully if ~this() is given the @safe attribute. @safe for the outer function is not transitively applied - perhaps it should be, but that isn't the way it works at the moment.