Simplification of @trusted

RazvanN razvan.nitu1305 at gmail.com
Wed Jun 16 15:58:23 UTC 2021


On Wednesday, 16 June 2021 at 14:57:19 UTC, GrimMaple wrote:

> What I like more, is permitting to temporarily increase the 
> safety level by using eg @safe blocks inside a @trusted 
> function. For example
>
> ```d
> void foo() @trusted
> {
>     int[100] a = void;
>     @safe
>     {
>         // Code with safety checks
>     }
> }
> ```
>

I don't think that this is a good alternative. The normalcy we 
are striving for is to have as much code as possible @safe and as 
little as possible trusted. From that perspective it makes much 
more sense to annotate the entire function as @safe and have 
minor sections as being trusted.

> Overall, if something like this is implemented, it should 
> support all safety levels for blocks, including @safe and 
> @system, for consistency purposes

I don't really see the point in having @safe/trusted blocks 
inside of @system functions or @system/trusted blocks inside 
@safe functions. As for trusted functions, although I like the 
idea of deprecating them, there are cases of functions that are a 
few lines of code long (or even one liners) that do some unsafe 
operations that can be trusted; in this situation it's much 
easier to annotate the function as trusted. However, outside of 
such scenarios (for big functions), annotating functions as 
trusted is bad practice.


More information about the Digitalmars-d mailing list