[Issue 14125] @trusted nested helper functions in std.file

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Feb 4 18:49:26 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14125

--- Comment #44 from Walter Bright <bugzilla at digitalmars.com> ---
(In reply to David Nadlinger from comment #40)
> grep for "trusted[A-Z]". For example, trustedCast() in join().

For reference:

  static U trustedCast(U, V)(V v) @trusted { return cast(U) v; }

That's a fine example of what I'm talking about as a complete misunderstanding
of what trust is supposed to be doing. It's putting the entire onus of using
the cast correctly on the CALLER. It is not checkable without checking the
supposedly @safe code that uses it, which has defeated the purpose of @safe.

The use in join() looks like this (paraphrasing):

    @safe join() {
       ... safe code ...
       return trustedCast();
    }

I understand you want the ...safe code... to be checked for safety. Here's how
to do it:

    @trusted join() {
        @safe {
            ... safe code ...
        }
        return cast(U) v;
    }

--


More information about the Digitalmars-d-bugs mailing list