Skip to content

Commit a023284

Browse files
committed
add explicit scope/return for pure functions
1 parent 73e51d3 commit a023284

9 files changed

Lines changed: 30 additions & 26 deletions

File tree

std/algorithm/mutation.d

Lines changed: 9 additions & 9 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 scope T target, ref return 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 scope T target, ref return 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
///
@@ -2388,7 +2388,7 @@ Range remove(alias pred, SwapStrategy s = SwapStrategy.stable, Range)(Range rang
23882388
@nogc @safe unittest
23892389
{
23902390
// @nogc test
2391-
int[10] arr = [0,1,2,3,4,5,6,7,8,9];
2391+
static int[] arr = [0,1,2,3,4,5,6,7,8,9];
23922392
alias pred = e => e < 5;
23932393

23942394
auto r = arr[].remove!(SwapStrategy.unstable)(0);

std/array.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ private enum bool hasCheapIteration(R) = isArray!R;
19531953
See_Also:
19541954
For a lazy version, see $(REF joiner, std,algorithm,iteration)
19551955
+/
1956-
ElementEncodingType!(ElementType!RoR)[] join(RoR, R)(RoR ror, scope R sep)
1956+
ElementEncodingType!(ElementType!RoR)[] join(RoR, R)(RoR ror, R sep)
19571957
if (isInputRange!RoR &&
19581958
isInputRange!(Unqual!(ElementType!RoR)) &&
19591959
isInputRange!R &&

std/datetime/timezone.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ package:
17021702
Params:
17031703
isoExtString = A string which represents a time zone in the ISO format.
17041704
+/
1705-
static immutable(SimpleTimeZone) fromISOExtString(S)(S isoExtString) @safe pure
1705+
static immutable(SimpleTimeZone) fromISOExtString(S)(scope S isoExtString) @safe pure
17061706
if (isSomeString!S)
17071707
{
17081708
import std.algorithm.searching : startsWith;

std/internal/math/biguintcore.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ public:
761761

762762
// If wantSub is false, return x + y, leaving sign unchanged
763763
// If wantSub is true, return abs(x - y), negating sign if x < y
764-
static BigUint addOrSubInt(Tulong)(const BigUint x, Tulong y,
764+
static BigUint addOrSubInt(Tulong)(const scope BigUint x, Tulong y,
765765
bool wantSub, ref bool sign) pure nothrow @safe if (is(Tulong == ulong))
766766
{
767767
BigUint r;
@@ -1380,7 +1380,7 @@ pure nothrow @safe
13801380
}
13811381

13821382
// Encode BigInt as BigDigit array (sign and 2's complement)
1383-
BigDigit[] includeSign(const(BigDigit) [] x, size_t minSize, bool sign)
1383+
BigDigit[] includeSign(scope const(BigDigit) [] x, size_t minSize, bool sign)
13841384
pure nothrow @safe
13851385
{
13861386
size_t length = (x.length > minSize) ? x.length : minSize;

std/path.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,14 @@ if (isRandomAccessRange!R && hasSlicing!R && isSomeChar!(ElementType!R) || isNar
558558
the POSIX requirements for the 'dirname' shell utility)
559559
(with suitable adaptations for Windows paths).
560560
*/
561-
auto dirName(R)(R path)
561+
auto dirName(R)(return scope R path)
562562
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementType!R) && !isSomeString!R)
563563
{
564564
return _dirName(path);
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;
@@ -2747,7 +2747,7 @@ else version (Posix)
27472747
See_Also:
27482748
$(LREF asAbsolutePath) which does not allocate
27492749
*/
2750-
string absolutePath(return scope string path, lazy string base = getcwd())
2750+
string absolutePath(string path, lazy string base = getcwd())
27512751
@safe pure
27522752
{
27532753
import std.array : array;
@@ -2893,7 +2893,7 @@ if (isConvertibleToString!R)
28932893
`Exception` if the specified _base directory is not absolute.
28942894
*/
28952895
string relativePath(CaseSensitive cs = CaseSensitive.osDefault)
2896-
(scope return string path, lazy string base = getcwd())
2896+
(string path, lazy string base = getcwd())
28972897
{
28982898
if (!isAbsolute(path))
28992899
return path;

std/process.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static:
276276
multi-threaded programs. See e.g.
277277
$(LINK2 https://www.gnu.org/software/libc/manual/html_node/Environment-Access.html#Environment-Access, glibc).
278278
*/
279-
inout(char)[] opIndexAssign(inout char[] value, scope const(char)[] name) @trusted
279+
inout(char)[] opIndexAssign(return inout char[] value, scope const(char)[] name) @trusted
280280
{
281281
version (Posix)
282282
{

std/random.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,8 +3362,8 @@ if (isRandomAccessRange!Range)
33623362
// Optionally @nogc std.random.randomCover
33633363
// https://issues.dlang.org/show_bug.cgi?id=14001
33643364
auto rng = Xorshift(123_456_789);
3365-
int[5] sa = [1, 2, 3, 4, 5];
3366-
auto r = randomCover(sa[], rng);
3365+
static immutable int[] sa = [1, 2, 3, 4, 5];
3366+
auto r = randomCover(sa, rng);
33673367
assert(!r.empty);
33683368
const x = r.front;
33693369
r.popFront();

std/range/package.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7708,7 +7708,7 @@ if (isForwardRange!RangeOfRanges &&
77087708
@safe unittest
77097709
{
77107710
import std.algorithm.comparison : equal;
7711-
ulong[1] t0 = [ 123 ];
7711+
ulong[] t0 = [ 123 ];
77127712

77137713
assert(!hasAssignableElements!(typeof(t0[].chunks(1))));
77147714
assert(!is(typeof(transposed(t0[].chunks(1)))));
@@ -10850,7 +10850,7 @@ if (isInputRange!Range && !isInstanceOf!(SortedRange, Range))
1085010850
into a `SortedRange`, it extracts the original range back out of the `SortedRange`
1085110851
using $(REF, move, std,algorithm,mutation).
1085210852
*/
10853-
auto release()
10853+
auto release() return scope
1085410854
{
1085510855
import std.algorithm.mutation : move;
1085610856
return move(_input);

std/string.d

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private:
154154
string _s;
155155
}
156156

157-
bool testAliasedString(alias func, Args...)(scope string s, scope Args args)
157+
bool testAliasedString(alias func, Args...)(string s, Args args)
158158
{
159159
import std.algorithm.comparison : equal;
160160
auto a = func(TestAliasedString(s), args);
@@ -2632,8 +2632,12 @@ if (isSomeChar!C)
26322632

26332633
enum S : string { a = "hello\nworld" }
26342634
assert(S.a.splitLines() == ["hello", "world"]);
2635+
}
26352636

2636-
char[S.a.length] sa = S.a[];
2637+
@system pure nothrow unittest
2638+
{
2639+
// dip1000 cannot express an array of scope arrays, so this is not @safe
2640+
char[11] sa = "hello\nworld";
26372641
assert(sa.splitLines() == ["hello", "world"]);
26382642
}
26392643

0 commit comments

Comments
 (0)