When a builtin-in method like opAssign is disabled, the error messages are quite noisy:
struct A
{
@disable void opAssign(Other)(Other other);
}
pure nothrow @safe @nogc unittest
{
A a;
a = A();
}
foo.d(16): Error: function foo.A.opAssign!(A).opAssign is not callable because it is annotated with @disable
foo.d(16): Error: pure function 'foo.__unittestL13_1' cannot call impure function 'foo.A.opAssign!(A).opAssign'
foo.d(16): Error: safe function 'foo.__unittestL13_1' cannot call system function 'foo.A.opAssign!(A).opAssign'
foo.d(16): Error: @nogc function 'foo.__unittestL13_1' cannot call non-@nogc function 'foo.A.opAssign!(A).opAssign'
foo.d(16): Error: function 'foo.A.opAssign!(A).opAssign' is not nothrow
foo.d(13): Error: function 'foo.__unittestL13_1' is nothrow yet may throw
There is a trick that is used in https://github.com/dlang/phobos/pull/4755, one can simply annotate the disabled function with all attributes:
struct B
{
pure nothrow @safe @nogc @disable void opAssign(Other)(Other other);
}
pure nothrow @safe @nogc unittest
{
B b;
b = B();
}
foo.d(16): Error: function foo.B.opAssign!(B).opAssign is not callable because it is annotated with @disable
Comment #1 by robert.schadek — 2024-12-13T18:49:52Z