https://issues.dlang.org/show_bug.cgi?id=23998
Paul Backus <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #5 from Paul Backus <[email protected]> --- Dennis is correct. This is completely outside the purview of @mustuse. What you are asking for is a guarantee not just that the object has been used, but that it has been used *correctly* (according to some programmer-defined criteria). For this specific example, I think the best solution is to redesign your Result type so that it is impossible to access the wrapped value without performing a null check. Here's one possible way to do so: --- import core.attribute, std.stdio; @mustuse struct Result { private int* value; bool isNull() => value is null; int opApply(scope int delegate(int) dg) { if (value is null) return 0; return dg(*value); } } Result getResult() => Result(new int(42)); void main() { auto r = getResult(); foreach (int n; r) writeln("got ", n); } --- --
