Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ enforce(chomp(readText("deleteme")) == "abc");
----
*/

S readText(S = string)(in char[] name)
S readText(S = string)(in char[] name) @safe if (isSomeString!S)
{
auto result = cast(S) read(name);
static auto trustedCast(void[] buf) @trusted { return cast(S)buf; }
auto result = trustedCast(read(name));
std.utf.validate(result);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please instead of marking whole function as @trusted do so in minimal possible "grains":

auto result_raw = read(name);
auto result = () @trusted { return cast(S) result_raw; } (); // define lambda and immediately call it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used a nested trusted function instead of a direct lambda call because Issue 10848 for dmd is still open.

return result;
}
Expand Down