[scope] add @trusted and 'scope' annotations to std.array#5082
[scope] add @trusted and 'scope' annotations to std.array#5082andralex merged 1 commit intodlang:masterfrom
Conversation
9805637 to
872317d
Compare
|
With this change, and the other pending scope PRs, std.array will now compile its unit tests with -dip1000. |
| the input. | ||
| */ | ||
| ElementType!String[] array(String)(String str) if (isNarrowString!String) | ||
| @trusted ElementType!String[] array(String)(scope String str) if (isNarrowString!String) |
There was a problem hiding this comment.
Applying @trusted to a template is really dangerous. What if toUTF32 becomes unsafe in the future? What if the template constraints are relaxed?
| * is unsafe - converting a dstring[] to a dchar[], for example. | ||
| * Our special knowledge of toUTF32 is needed to know the cast is safe. | ||
| */ | ||
| return cast(typeof(return)) str.toUTF32; |
There was a problem hiding this comment.
The whole trusted thing can be avoided by
- Changing this line to
return toUTFImpl!(dchar[])(str); - Changing
std.utf.toUTFImplto bepackagerather thanprivate
There was a problem hiding this comment.
There's no need for the cast using my solution.
There was a problem hiding this comment.
Yeah, you're right. Just thought I'd mention it.
There was a problem hiding this comment.
toUTF32
Throws an Exception on invalid UTF. toUTFIml does not. I.e. the behavior is different.
trusted lambda
While that will work, it kinda is superfluous. The reason the cast is safe is because of special knowledge of how toUTF32 is implemented. Any changes should reflect knowledge of the whole, it isn't just about an unsafe cast.
There was a problem hiding this comment.
This is indeed fragile but I'll allow it in the interest of moving forward.
|
Auto-merge toggled on |
With apologies. @JackStouffer would you mind following up with a PR? Walter has a long backlog. Thanks!
|
@WalterBright @CyberShadow what is the problem with the doc builder here? Thx. |
Same problem as dlang/dmd#4745 (comment) (and everywhere else)... |
The
@trustedis documented in the comments. The need forscopeis there forjoinbecause the use ofsepis convoluted enough the relatively simple inference engine in the compiler cannot infer it, so a little help is needed.