--- struct Oops { pure: bool empty() { *cast(int*)0xcafebabe = 0xdeadbeef; return true; } Oops save() @property { return this; } char front; void popFront() {} char back; void popBack() {} ref char opIndex(size_t idx) { return front; } enum size_t length = 0; alias opDollar = length; } void main() @safe { import std.uni; auto m = utfMatcher!char(unicode.Number); Oops o; m.match(o); } --- Again, the reason is a @trusted template function taking an arbitrary range. Source permalink (other match variants are affected too): https://github.com/D-Programming-Language/phobos/blob/041db2d8fac2b1cf5169be7188ea537a01f27586/std/uni.d#L4767-L4787 Introduced in https://github.com/D-Programming-Language/phobos/pull/2020.
https://github.com/dlang/phobos/pull/4416
I don't think match calls empty anywhere except inside an assert.
match() is just one of a number of @trusted range functions in that module (see e.g. the declarations immediately surrounding it). This example is just to illustrate that this indeed leads to a real problem with safety. Careful auditing of the use of @trusted in the module will be required to fully resolve this issue.
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/16099c6ec538b34cc5de97940f509fb0c15c0268 fix Issue 14136 - std.uni.utfMatcher breaks @safety https://github.com/dlang/phobos/commit/7792499d9ebfee7b808964b2e492270ead4111f2 Merge pull request #4416 from WalterBright/fix14136 fix Issue 14136 - std.uni.utfMatcher breaks @safety
As pointed out before, the patch actually only fixed a part of the problem, but the issue was still auto-closed.
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/16099c6ec538b34cc5de97940f509fb0c15c0268 fix https://github.com/dlang/phobos/commit/7792499d9ebfee7b808964b2e492270ead4111f2 Merge pull request #4416 from WalterBright/fix14136 fix Issue 14136 - std.uni.utfMatcher breaks @safety