Skip to content

Commit 1bee1db

Browse files
committed
annotate more of phobos with return and scope
1 parent 048df4a commit 1bee1db

12 files changed

Lines changed: 42 additions & 40 deletions

File tree

std/algorithm/mutation.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ Params:
10741074
*/
10751075
void move(T)(ref T source, ref T target)
10761076
{
1077-
moveImpl(source, target);
1077+
moveImpl(target, source);
10781078
}
10791079

10801080
/// For non-struct types, `move` just performs `target = source`:
@@ -1244,7 +1244,7 @@ pure nothrow @safe @nogc unittest
12441244
static assert(is(typeof({ S s; move(s, s); }) == T));
12451245
}
12461246

1247-
private void moveImpl(T)(ref T source, ref T target)
1247+
private void moveImpl(T)(ref return scope T target, ref scope T source)
12481248
{
12491249
import std.traits : hasElaborateDestructor;
12501250

@@ -1257,10 +1257,10 @@ private void moveImpl(T)(ref T source, ref T target)
12571257
static if (hasElaborateDestructor!T) target.__xdtor();
12581258
}
12591259
// move and emplace source into target
1260-
moveEmplaceImpl(source, target);
1260+
moveEmplaceImpl(target, source);
12611261
}
12621262

1263-
private T moveImpl(T)(ref T source)
1263+
private T moveImpl(T)(ref return scope T source)
12641264
{
12651265
// Properly infer safety from moveEmplaceImpl as the implementation below
12661266
// might void-initialize pointers in result and hence needs to be @trusted
@@ -1269,10 +1269,10 @@ private T moveImpl(T)(ref T source)
12691269
return trustedMoveImpl(source);
12701270
}
12711271

1272-
private T trustedMoveImpl(T)(ref T source) @trusted
1272+
private T trustedMoveImpl(T)(ref return scope T source) @trusted
12731273
{
12741274
T result = void;
1275-
moveEmplaceImpl(source, result);
1275+
moveEmplaceImpl(result, source);
12761276
return result;
12771277
}
12781278

@@ -1415,7 +1415,7 @@ private T trustedMoveImpl(T)(ref T source) @trusted
14151415
move(x, x);
14161416
}
14171417

1418-
private void moveEmplaceImpl(T)(ref T source, ref T target)
1418+
private void moveEmplaceImpl(T)(ref return scope T target, ref scope T source)
14191419
{
14201420
import core.stdc.string : memcpy, memset;
14211421
import std.traits : hasAliasing, hasElaborateAssign,
@@ -1486,7 +1486,7 @@ private void moveEmplaceImpl(T)(ref T source, ref T target)
14861486
*/
14871487
void moveEmplace(T)(ref T source, ref T target) pure @system
14881488
{
1489-
moveEmplaceImpl(source, target);
1489+
moveEmplaceImpl(target, source);
14901490
}
14911491

14921492
///

std/bigint.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public:
246246
* Implements assignment operators from built-in integers of the form
247247
* `BigInt op= integer`.
248248
*/
249-
BigInt opOpAssign(string op, T)(T y) pure nothrow @safe return
249+
BigInt opOpAssign(string op, T)(T y) pure nothrow @safe return scope
250250
if ((op=="+" || op=="-" || op=="*" || op=="/" || op=="%"
251251
|| op==">>" || op=="<<" || op=="^^" || op=="|" || op=="&" || op=="^") && isIntegral!T)
252252
{
@@ -1351,16 +1351,16 @@ public:
13511351

13521352
// for backwards compatibility, see unittest below
13531353
/// ditto
1354-
void toString(scope void delegate(const(char)[]) sink, string formatString) const
1354+
void toString(scope void delegate(scope const(char)[]) sink, string formatString) const
13551355
{
1356-
toString!(void delegate(const(char)[]))(sink, formatString);
1356+
toString!(void delegate(scope const(char)[]))(sink, formatString);
13571357
}
13581358

13591359
// for backwards compatibility, see unittest below
13601360
/// ditto
1361-
void toString(scope void delegate(const(char)[]) sink, scope const ref FormatSpec!char f) const
1361+
void toString(scope void delegate(scope const(char)[]) sink, scope const ref FormatSpec!char f) const
13621362
{
1363-
toString!(void delegate(const(char)[]))(sink, f);
1363+
toString!(void delegate(scope const(char)[]))(sink, f);
13641364
}
13651365

13661366
// Backwards compatibility test

std/conv.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4758,7 +4758,7 @@ if (T.length > 0) { return textImpl!dstring(args); }
47584758
assert(dtext(cs, ' ', ws, " ", ds) == "今日は 여보세요 Здравствуйте"d);
47594759
}
47604760

4761-
private S textImpl(S, U...)(U args)
4761+
private S textImpl(S, U...)(scope U args)
47624762
{
47634763
static if (U.length == 0)
47644764
{

std/getopt.d

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ private struct configuration
11061106
private bool optMatch(string arg, scope string optPattern, ref string value,
11071107
configuration cfg) @safe
11081108
{
1109-
import std.array : split;
1109+
import std.algorithm : splitter;
11101110
import std.string : indexOf;
11111111
import std.uni : toUpper;
11121112
//writeln("optMatch:\n ", arg, "\n ", optPattern, "\n ", value);
@@ -1148,8 +1148,7 @@ private bool optMatch(string arg, scope string optPattern, ref string value,
11481148
}
11491149
//writeln("Arg: ", arg, " pattern: ", optPattern, " value: ", value);
11501150
// Split the option
1151-
const variants = split(optPattern, "|");
1152-
foreach (v ; variants)
1151+
foreach (v ; splitter(optPattern, "|"))
11531152
{
11541153
//writeln("Trying variant: ", v, " against ", arg);
11551154
if (arg == v || !cfg.caseSensitive && toUpper(arg) == toUpper(v))

std/internal/cstring.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private:
269269
static TempCStringBuffer trustedVoidInit() { TempCStringBuffer res = void; return res; }
270270
}
271271

272-
private To[] trustedRealloc(To)(scope To[] buf, size_t strLength, bool bufIsOnStack)
272+
private To[] trustedRealloc(To)(return scope To[] buf, size_t strLength, bool bufIsOnStack)
273273
@trusted @nogc pure nothrow
274274
{
275275
pragma(inline, false); // because it's rarely called

std/internal/math/biguintcore.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private:
245245

246246
immutable(BigDigit) [] data = ZERO;
247247

248-
this(immutable(BigDigit) [] x) pure nothrow @nogc @safe scope
248+
this(return scope immutable(BigDigit) [] x) pure nothrow @nogc @safe
249249
{
250250
data = x;
251251
}
@@ -710,7 +710,7 @@ public:
710710
// All of these member functions create a new BigUint.
711711

712712
// return x >> y
713-
BigUint opBinary(string op, Tulong)(Tulong y) pure nothrow @safe const
713+
BigUint opBinary(string op, Tulong)(Tulong y) pure nothrow @safe const return scope
714714
if (op == ">>" && is (Tulong == ulong))
715715
{
716716
assert(y > 0, "Can not right shift BigUint by 0");
@@ -1498,7 +1498,7 @@ private int slowHighestPowerBelowUintMax(uint x) pure nothrow @safe
14981498
* Returns:
14991499
* unique memory
15001500
*/
1501-
BigDigit [] sub(const BigDigit [] x, const BigDigit [] y, bool *negative)
1501+
BigDigit [] sub(const scope BigDigit [] x, const scope BigDigit [] y, bool *negative)
15021502
pure nothrow @safe
15031503
{
15041504
if (x.length == y.length)
@@ -1558,7 +1558,7 @@ pure nothrow @safe
15581558
* Returns:
15591559
* unique memory
15601560
*/
1561-
BigDigit [] add(const BigDigit [] a, const BigDigit [] b) pure nothrow @safe
1561+
BigDigit [] add(const scope BigDigit [] a, const scope BigDigit [] b) pure nothrow @safe
15621562
{
15631563
const(BigDigit) [] x, y;
15641564
if (a.length < b.length)

std/internal/memory.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void* enforceCalloc()(size_t nmemb, size_t size) @nogc nothrow pure @safe
4242
}
4343

4444
// ditto
45-
void* enforceRealloc()(void* ptr, size_t size) @nogc nothrow pure @system
45+
void* enforceRealloc()(return scope void* ptr, size_t size) @nogc nothrow pure @system
4646
{
4747
auto result = fakePureRealloc(ptr, size);
4848
if (!result) mixin(allocationFailed);
@@ -54,5 +54,5 @@ extern (C) @nogc nothrow pure private
5454
{
5555
pragma(mangle, "malloc") void* fakePureMalloc(size_t) @safe;
5656
pragma(mangle, "calloc") void* fakePureCalloc(size_t nmemb, size_t size) @safe;
57-
pragma(mangle, "realloc") void* fakePureRealloc(void* ptr, size_t size) @system;
57+
pragma(mangle, "realloc") void* fakePureRealloc(return scope void* ptr, size_t size) @system;
5858
}

std/path.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementT
565565
}
566566

567567
/// ditto
568-
auto dirName(C)(C[] path)
568+
auto dirName(C)(return scope C[] path)
569569
if (isSomeChar!C)
570570
{
571571
return _dirName(path);
@@ -662,7 +662,7 @@ if (isSomeChar!C)
662662
//static assert(dirName("dir/file".byChar).array == "dir");
663663
}
664664

665-
private auto _dirName(R)(R path)
665+
private auto _dirName(R)(return scope R path)
666666
{
667667
static auto result(bool dot, typeof(path[0 .. 1]) p)
668668
{
@@ -1448,7 +1448,7 @@ private auto _withDefaultExtension(R, C)(R path, C[] ext)
14481448
Returns: The assembled path.
14491449
*/
14501450
immutable(ElementEncodingType!(ElementType!Range))[]
1451-
buildPath(Range)(Range segments)
1451+
buildPath(Range)(scope Range segments)
14521452
if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range))
14531453
{
14541454
if (segments.empty) return null;
@@ -1622,7 +1622,7 @@ if (isSomeChar!C)
16221622
* See_Also:
16231623
* $(LREF buildPath)
16241624
*/
1625-
auto chainPath(R1, R2, Ranges...)(R1 r1, R2 r2, Ranges ranges)
1625+
auto chainPath(R1, R2, Ranges...)(return scope R1 r1, return scope R2 r2, Ranges ranges) @safe
16261626
if ((isRandomAccessRange!R1 && hasSlicing!R1 && hasLength!R1 && isSomeChar!(ElementType!R1) ||
16271627
isNarrowString!R1 &&
16281628
!isConvertibleToString!R1) &&

std/range/package.d

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ Returns:
886886
887887
See_Also: $(LREF only) to chain values to a range
888888
*/
889-
auto chain(Ranges...)(Ranges rs)
889+
auto chain(Ranges...)(return scope Ranges rs)
890890
if (Ranges.length > 0 &&
891891
allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) &&
892892
!is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void))
@@ -930,9 +930,11 @@ if (Ranges.length > 0 &&
930930
// TODO: use a vtable (or more) instead of linear iteration
931931

932932
public:
933-
this(R input)
933+
this(return scope R input)
934934
{
935-
foreach (i, v; input)
935+
// this has to be static foreach instead of just foreach, otherwise
936+
// "scope variable `v` assigned to `this` with longer lifetime"
937+
static foreach (i, v; input)
936938
{
937939
source[i] = v;
938940
}

std/typecons.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ struct Nullable(T)
30103010
* Params:
30113011
* value = A value of type `T` to assign to this `Nullable`.
30123012
*/
3013-
void opAssign()(T value)
3013+
void opAssign()(return scope T value)
30143014
{
30153015
import std.algorithm.mutation : moveEmplace, move;
30163016

@@ -3025,7 +3025,7 @@ struct Nullable(T)
30253025
}
30263026
else
30273027
{
3028-
move(copy.payload, _value.payload);
3028+
() @trusted { move(copy.payload, _value.payload); }();
30293029
}
30303030
_isNull = false;
30313031
}

0 commit comments

Comments
 (0)