DIP 1028---Make @safe the Default---Community Review Round 1

ag0aep6g anonymous at example.com
Thu Jan 9 20:08:06 UTC 2020


On Thursday, 9 January 2020 at 19:35:36 UTC, Steven Schveighoffer 
wrote:
> If I could mark the whole thing trusted, and turn on the 
> mechanical checking for everything except line X, then I'd do 
> that instead.

Well, you can do that:

     void foo() @trusted
     {
         () @safe { /* ... stuff ... */ } ();
         bar(1, 2, 3); /* line X */
         () @safe { /* ... stuff ... */ } ();
     }

The problem is, of course, that you can't have `foo`'s safety 
inferred based on "stuff". Which is what we usually want.

I have actually used that pattern once in Phobos:

https://github.com/dlang/phobos/blob/master/std/range/package.d#L1550-L1581

I had to duplicate the code and use `__traits(compiles, ...)` to 
get inference. So the result isn't exactly pretty. But the use of 
@trusted is watertight, as far as I can tell.


More information about the Digitalmars-d mailing list