@trust is an encapsulation method, not an escape

Tobias Pankrath via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 6 08:32:19 PST 2015


On Friday, 6 February 2015 at 16:19:26 UTC, John Colvin wrote:
> It feels inelegant, but it might be the best way out of a bad 
> situation.
>
> I can instantly see this happening:
>
> void foo() @trusted
> {
>     @safe
>     {
>         //loads of code
>     }
>
>     //a few lines of system code, only safe due to context in 
> the @safe blocks
>
>     @safe
>     {
>         \\loads of code
>     }
> }
>
> Is that what we want? I can't see why not, but it feels off 
> somehow... Effectively you've got @trusted blocks in an 
> @trusted function, just inverted.

Some observations.

1. You cannot corrupt memory in the first @safe block. That's a 
plus.
2. It solves the 
"my- at safe-function-turned-@system-behind-my-back"-problem
3. It solves the problems the current @trusted-abuse in std.file 
tried to solve

And most importantly:
If that function can be made @trusted, there probably is a 
function bar, so that

void bar() { .. } @trusted

void foo() @safe
{

    @safe {}
    bar();
    @safe {}
}




More information about the Digitalmars-d mailing list