Is @trusted the wrong direction?

Steven Schveighoffer schveiguy at gmail.com
Sat Nov 9 14:29:09 UTC 2019


On 11/9/19 1:55 AM, Jesse Phillips wrote:
> Trusted code is the gateway for safe code to call into system code. The 
> code is suppose to indicate the layer for verify safe use of system code.
> 
> @safe
> void main()
> {
>      foo();
> }
> 
> @trusted
> void foo () {
>      auto fish = 5;
>      auto m = &fish;
> }
> 
> However the code itself is system code and the language does not 
> restrict operations like in safe.
> 
> I'm wondering if trusted should operate in the same world as safe, with 
> the benefit of calling @system code.
> 
> Now the concern would be that there would just be an additional system 
> function between safe and the desired system code.
> 
> Would it make sense to analyze some existing trusted methods and suggest 
> a change?

I wrote an article about @trusted. It's definitely overused in a lot of 
places. I won't rehash what I said in the article, so please have a 
read. When to use @trusted is not always a straightforward and easy set 
of rules.

https://dlang.org/blog/2016/09/28/how-to-write-trusted-code-in-d/

-Steve


More information about the Digitalmars-d mailing list