-
-
Notifications
You must be signed in to change notification settings - Fork 746
[Trivial] std.path: fix a -dip1000 compilable issue #6203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for your pull request and interest in making D better, @carblue! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
wilzbach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(FWIW this piece looks like it could use an appender)
std/path.d
Outdated
| result = chainPath(result, path).array; | ||
| else | ||
| result = path; | ||
| result = path.idup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it: wouldn't assumeUnique be better here to avoid an unnecessary allocation?
I know the loop is already horrible with .array on every iteration, but that's not an argument to make it even worse?
To ensure that the new content is freshly allocated, we could check this after the loop is then and only idup then...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need return scope or abbreviated (w/o ref) you can just use return on the paths parameter, as you're returning/escaping a parameter. Please file a bug report with the [scope] tag if something is fishy about variadic arguments. Just repainting the returned array can leak the passed in parameter without letting the compiler know.
|
I won't pursue this PR any more, just closing it |
|
I redid this as #6357 but I don't see how this PR makes it any more DIP1000 compatible. The return value of the function is always copied into fresh memory. |
Without this fix and
string relativePath(CaseSensitive cs = CaseSensitive.osDefault)
(string path, lazy string base = getcwd()) temporarily attributed @safe
the reported errors are:
std/path.d(1742): Error: scope variable result may not be returned
std/path.d(1748): Error: template instance
std.path.buildNormalizedPath!charerror instantiatingstd/path.d(1800): while evaluating: static assert(buildNormalizedPath(["/foo/..", "/bar/./baz"][]) == "/bar/baz")
std/path.d(2873): Error: @safe function std.path.relativePath!cast(CaseSensitive)true.relativePath cannot call @System function std.conv.to!string.to!(ChooseResult!(ByCodeUnitImpl, Result)).to
Thus the remainder will be an error from std.conv.to!string.to only.