Currently, @trusted applies only to functions. This is most of the times a pain when you want trusted code blocks inside functions. Why not simplify it a bit by using trusted scope blocks? E.g. this:
void foo() @safe
{
() @trusted { ... }();
}
becomes this:
void foo() @safe
{
@trusted
{
....
}
}
To make things easier, @trusted does not insert a scope (similar to static if
).
Of course, the feature would be additive (you can have both trusted functions and code blocks).
That would also provide an elegant workaround if void initialization is rejected in @safe code [1][2]. For example:
void foo() @safe
{
@trusted
{
int[100] a = void;
}
...
}
What do you think?
Cheers,
RazvanN
[1] https://issues.dlang.org/show_bug.cgi?id=17566
[2] https://github.com/dlang/dlang.org/pull/2260