@@ -2169,13 +2169,13 @@ Allows to directly use range operations on lines of a file.
2169
2169
private struct ByLineImpl (Char, Terminator)
2170
2170
{
2171
2171
private :
2172
- import std.typecons : RefCounted , RefCountedAutoInitialize;
2172
+ import std.typecons : borrow , RefCountedAutoInitialize, SafeRefCounted ;
2173
2173
2174
2174
/* Ref-counting stops the source range's Impl
2175
2175
* from getting out of sync after the range is copied, e.g.
2176
2176
* when accessing range.front, then using std.range.take,
2177
2177
* then accessing range.front again. */
2178
- alias PImpl = RefCounted ! (Impl, RefCountedAutoInitialize.no);
2178
+ alias PImpl = SafeRefCounted ! (Impl, RefCountedAutoInitialize.no);
2179
2179
PImpl impl;
2180
2180
2181
2181
static if (isScalarType! Terminator)
@@ -2190,19 +2190,24 @@ Allows to directly use range operations on lines of a file.
2190
2190
impl = PImpl(f, kt, terminator);
2191
2191
}
2192
2192
2193
- @property bool empty()
2193
+ /* Verifiably `@safe` when built with -preview=DIP1000. */
2194
+ @property bool empty() @trusted
2194
2195
{
2195
- return impl.refCountedPayload.empty;
2196
+ // Using `ref` is actually necessary here.
2197
+ return impl.borrow! ((ref i) => i.empty);
2196
2198
}
2197
2199
2198
- @property Char[] front()
2200
+ /* Verifiably `@safe` when built with -preview=DIP1000. */
2201
+ @property Char[] front() @trusted
2199
2202
{
2200
- return impl.refCountedPayload.front;
2203
+ // Using `ref` is likely optional here.
2204
+ return impl.borrow! ((ref i) => i.front);
2201
2205
}
2202
2206
2203
- void popFront ()
2207
+ /* Verifiably `@safe` when built with -preview=DIP1000. */
2208
+ void popFront () @trusted
2204
2209
{
2205
- impl.refCountedPayload .popFront();
2210
+ return impl.borrow ! (( ref i) => i .popFront() );
2206
2211
}
2207
2212
2208
2213
private :
@@ -2216,6 +2221,7 @@ Allows to directly use range operations on lines of a file.
2216
2221
KeepTerminator keepTerminator;
2217
2222
bool haveLine;
2218
2223
2224
+ @safe :
2219
2225
public :
2220
2226
this (File f, KeepTerminator kt, Terminator terminator)
2221
2227
{
@@ -2375,7 +2381,7 @@ void main()
2375
2381
return ByLineImpl! (Char, Terminator)(this , keepTerminator, terminator);
2376
2382
}
2377
2383
2378
- @system unittest
2384
+ @safe unittest
2379
2385
{
2380
2386
static import std.file ;
2381
2387
auto deleteme = testFilename();
@@ -2393,7 +2399,7 @@ void main()
2393
2399
}
2394
2400
2395
2401
// https://issues.dlang.org/show_bug.cgi?id=19980
2396
- @system unittest
2402
+ @safe unittest
2397
2403
{
2398
2404
static import std.file ;
2399
2405
auto deleteme = testFilename();
@@ -2541,12 +2547,11 @@ $(REF readText, std,file)
2541
2547
is (typeof (File (" " ).byLineCopy! (char , char ).front) == char []));
2542
2548
}
2543
2549
2544
- @system unittest
2550
+ @safe unittest
2545
2551
{
2546
2552
import std.algorithm.comparison : equal;
2547
2553
static import std.file ;
2548
2554
2549
- scope (failure) printf (" Failed test at line %d\n " , __LINE__ );
2550
2555
auto deleteme = testFilename();
2551
2556
std.file.write (deleteme, " " );
2552
2557
scope (success) std.file.remove (deleteme);
@@ -2620,7 +2625,7 @@ $(REF readText, std,file)
2620
2625
test(" sue\r " , [" sue\r " ], kt, ' \r ' );
2621
2626
}
2622
2627
2623
- @system unittest
2628
+ @safe unittest
2624
2629
{
2625
2630
import std.algorithm.comparison : equal;
2626
2631
import std.range : drop, take;
@@ -4765,6 +4770,15 @@ struct lines
4765
4770
foreach (line; myByLineCopy)
4766
4771
continue ;
4767
4772
}
4773
+
4774
+ {
4775
+ auto f = File (deleteMe, " r" );
4776
+ scope (exit) { f.close(); }
4777
+
4778
+ auto myByLine = f.byLine;
4779
+ foreach (line; myByLine)
4780
+ continue ;
4781
+ }
4768
4782
}
4769
4783
4770
4784
@system unittest
0 commit comments