Fix D-Scanner linting issues (#9070)

* Fix UndocumentedDeclarationCheck linting issue

* Fix IfConstraintsIndentCheck linting issue

* Address feedback

* Fix publictests CI

* Fix old (libdparse) D-Scanner linting warn
This commit is contained in:
Vladiwostok 2024-10-27 10:21:56 +02:00 committed by GitHub
parent fec5e7e4b9
commit 231ae8b68a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 498 additions and 414 deletions

View file

@ -443,7 +443,8 @@ if (fun.length >= 1)
A range with each fun applied to all the elements. If there is more than one A range with each fun applied to all the elements. If there is more than one
fun, the element type will be `Tuple` containing one element for each fun. fun, the element type will be `Tuple` containing one element for each fun.
*/ */
auto map(Range)(Range r) if (isInputRange!(Unqual!Range)) auto map(Range)(Range r)
if (isInputRange!(Unqual!Range))
{ {
import std.meta : AliasSeq, staticMap; import std.meta : AliasSeq, staticMap;
@ -1308,7 +1309,8 @@ if (is(typeof(unaryFun!predicate)))
A range containing only elements `x` in `range` for A range containing only elements `x` in `range` for
which `predicate(x)` returns `true`. which `predicate(x)` returns `true`.
*/ */
auto filter(Range)(Range range) if (isInputRange!(Unqual!Range)) auto filter(Range)(Range range)
if (isInputRange!(Unqual!Range))
{ {
return FilterResult!(unaryFun!predicate, Range)(range); return FilterResult!(unaryFun!predicate, Range)(range);
} }
@ -1545,7 +1547,8 @@ template filterBidirectional(alias pred)
Returns: Returns:
A range containing only the elements in `r` for which `pred` returns `true`. A range containing only the elements in `r` for which `pred` returns `true`.
*/ */
auto filterBidirectional(Range)(Range r) if (isBidirectionalRange!(Unqual!Range)) auto filterBidirectional(Range)(Range r)
if (isBidirectionalRange!(Unqual!Range))
{ {
return FilterBidiResult!(unaryFun!pred, Range)(r); return FilterBidiResult!(unaryFun!pred, Range)(r);
} }

View file

@ -3701,7 +3701,8 @@ if (isDynamicArray!A)
* Params: * Params:
* item = the single item to append * item = the single item to append
*/ */
void put(U)(U item) if (canPutItem!U) void put(U)(U item)
if (canPutItem!U)
{ {
static if (isSomeChar!T && isSomeChar!U && T.sizeof < U.sizeof) static if (isSomeChar!T && isSomeChar!U && T.sizeof < U.sizeof)
{ {
@ -3730,7 +3731,8 @@ if (isDynamicArray!A)
} }
// Const fixing hack. // Const fixing hack.
void put(Range)(Range items) if (canPutConstRange!Range) void put(Range)(Range items)
if (canPutConstRange!Range)
{ {
alias p = put!(Unqual!Range); alias p = put!(Unqual!Range);
p(items); p(items);
@ -3743,7 +3745,8 @@ if (isDynamicArray!A)
* Params: * Params:
* items = the range of items to append * items = the range of items to append
*/ */
void put(Range)(Range items) if (canPutRange!Range) void put(Range)(Range items)
if (canPutRange!Range)
{ {
// note, we disable this branch for appending one type of char to // note, we disable this branch for appending one type of char to
// another because we can't trust the length portion. // another because we can't trust the length portion.

View file

@ -299,7 +299,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
/** /**
* ditto * ditto
*/ */
char[] encode(R1, R2)(R1 source, R2 buffer) if (!isArray!R1 && isInputRange!R1 && char[] encode(R1, R2)(R1 source, R2 buffer)
if (!isArray!R1 && isInputRange!R1 &&
is(ElementType!R1 : ubyte) && hasLength!R1 && is(ElementType!R1 : ubyte) && hasLength!R1 &&
is(R2 == char[])) is(R2 == char[]))
in in
@ -559,7 +560,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* A newly-allocated `char[]` buffer containing the encoded string. * A newly-allocated `char[]` buffer containing the encoded string.
*/ */
@safe @safe
pure char[] encode(Range)(Range source) if (isArray!Range && is(ElementType!Range : ubyte)) pure char[] encode(Range)(Range source)
if (isArray!Range && is(ElementType!Range : ubyte))
{ {
return encode(source, new char[encodeLength(source.length)]); return encode(source, new char[encodeLength(source.length)]);
} }
@ -575,7 +577,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
/** /**
* ditto * ditto
*/ */
char[] encode(Range)(Range source) if (!isArray!Range && isInputRange!Range && char[] encode(Range)(Range source)
if (!isArray!Range && isInputRange!Range &&
is(ElementType!Range : ubyte) && hasLength!Range) is(ElementType!Range : ubyte) && hasLength!Range)
{ {
return encode(source, new char[encodeLength(source.length)]); return encode(source, new char[encodeLength(source.length)]);
@ -592,7 +595,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* Note: This struct is not intended to be created in user code directly; * Note: This struct is not intended to be created in user code directly;
* use the $(LREF encoder) function instead. * use the $(LREF encoder) function instead.
*/ */
struct Encoder(Range) if (isInputRange!Range && (is(ElementType!Range : const(ubyte)[]) || struct Encoder(Range)
if (isInputRange!Range && (is(ElementType!Range : const(ubyte)[]) ||
is(ElementType!Range : const(char)[]))) is(ElementType!Range : const(char)[])))
{ {
private: private:
@ -702,7 +706,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* Note: This struct is not intended to be created in user code directly; * Note: This struct is not intended to be created in user code directly;
* use the $(LREF encoder) function instead. * use the $(LREF encoder) function instead.
*/ */
struct Encoder(Range) if (isInputRange!Range && is(ElementType!Range : ubyte)) struct Encoder(Range)
if (isInputRange!Range && is(ElementType!Range : ubyte))
{ {
private: private:
Range range_; Range range_;
@ -884,7 +889,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* } * }
* ----- * -----
*/ */
Encoder!(Range) encoder(Range)(Range range) if (isInputRange!Range) Encoder!(Range) encoder(Range)(Range range)
if (isInputRange!Range)
{ {
return typeof(return)(range); return typeof(return)(range);
} }
@ -981,7 +987,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* base alphabet of the current Base64 encoding scheme. * base alphabet of the current Base64 encoding scheme.
*/ */
@trusted @trusted
pure ubyte[] decode(R1, R2)(in R1 source, return scope R2 buffer) if (isArray!R1 && is(ElementType!R1 : dchar) && pure ubyte[] decode(R1, R2)(in R1 source, return scope R2 buffer)
if (isArray!R1 && is(ElementType!R1 : dchar) &&
is(R2 == ubyte[]) && isOutputRange!(R2, ubyte)) is(R2 == ubyte[]) && isOutputRange!(R2, ubyte))
in in
{ {
@ -1065,7 +1072,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
/** /**
* ditto * ditto
*/ */
ubyte[] decode(R1, R2)(R1 source, R2 buffer) if (!isArray!R1 && isInputRange!R1 && ubyte[] decode(R1, R2)(R1 source, R2 buffer)
if (!isArray!R1 && isInputRange!R1 &&
is(ElementType!R1 : dchar) && hasLength!R1 && is(ElementType!R1 : dchar) && hasLength!R1 &&
is(R2 == ubyte[]) && isOutputRange!(R2, ubyte)) is(R2 == ubyte[]) && isOutputRange!(R2, ubyte))
in in
@ -1334,7 +1342,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* A newly-allocated `ubyte[]` buffer containing the decoded string. * A newly-allocated `ubyte[]` buffer containing the decoded string.
*/ */
@safe @safe
pure ubyte[] decode(Range)(Range source) if (isArray!Range && is(ElementType!Range : dchar)) pure ubyte[] decode(Range)(Range source)
if (isArray!Range && is(ElementType!Range : dchar))
{ {
return decode(source, new ubyte[decodeLength(source.length)]); return decode(source, new ubyte[decodeLength(source.length)]);
} }
@ -1350,7 +1359,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
/** /**
* ditto * ditto
*/ */
ubyte[] decode(Range)(Range source) if (!isArray!Range && isInputRange!Range && ubyte[] decode(Range)(Range source)
if (!isArray!Range && isInputRange!Range &&
is(ElementType!Range : dchar) && hasLength!Range) is(ElementType!Range : dchar) && hasLength!Range)
{ {
return decode(source, new ubyte[decodeLength(source.length)]); return decode(source, new ubyte[decodeLength(source.length)]);
@ -1367,7 +1377,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* Note: This struct is not intended to be created in user code directly; * Note: This struct is not intended to be created in user code directly;
* use the $(LREF decoder) function instead. * use the $(LREF decoder) function instead.
*/ */
struct Decoder(Range) if (isInputRange!Range && (is(ElementType!Range : const(char)[]) || struct Decoder(Range)
if (isInputRange!Range && (is(ElementType!Range : const(char)[]) ||
is(ElementType!Range : const(ubyte)[]))) is(ElementType!Range : const(ubyte)[])))
{ {
private: private:
@ -1492,7 +1503,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* Note: This struct is not intended to be created in user code directly; * Note: This struct is not intended to be created in user code directly;
* use the $(LREF decoder) function instead. * use the $(LREF decoder) function instead.
*/ */
struct Decoder(Range) if (isInputRange!Range && is(ElementType!Range : char)) struct Decoder(Range)
if (isInputRange!Range && is(ElementType!Range : char))
{ {
private: private:
Range range_; Range range_;
@ -1683,7 +1695,8 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
* } * }
* ----- * -----
*/ */
Decoder!(Range) decoder(Range)(Range range) if (isInputRange!Range) Decoder!(Range) decoder(Range)(Range range)
if (isInputRange!Range)
{ {
return typeof(return)(range); return typeof(return)(range);
} }

View file

@ -63,8 +63,8 @@ public:
* Throws: * Throws:
* $(REF ConvException, std,conv) if the string doesn't represent a valid number * $(REF ConvException, std,conv) if the string doesn't represent a valid number
*/ */
this(Range)(Range s) if ( this(Range)(Range s)
isBidirectionalRange!Range && if (isBidirectionalRange!Range &&
isSomeChar!(ElementType!Range) && isSomeChar!(ElementType!Range) &&
!isInfinite!Range && !isInfinite!Range &&
!isNarrowString!Range) !isNarrowString!Range)
@ -160,8 +160,8 @@ public:
* (ignored when magnitude is zero) * (ignored when magnitude is zero)
* magnitude = a finite range of unsigned integers * magnitude = a finite range of unsigned integers
*/ */
this(Range)(bool isNegative, Range magnitude) if ( this(Range)(bool isNegative, Range magnitude)
isInputRange!Range && if (isInputRange!Range &&
isUnsigned!(ElementType!Range) && isUnsigned!(ElementType!Range) &&
(hasLength!Range || isForwardRange!Range) && (hasLength!Range || isForwardRange!Range) &&
!isInfinite!Range) !isInfinite!Range)
@ -181,7 +181,8 @@ public:
} }
/// Construct a `BigInt` from a built-in integral type. /// Construct a `BigInt` from a built-in integral type.
this(T)(T x) pure nothrow @safe if (isIntegral!T) this(T)(T x) pure nothrow @safe
if (isIntegral!T)
{ {
data = data.init; // @@@: Workaround for compiler bug data = data.init; // @@@: Workaround for compiler bug
opAssign(x); opAssign(x);
@ -196,7 +197,8 @@ public:
} }
/// Construct a `BigInt` from another `BigInt`. /// Construct a `BigInt` from another `BigInt`.
this(T)(T x) pure nothrow @safe if (is(immutable T == immutable BigInt)) this(T)(T x) pure nothrow @safe
if (is(immutable T == immutable BigInt))
{ {
opAssign(x); opAssign(x);
} }
@ -210,7 +212,8 @@ public:
} }
/// Assignment from built-in integer types. /// Assignment from built-in integer types.
BigInt opAssign(T)(T x) pure nothrow @safe if (isIntegral!T) BigInt opAssign(T)(T x) pure nothrow @safe
if (isIntegral!T)
{ {
data = cast(ulong) absUnsign(x); data = cast(ulong) absUnsign(x);
sign = (x < 0); sign = (x < 0);
@ -436,8 +439,7 @@ public:
* Implements assignment operators of the form `BigInt op= BigInt`. * Implements assignment operators of the form `BigInt op= BigInt`.
*/ */
BigInt opOpAssign(string op, T)(T y) pure nothrow @safe return scope BigInt opOpAssign(string op, T)(T y) pure nothrow @safe return scope
if ((op=="+" || op== "-" || op=="*" || op=="|" || op=="&" || op=="^" || op=="/" || op=="%") if ((op=="+" || op== "-" || op=="*" || op=="|" || op=="&" || op=="^" || op=="/" || op=="%") && is (T: BigInt))
&& is (T: BigInt))
{ {
static if (op == "+") static if (op == "+")
{ {
@ -495,8 +497,7 @@ public:
*/ */
BigInt opBinary(string op, T)(T y) pure nothrow @safe const return scope BigInt opBinary(string op, T)(T y) pure nothrow @safe const return scope
if ((op=="+" || op == "*" || op=="-" || op=="|" || op=="&" || op=="^" || if ((op=="+" || op == "*" || op=="-" || op=="|" || op=="&" || op=="^" ||
op=="/" || op=="%") op=="/" || op=="%") && is (T: BigInt))
&& is (T: BigInt))
{ {
BigInt r = this; BigInt r = this;
return r.opOpAssign!(op)(y); return r.opOpAssign!(op)(y);
@ -669,7 +670,8 @@ public:
/** /**
Implements `BigInt` unary operators. Implements `BigInt` unary operators.
*/ */
BigInt opUnary(string op)() pure nothrow @safe const if (op=="+" || op=="-" || op=="~") BigInt opUnary(string op)() pure nothrow @safe const
if (op=="+" || op=="-" || op=="~")
{ {
static if (op=="-") static if (op=="-")
{ {
@ -687,7 +689,8 @@ public:
// non-const unary operations // non-const unary operations
/// ditto /// ditto
BigInt opUnary(string op)() pure nothrow @safe if (op=="++" || op=="--") BigInt opUnary(string op)() pure nothrow @safe
if (op=="++" || op=="--")
{ {
static if (op=="++") static if (op=="++")
{ {
@ -721,7 +724,8 @@ public:
} }
/// ditto /// ditto
bool opEquals(T)(const T y) const pure nothrow @nogc @safe if (isIntegral!T) bool opEquals(T)(const T y) const pure nothrow @nogc @safe
if (isIntegral!T)
{ {
if (sign != (y<0)) if (sign != (y<0))
return 0; return 0;
@ -729,7 +733,8 @@ public:
} }
/// ditto /// ditto
bool opEquals(T)(const T y) const pure nothrow @nogc if (isFloatingPoint!T) bool opEquals(T)(const T y) const pure nothrow @nogc
if (isFloatingPoint!T)
{ {
return 0 == opCmp(y); return 0 == opCmp(y);
} }
@ -896,7 +901,8 @@ public:
/** /**
Implements casting to floating point types. Implements casting to floating point types.
*/ */
T opCast(T)() @safe nothrow @nogc const if (isFloatingPoint!T) T opCast(T)() @safe nothrow @nogc const
if (isFloatingPoint!T)
{ {
return toFloat!(T, "nearest"); return toFloat!(T, "nearest");
} }
@ -1090,7 +1096,8 @@ public:
} }
/// ditto /// ditto
int opCmp(T)(const T y) pure nothrow @nogc @safe const if (isIntegral!T) int opCmp(T)(const T y) pure nothrow @nogc @safe const
if (isIntegral!T)
{ {
if (sign != (y<0) ) if (sign != (y<0) )
return sign ? -1 : 1; return sign ? -1 : 1;
@ -1098,7 +1105,8 @@ public:
return sign? -cmp: cmp; return sign? -cmp: cmp;
} }
/// ditto /// ditto
int opCmp(T)(const T y) nothrow @nogc @safe const if (isFloatingPoint!T) int opCmp(T)(const T y) nothrow @nogc @safe const
if (isFloatingPoint!T)
{ {
import core.bitop : bsr; import core.bitop : bsr;
import std.math.operations : cmp; import std.math.operations : cmp;

View file

@ -3362,12 +3362,14 @@ version (StdUnittest) private struct CountOverflows
static struct Hook1 static struct Hook1
{ {
uint calls; uint calls;
auto hookOpUnary(string op, T)(T value) if (op == "-") auto hookOpUnary(string op, T)(T value)
if (op == "-")
{ {
++calls; ++calls;
return T(42); return T(42);
} }
auto hookOpUnary(string op, T)(T value) if (op == "~") auto hookOpUnary(string op, T)(T value)
if (op == "~")
{ {
++calls; ++calls;
return T(43); return T(43);
@ -3383,12 +3385,14 @@ version (StdUnittest) private struct CountOverflows
static struct Hook2 static struct Hook2
{ {
uint calls; uint calls;
void hookOpUnary(string op, T)(ref T value) if (op == "++") void hookOpUnary(string op, T)(ref T value)
if (op == "++")
{ {
++calls; ++calls;
--value; --value;
} }
void hookOpUnary(string op, T)(ref T value) if (op == "--") void hookOpUnary(string op, T)(ref T value)
if (op == "--")
{ {
++calls; ++calls;
++value; ++value;

View file

@ -163,7 +163,8 @@ private
MsgType type; MsgType type;
Variant data; Variant data;
this(T...)(MsgType t, T vals) if (T.length > 0) this(T...)(MsgType t, T vals)
if (T.length > 0)
{ {
static if (T.length == 1) static if (T.length == 1)
{ {

View file

@ -245,7 +245,8 @@ struct DList(T)
/** /**
Constructor taking a number of nodes Constructor taking a number of nodes
*/ */
this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) this(U)(U[] values...)
if (isImplicitlyConvertible!(U, T))
{ {
insertBack(values); insertBack(values);
} }

View file

@ -801,7 +801,8 @@ Indexing operators yield or modify the value at a specified index.
/** /**
$(D k in container) returns true if the given key is in the container. $(D k in container) returns true if the given key is in the container.
*/ */
bool opBinaryRight(string op)(KeyType k) if (op == "in") bool opBinaryRight(string op)(KeyType k)
if (op == "in")
{ {
assert(0, "Not implemented"); assert(0, "Not implemented");
} }
@ -843,13 +844,15 @@ define `opBinary`.
Complexity: $(BIGOH n + m), where m is the number of elements in $(D Complexity: $(BIGOH n + m), where m is the number of elements in $(D
stuff) stuff)
*/ */
TotalContainer opBinary(string op)(Stuff rhs) if (op == "~") TotalContainer opBinary(string op)(Stuff rhs)
if (op == "~")
{ {
assert(0, "Not implemented"); assert(0, "Not implemented");
} }
/// ditto /// ditto
TotalContainer opBinaryRight(string op)(Stuff lhs) if (op == "~") TotalContainer opBinaryRight(string op)(Stuff lhs)
if (op == "~")
{ {
assert(0, "Not implemented"); assert(0, "Not implemented");
} }
@ -857,7 +860,8 @@ stuff)
/** /**
Forwards to $(D insertAfter(this[], stuff)). Forwards to $(D insertAfter(this[], stuff)).
*/ */
void opOpAssign(string op)(Stuff stuff) if (op == "~") void opOpAssign(string op)(Stuff stuff)
if (op == "~")
{ {
assert(0, "Not implemented"); assert(0, "Not implemented");
} }

View file

@ -1057,7 +1057,8 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
Complexity: $(BIGOH log(n)) Complexity: $(BIGOH log(n))
+/ +/
bool opBinaryRight(string op)(Elem e) const if (op == "in") bool opBinaryRight(string op)(Elem e) const
if (op == "in")
{ {
return _find(e) !is null; return _find(e) !is null;
} }
@ -1261,7 +1262,8 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
* *
* Complexity: $(BIGOH log(n)) * Complexity: $(BIGOH log(n))
*/ */
size_t stableInsert(Stuff)(Stuff stuff) if (isImplicitlyConvertible!(Stuff, Elem)) size_t stableInsert(Stuff)(Stuff stuff)
if (isImplicitlyConvertible!(Stuff, Elem))
{ {
static if (allowDuplicates) static if (allowDuplicates)
{ {
@ -1873,7 +1875,8 @@ assert(equal(rbt[], [5]));
/** /**
* Constructor. Pass in a range of elements to initialize the tree with. * Constructor. Pass in a range of elements to initialize the tree with.
*/ */
this(Stuff)(Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, Elem)) this(Stuff)(Stuff stuff)
if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, Elem))
{ {
_setup(); _setup();
stableInsert(stuff); stableInsert(stuff);

View file

@ -182,7 +182,8 @@ if (!is(T == shared))
/** /**
Constructor taking a number of nodes Constructor taking a number of nodes
*/ */
this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) this(U)(U[] values...)
if (isImplicitlyConvertible!(U, T))
{ {
insertFront(values); insertFront(values);
} }

View file

@ -1935,7 +1935,8 @@ template hasToString(T, Char)
static struct G static struct G
{ {
string toString() {return "";} string toString() {return "";}
void toString(Writer)(ref Writer w) if (isOutputRange!(Writer, string)) {} void toString(Writer)(ref Writer w)
if (isOutputRange!(Writer, string)) {}
} }
static struct H static struct H
{ {
@ -1946,7 +1947,8 @@ template hasToString(T, Char)
} }
static struct I static struct I
{ {
void toString(Writer)(ref Writer w) if (isOutputRange!(Writer, string)) {} void toString(Writer)(ref Writer w)
if (isOutputRange!(Writer, string)) {}
void toString(Writer)(ref Writer w, scope const ref FormatSpec!char fmt) void toString(Writer)(ref Writer w, scope const ref FormatSpec!char fmt)
if (isOutputRange!(Writer, string)) if (isOutputRange!(Writer, string))
{} {}
@ -2042,7 +2044,8 @@ template hasToString(T, Char)
static struct G static struct G
{ {
string toString() const {return "";} string toString() const {return "";}
void toString(Writer)(ref Writer w) const if (isOutputRange!(Writer, string)) {} void toString(Writer)(ref Writer w) const
if (isOutputRange!(Writer, string)) {}
} }
static struct H static struct H
{ {
@ -2053,7 +2056,8 @@ template hasToString(T, Char)
} }
static struct I static struct I
{ {
void toString(Writer)(ref Writer w) const if (isOutputRange!(Writer, string)) {} void toString(Writer)(ref Writer w) const
if (isOutputRange!(Writer, string)) {}
void toString(Writer)(ref Writer w, scope const ref FormatSpec!char fmt) const void toString(Writer)(ref Writer w, scope const ref FormatSpec!char fmt) const
if (isOutputRange!(Writer, string)) if (isOutputRange!(Writer, string))
{} {}
@ -2603,7 +2607,8 @@ if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) || !is(Builtin
{ {
int n = 0; int n = 0;
alias n this; alias n this;
T opCast(T) () if (is(T == Frop)) T opCast(T) ()
if (is(T == Frop))
{ {
return Frop(); return Frop();
} }

View file

@ -250,7 +250,8 @@ private:
data = x; data = x;
} }
package(std) // used from: std.bigint package(std) // used from: std.bigint
this(T)(T x) pure nothrow @safe scope if (isIntegral!T) this(T)(T x) pure nothrow @safe scope
if (isIntegral!T)
{ {
opAssign(x); opAssign(x);
} }
@ -312,7 +313,8 @@ public:
} }
/// ///
void opAssign(Tulong)(Tulong u) pure nothrow @safe scope if (is (Tulong == ulong)) void opAssign(Tulong)(Tulong u) pure nothrow @safe scope
if (is (Tulong == ulong))
{ {
if (u == 0) data = ZERO; if (u == 0) data = ZERO;
else if (u == 1) data = ONE; else if (u == 1) data = ONE;
@ -356,7 +358,8 @@ public:
} }
/// ///
int opCmp(Tulong)(Tulong y) pure nothrow @nogc const @safe scope if (is (Tulong == ulong)) int opCmp(Tulong)(Tulong y) pure nothrow @nogc const @safe scope
if (is (Tulong == ulong))
{ {
if (data.length > maxBigDigits!Tulong) if (data.length > maxBigDigits!Tulong)
return 1; return 1;
@ -501,8 +504,8 @@ public:
} }
// return false if invalid character found // return false if invalid character found
bool fromHexString(Range)(Range s) scope if ( bool fromHexString(Range)(Range s) scope
isBidirectionalRange!Range && isSomeChar!(ElementType!Range)) if (isBidirectionalRange!Range && isSomeChar!(ElementType!Range))
{ {
import std.range : walkLength; import std.range : walkLength;
@ -570,8 +573,8 @@ public:
} }
// return true if OK; false if erroneous characters found // return true if OK; false if erroneous characters found
bool fromDecimalString(Range)(Range s) scope if ( bool fromDecimalString(Range)(Range s) scope
isForwardRange!Range && isSomeChar!(ElementType!Range)) if (isForwardRange!Range && isSomeChar!(ElementType!Range))
{ {
import std.range : walkLength; import std.range : walkLength;
@ -761,8 +764,8 @@ public:
// If wantSub is false, return x + y, leaving sign unchanged // If wantSub is false, return x + y, leaving sign unchanged
// If wantSub is true, return abs(x - y), negating sign if x < y // If wantSub is true, return abs(x - y), negating sign if x < y
static BigUint addOrSubInt(Tulong)(const scope BigUint x, Tulong y, static BigUint addOrSubInt(Tulong)(const scope BigUint x, Tulong y, bool wantSub, ref bool sign) pure nothrow @safe
bool wantSub, ref bool sign) pure nothrow @safe if (is(Tulong == ulong)) if (is(Tulong == ulong))
{ {
BigUint r; BigUint r;
if (wantSub) if (wantSub)
@ -921,7 +924,8 @@ public:
} }
// return x % y // return x % y
static uint modInt(T)(scope BigUint x, T y_) pure if ( is(immutable T == immutable uint) ) static uint modInt(T)(scope BigUint x, T y_) pure
if ( is(immutable T == immutable uint) )
{ {
import core.memory : GC; import core.memory : GC;
uint y = y_; uint y = y_;
@ -994,7 +998,8 @@ public:
// return x op y // return x op y
static BigUint bitwiseOp(string op)(scope BigUint x, scope BigUint y, bool xSign, bool ySign, ref bool resultSign) static BigUint bitwiseOp(string op)(scope BigUint x, scope BigUint y, bool xSign, bool ySign, ref bool resultSign)
pure nothrow @safe if (op == "|" || op == "^" || op == "&") pure nothrow @safe
if (op == "|" || op == "^" || op == "&")
{ {
auto d1 = includeSign(x.data, y.uintLength, xSign); auto d1 = includeSign(x.data, y.uintLength, xSign);
auto d2 = includeSign(y.data, x.uintLength, ySign); auto d2 = includeSign(y.data, x.uintLength, ySign);

View file

@ -255,7 +255,8 @@ class ReferenceInputRange(T)
{ {
import std.array : array; import std.array : array;
this(Range)(Range r) if (isInputRange!Range) {_payload = array(r);} this(Range)(Range r)
if (isInputRange!Range) {_payload = array(r);}
final @property ref T front() {return _payload.front;} final @property ref T front() {return _payload.front;}
final void popFront() {_payload.popFront();} final void popFront() {_payload.popFront();}
final @property bool empty() {return _payload.empty;} final @property bool empty() {return _payload.empty;}
@ -279,7 +280,8 @@ Reference forward range
*/ */
class ReferenceForwardRange(T) : ReferenceInputRange!T class ReferenceForwardRange(T) : ReferenceInputRange!T
{ {
this(Range)(Range r) if (isInputRange!Range) {super(r);} this(Range)(Range r)
if (isInputRange!Range) {super(r);}
final @property auto save(this This)() {return new This( _payload);} final @property auto save(this This)() {return new This( _payload);}
} }
@ -298,7 +300,8 @@ Reference bidirectional range
*/ */
class ReferenceBidirectionalRange(T) : ReferenceForwardRange!T class ReferenceBidirectionalRange(T) : ReferenceForwardRange!T
{ {
this(Range)(Range r) if (isInputRange!Range) {super(r);} this(Range)(Range r)
if (isInputRange!Range) {super(r);}
final @property ref T back() {return _payload.back;} final @property ref T back() {return _payload.back;}
final void popBack() {_payload.popBack();} final void popBack() {_payload.popBack();}
} }

View file

@ -652,7 +652,8 @@ struct JSONValue
} }
} }
private void assignRef(T)(ref T arg) if (isStaticArray!T) private void assignRef(T)(ref T arg)
if (isStaticArray!T)
{ {
type_tag = JSONType.array; type_tag = JSONType.array;
static if (is(ElementEncodingType!T : JSONValue)) static if (is(ElementEncodingType!T : JSONValue))
@ -680,12 +681,14 @@ struct JSONValue
* and `K` i.e. a JSON object, any array or `bool`. The type will * and `K` i.e. a JSON object, any array or `bool`. The type will
* be set accordingly. * be set accordingly.
*/ */
this(T)(T arg) if (!isStaticArray!T) this(T)(T arg)
if (!isStaticArray!T)
{ {
assign(arg); assign(arg);
} }
/// Ditto /// Ditto
this(T)(ref T arg) if (isStaticArray!T) this(T)(ref T arg)
if (isStaticArray!T)
{ {
assignRef(arg); assignRef(arg);
} }
@ -774,12 +777,14 @@ struct JSONValue
assert(arr1 != arr2); assert(arr1 != arr2);
} }
void opAssign(T)(T arg) if (!isStaticArray!T && !is(T : JSONValue)) void opAssign(T)(T arg)
if (!isStaticArray!T && !is(T : JSONValue))
{ {
assign(arg); assign(arg);
} }
void opAssign(T)(ref T arg) if (isStaticArray!T) void opAssign(T)(ref T arg)
if (isStaticArray!T)
{ {
assignRef(arg); assignRef(arg);
} }

View file

@ -496,7 +496,8 @@ public:
static @property CustomFloat im() { return CustomFloat(0.0f); } static @property CustomFloat im() { return CustomFloat(0.0f); }
/// Initialize from any `real` compatible type. /// Initialize from any `real` compatible type.
this(F)(F input) if (__traits(compiles, cast(real) input )) this(F)(F input)
if (__traits(compiles, cast(real) input ))
{ {
this = input; this = input;
} }

View file

@ -2269,7 +2269,8 @@ public:
call to `popFront` or, if thrown during construction, simply call to `popFront` or, if thrown during construction, simply
allowed to propagate to the caller. allowed to propagate to the caller.
*/ */
auto asyncBuf(S)(S source, size_t bufSize = 100) if (isInputRange!S) auto asyncBuf(S)(S source, size_t bufSize = 100)
if (isInputRange!S)
{ {
static final class AsyncBuf static final class AsyncBuf
{ {

View file

@ -1446,8 +1446,7 @@ private auto _withDefaultExtension(R, C)(R path, C[] ext)
of segments to assemble the path from. of segments to assemble the path from.
Returns: The assembled path. Returns: The assembled path.
*/ */
immutable(ElementEncodingType!(ElementType!Range))[] immutable(ElementEncodingType!(ElementType!Range))[] buildPath(Range)(scope Range segments)
buildPath(Range)(scope Range segments)
if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range)) if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range))
{ {
if (segments.empty) return null; if (segments.empty) return null;

View file

@ -935,7 +935,8 @@ Parameters for the generator.
`Exception` if the InputRange didn't provide enough elements to seed the generator. `Exception` if the InputRange didn't provide enough elements to seed the generator.
The number of elements required is the 'n' template parameter of the MersenneTwisterEngine struct. The number of elements required is the 'n' template parameter of the MersenneTwisterEngine struct.
*/ */
void seed(T)(T range) if (isInputRange!T && is(immutable ElementType!T == immutable UIntType)) void seed(T)(T range)
if (isInputRange!T && is(immutable ElementType!T == immutable UIntType))
{ {
this.seedImpl(range, this.state); this.seedImpl(range, this.state);
} }
@ -2215,6 +2216,7 @@ at least that number won't be represented fairly.
Hence, our condition to reroll is Hence, our condition to reroll is
`bucketFront > (UpperType.max - (upperDist - 1))` `bucketFront > (UpperType.max - (upperDist - 1))`
+/ +/
/// ditto
auto uniform(string boundaries = "[)", T1, T2, RandomGen) auto uniform(string boundaries = "[)", T1, T2, RandomGen)
(T1 a, T2 b, ref RandomGen rng) (T1 a, T2 b, ref RandomGen rng)
if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) && if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) &&
@ -2277,9 +2279,14 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) &&
return cast(ResultType)(lower + offset); return cast(ResultType)(lower + offset);
} }
///
@safe unittest @safe unittest
{ {
import std.conv : to; import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789); auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen))); static assert(isForwardRange!(typeof(gen)));
@ -2290,7 +2297,7 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) &&
auto c = uniform(0.0, 1.0); auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1); assert(0 <= c && c < 1);
static foreach (T; std.meta.AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort, static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real)) int, uint, long, ulong, float, double, real))
{{ {{
T lo = 0, hi = 100; T lo = 0, hi = 100;
@ -2344,7 +2351,7 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) &&
auto reproRng = Xorshift(239842); auto reproRng = Xorshift(239842);
static foreach (T; std.meta.AliasSeq!(char, wchar, dchar, byte, ubyte, short, static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong)) ushort, int, uint, long, ulong))
{{ {{
T lo = T.min + 10, hi = T.max - 10; T lo = T.min + 10, hi = T.max - 10;

View file

@ -7492,7 +7492,8 @@ if (!isIntegral!(CommonType!(B, E)) &&
bool opEquals(Cyclic c) const { return current == c.current; } bool opEquals(Cyclic c) const { return current == c.current; }
bool opEquals(int i) const { return current == i; } bool opEquals(int i) const { return current == i; }
void opUnary(string op)() if (op == "++") void opUnary(string op)()
if (op == "++")
{ {
current = (current + 1) % wrapAround; current = (current + 1) % wrapAround;
} }

View file

@ -474,7 +474,8 @@ void put(R, E)(ref R r, E e)
{ {
string data; string data;
void put(C)(C c) if (isSomeChar!C) void put(C)(C c)
if (isSomeChar!C)
{ {
data ~= c; data ~= c;
} }

View file

@ -3044,7 +3044,8 @@ is empty, throws an `Exception`. In case of an I/O error throws
} }
/// ditto /// ditto
void put(C)(scope C c) @safe if (isSomeChar!C || is(C : const(ubyte))) void put(C)(scope C c) @safe
if (isSomeChar!C || is(C : const(ubyte)))
{ {
import std.utf : decodeFront, encode, stride; import std.utf : decodeFront, encode, stride;

View file

@ -7367,10 +7367,12 @@ template isInstanceOf(alias S, alias T)
static struct A(T = void) static struct A(T = void)
{ {
// doesn't work as expected, only accepts A when T = void // doesn't work as expected, only accepts A when T = void
void func(B)(B b) if (isInstanceOf!(A, B)) {} void func(B)(B b)
if (isInstanceOf!(A, B)) {}
// correct behavior // correct behavior
void method(B)(B b) if (isInstanceOf!(TemplateOf!(A), B)) {} void method(B)(B b)
if (isInstanceOf!(TemplateOf!(A), B)) {}
} }
A!(void) a1; A!(void) a1;

View file

@ -2235,12 +2235,14 @@ template tuple(Names...)
// e.g. Tuple!(int, "x", string, "y") // e.g. Tuple!(int, "x", string, "y")
template Interleave(A...) template Interleave(A...)
{ {
template and(B...) if (B.length == 1) template and(B...)
if (B.length == 1)
{ {
alias and = AliasSeq!(A[0], B[0]); alias and = AliasSeq!(A[0], B[0]);
} }
template and(B...) if (B.length != 1) template and(B...)
if (B.length != 1)
{ {
alias and = AliasSeq!(A[0], B[0], alias and = AliasSeq!(A[0], B[0],
Interleave!(A[1..$]).and!(B[1..$])); Interleave!(A[1..$]).and!(B[1..$]));
@ -7498,7 +7500,8 @@ Constructor that initializes the payload.
Postcondition: `refCountedStore.isInitialized` Postcondition: `refCountedStore.isInitialized`
*/ */
this(A...)(auto ref A args) if (A.length > 0) this(A...)(auto ref A args)
if (A.length > 0)
out out
{ {
assert(refCountedStore.isInitialized); assert(refCountedStore.isInitialized);
@ -7931,7 +7934,8 @@ template borrow(alias fun)
{ {
import std.functional : unaryFun; import std.functional : unaryFun;
auto ref borrow(RC)(RC refCount) if auto ref borrow(RC)(RC refCount)
if
( (
isInstanceOf!(SafeRefCounted, RC) isInstanceOf!(SafeRefCounted, RC)
&& is(typeof(unaryFun!fun(refCount.refCountedPayload))) && is(typeof(unaryFun!fun(refCount.refCountedPayload)))
@ -8274,7 +8278,8 @@ mixin template Proxy(alias a)
} }
} }
auto ref opAssign (this X, V )(auto ref V v) if (!is(V == typeof(this))) { return a = v; } auto ref opAssign (this X, V )(auto ref V v)
if (!is(V == typeof(this))) { return a = v; }
auto ref opIndexAssign(this X, V, D...)(auto ref V v, auto ref D i) { return a[i] = v; } auto ref opIndexAssign(this X, V, D...)(auto ref V v, auto ref D i) { return a[i] = v; }
auto ref opSliceAssign(this X, V )(auto ref V v) { return a[] = v; } auto ref opSliceAssign(this X, V )(auto ref V v) { return a[] = v; }
auto ref opSliceAssign(this X, V, B, E)(auto ref V v, auto ref B b, auto ref E e) { return a[b .. e] = v; } auto ref opSliceAssign(this X, V, B, E)(auto ref V v, auto ref B b, auto ref E e) { return a[b .. e] = v; }
@ -10653,25 +10658,29 @@ struct Ternary
$(TR $(TD `unknown`) $(TD `unknown`) $(TD) $(TD `unknown`) $(TD `unknown`) $(TD `unknown`)) $(TR $(TD `unknown`) $(TD `unknown`) $(TD) $(TD `unknown`) $(TD `unknown`) $(TD `unknown`))
) )
*/ */
Ternary opUnary(string s)() if (s == "~") Ternary opUnary(string s)()
if (s == "~")
{ {
return make((386 >> value) & 6); return make((386 >> value) & 6);
} }
/// ditto /// ditto
Ternary opBinary(string s)(Ternary rhs) if (s == "|") Ternary opBinary(string s)(Ternary rhs)
if (s == "|")
{ {
return make((25_512 >> (value + rhs.value)) & 6); return make((25_512 >> (value + rhs.value)) & 6);
} }
/// ditto /// ditto
Ternary opBinary(string s)(Ternary rhs) if (s == "&") Ternary opBinary(string s)(Ternary rhs)
if (s == "&")
{ {
return make((26_144 >> (value + rhs.value)) & 6); return make((26_144 >> (value + rhs.value)) & 6);
} }
/// ditto /// ditto
Ternary opBinary(string s)(Ternary rhs) if (s == "^") Ternary opBinary(string s)(Ternary rhs)
if (s == "^")
{ {
return make((26_504 >> (value + rhs.value)) & 6); return make((26_504 >> (value + rhs.value)) & 6);
} }
@ -10937,7 +10946,8 @@ struct RefCounted(T, RefCountedAutoInitialize autoInit =
return _refCounted; return _refCounted;
} }
this(A...)(auto ref A args) if (A.length > 0) this(A...)(auto ref A args)
if (A.length > 0)
out out
{ {
assert(refCountedStore.isInitialized); assert(refCountedStore.isInitialized);

View file

@ -331,7 +331,8 @@ public struct UUID
* *
* For a less strict parser, see $(LREF parseUUID) * For a less strict parser, see $(LREF parseUUID)
*/ */
this(T)(in T[] uuid) if (isSomeChar!T) this(T)(in T[] uuid)
if (isSomeChar!T)
{ {
import std.conv : to, parse; import std.conv : to, parse;
if (uuid.length < 36) if (uuid.length < 36)

View file

@ -1191,7 +1191,8 @@ public:
If the `VariantN` contains an array, applies `dg` to each If the `VariantN` contains an array, applies `dg` to each
element of the array in turn. Otherwise, throws an exception. element of the array in turn. Otherwise, throws an exception.
*/ */
int opApply(Delegate)(scope Delegate dg) if (is(Delegate == delegate)) int opApply(Delegate)(scope Delegate dg)
if (is(Delegate == delegate))
{ {
alias A = Parameters!(Delegate)[0]; alias A = Parameters!(Delegate)[0];
if (type == typeid(A[])) if (type == typeid(A[]))