Skip to content

Conversation

@WalterBright
Copy link
Member

Shrink the @trusted to the smallest bit of the function that needs it. The rest is to follow the convention that result is for the return value.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#6357"

@WalterBright WalterBright added the Review:Vision Vision Plan https://wiki.dlang.org/Vision/2018H1 label Mar 28, 2018
std/path.d Outdated
result = asNormalizedPath(result).array;
return cast(typeof(return)) result;
auto result = asNormalizedPath(chained).array; // .array returns a copy, so we know it is unique
return () @trusted { return assumeUnique(result); } ();
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize that this has become an accepted way to do @trusted. But I think it actually goes against the idea behind it.

The @trusted snippet doesn't ensure safety by itself. It relies on the rest of the code not messing with result. That means, you can trigger undefined behavior by editing @safe code. Exactly what should not be possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.

return cast(typeof(return)) result;
auto result = asNormalizedPath(chained);
// .array returns a copy, so we know it is unique
return () @trusted { return assumeUnique(result.array); } ();
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. If .array returns a unique array, how come the compiler can't infer it? I would have thought that it should be inferred as pure, and the compiler would have been able to implicitly convert it to immutable without a @trusted escape.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pure isn't enough to infer the result is immutable.

@dlang-bot dlang-bot merged commit 012395e into dlang:master Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:auto-merge Review:Vision Vision Plan https://wiki.dlang.org/Vision/2018H1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants