Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ has_public_example="-etc.c.curl,\
imports_sortedness="+disabled"
;imports_sortedness="-etc.c.curl,-std.algorithm.comparison,-std.algorithm.internal,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.c.freebsd.socket,-std.c.linux.pthread,-std.c.process,-std.complex,-std.concurrency,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.conv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.systime,-std.datetime.timezone,-std.digest,-std.digest.hmac,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.common,-std.experimental.allocator.mallocator,-std.experimental.allocator.mmap_allocator,-std.experimental.allocator.showcase,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.math.biguintcore,-std.internal.test.dummyrange,-std.json,-std.math,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.signals,-std.socket,-std.stdio,-std.string,-std.uni,-std.utf,-std.uuid,-std.variant,-std.windows.charset,-std.windows.registry,-std.windows.syserror,-std.zip"
; Checks for labels with the same name as variables
label_var_same_name_check="-std.algorithm.iteration,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.conv,-std.encoding,-std.experimental.allocator.building_blocks.segregator,-std.experimental.typecons,-std.format,-std.internal.digest.sha_SSSE3,-std.parallelism,-std.process,-std.typecons,-std.utf"
label_var_same_name_check="-std.algorithm.iteration,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.conv,-std.encoding,-std.experimental.allocator.building_blocks.segregator,-std.experimental.typecons,-std.format,-std.internal.digest.sha_SSSE3,-std.parallelism,-std.process,-std.typecons,-std.utf,-std.traits"
Copy link
Contributor Author

@nordlow nordlow Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed @wilzbach ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't recall that this would have been fixed on the dscanner side. Though opening an issue there might help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ok to keep as is then so we can pull this?

; Checks for subtraction from .length properties
length_subtraction_check="+disabled"
;length_subtraction_check="-std.algorithm.internal,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.sorting,-std.array,-std.concurrency,-std.container.array,-std.container.binaryheap,-std.conv,-std.datetime.timezone,-std.experimental.allocator.building_blocks.segregator,-std.experimental.logger.core,-std.file,-std.format,-std.getopt,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.biguintx86,-std.internal.scopebuffer,-std.math,-std.net.curl,-std.net.isemail,-std.numeric,-std.parallelism,-std.path,-std.process,-std.range,-std.regex,-std.regex.internal.parser,-std.regex.internal.tests,-std.string,-std.uni,-std.windows.charset,-std.windows.registry,-std.zip"
Expand Down
62 changes: 24 additions & 38 deletions std/meta.d
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ if (!isAggregateType!T || is(Unqual!T == T))
*/
template staticIndexOf(T, TList...)
{
enum staticIndexOf = genericIndexOf!(T, TList).index;
enum staticIndexOf = genericIndexOf!(T, TList);
}

/// Ditto
template staticIndexOf(alias T, TList...)
{
enum staticIndexOf = genericIndexOf!(T, TList).index;
enum staticIndexOf = genericIndexOf!(T, TList);
}

///
Expand All @@ -303,27 +303,17 @@ template staticIndexOf(alias T, TList...)
private template genericIndexOf(args...)
if (args.length >= 1)
{
alias e = OldAlias!(args[0]);
alias tuple = args[1 .. $];

static if (tuple.length)
static foreach (idx, arg; args[1 .. $])
{
alias head = OldAlias!(tuple[0]);
alias tail = tuple[1 .. $];

static if (isSame!(e, head))
static if (is(typeof(genericIndexOf) == void) && // not yet defined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

isSame!(args[0], arg))
{
enum index = 0;
}
else
{
enum next = genericIndexOf!(e, tail).index;
enum index = (next == -1) ? -1 : 1 + next;
enum genericIndexOf = idx;
}
}
else
static if (is(typeof(genericIndexOf) == void)) // no hit
{
enum index = -1;
enum genericIndexOf = -1;
}
}

Expand Down Expand Up @@ -844,19 +834,17 @@ template predicate must be instantiable with all the given items.
*/
template allSatisfy(alias F, T...)
{
static if (T.length == 0)
{
enum allSatisfy = true;
}
else static if (T.length == 1)
static foreach (Ti; T)
{
enum allSatisfy = F!(T[0]);
static if (!is(typeof(allSatisfy) == bool) && // not yet defined
!F!(Ti))
{
enum allSatisfy = false;
}
}
else
static if (!is(typeof(allSatisfy) == bool)) // if not yet defined
{
enum allSatisfy =
allSatisfy!(F, T[ 0 .. $/2]) &&
allSatisfy!(F, T[$/2 .. $ ]);
enum allSatisfy = true;
}
}

Expand All @@ -878,19 +866,17 @@ template predicate must be instantiable with one of the given items.
*/
template anySatisfy(alias F, T...)
{
static if (T.length == 0)
static foreach (Ti; T)
{
enum anySatisfy = false;
}
else static if (T.length == 1)
{
enum anySatisfy = F!(T[0]);
static if (!is(typeof(anySatisfy) == bool) && // not yet defined
F!(Ti))
{
enum anySatisfy = true;
}
}
else
static if (!is(typeof(anySatisfy) == bool)) // if not yet defined
{
enum anySatisfy =
anySatisfy!(F, T[ 0 .. $/2]) ||
anySatisfy!(F, T[$/2 .. $ ]);
enum anySatisfy = false;
}
}

Expand Down
36 changes: 22 additions & 14 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -6931,17 +6931,20 @@ template isInstanceOf(alias S, alias T)
*
* See_Also: $(LREF isTypeTuple).
*/
template isExpressions(T ...)
template isExpressions(T...)
{
static if (T.length >= 2)
enum bool isExpressions =
isExpressions!(T[0 .. $/2]) &&
isExpressions!(T[$/2 .. $]);
else static if (T.length == 1)
enum bool isExpressions =
!is(T[0]) && __traits(compiles, { auto ex = T[0]; });
else
enum bool isExpressions = true; // default
static foreach (Ti; T)
{
static if (!is(typeof(isExpressions) == bool) && // not yet defined
(is(Ti) || !__traits(compiles, { auto ex = Ti; })))
{
enum isExpressions = false;
}
}
static if (!is(typeof(isExpressions) == bool)) // if not yet defined
{
enum isExpressions = true;
}
}

///
Expand Down Expand Up @@ -8487,13 +8490,18 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...)
*/
template allSameType(T...)
{
static if (T.length <= 1)
static foreach (idx, Ti; T)
{
enum bool allSameType = true;
static if (idx + 1 < T.length &&
!is(typeof(allSameType) == bool) &&
!is(T[idx] == T[idx + 1]))
{
enum bool allSameType = false;
}
}
else
static if (!is(typeof(allSameType) == bool))
{
enum bool allSameType = is(T[0] == T[1]) && allSameType!(T[1..$]);
enum bool allSameType = true;
Copy link
Contributor

@wilzbach wilzbach Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks like DScanner's check is bogus here:

std/traits.d(8419:19)[warn]: Variable "allSameType" has the same name as a variable defined on line 8414.

I don't know why the other very similar code is accepted though.
However, you can ignore this module for this check by adding the following to the ModuleFilter blacklist in the .dscanner.ini

label_var_same_name_check="-std.traits"

(Ideally preceded by a reference to a DScanner issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}

Expand Down