From 6a79d1ea06e418f4bed443ebdbca69c5be7dbad9 Mon Sep 17 00:00:00 2001 From: Jack Stouffer Date: Sun, 3 Jul 2016 19:33:02 -0400 Subject: [PATCH 1/3] Removed global std.conv import from std.variant --- std/variant.d | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/std/variant.d b/std/variant.d index c352dfdb9..79967a0fc 100644 --- a/std/variant.d +++ b/std/variant.d @@ -65,7 +65,7 @@ Source: $(PHOBOSSRC std/_variant.d) */ module std.variant; -import core.stdc.string, std.conv, std.exception, std.meta, std.traits, +import core.stdc.string, std.exception, std.meta, std.traits, std.typecons; /++ @@ -205,6 +205,7 @@ private: // Handler for all of a type's operations static ptrdiff_t handler(A)(OpID selector, ubyte[size]* pStore, void* parm) { + import std.conv : to; static A* getPtr(void* untyped) { if (untyped) @@ -472,11 +473,13 @@ private: case OpID.apply: static if (!isFunctionPointer!A && !isDelegate!A) { + import std.conv : text; enforce(0, text("Cannot apply `()' to a value of type `", A.stringof, "'.")); } else { + import std.conv : text; alias ParamTypes = Parameters!A; auto p = cast(Variant*) parm; auto argCount = p.get!size_t; @@ -777,6 +780,7 @@ public: @property T coerce(T)() { + import std.conv : to, text; static if (isNumeric!T || isBoolean!T) { if (convertsTo!real) @@ -1157,6 +1161,7 @@ public: } else { + import std.conv : text; enforce(false, text("Variant type ", type, " not iterable with values of type ", A.stringof)); @@ -1167,6 +1172,7 @@ public: unittest { + import std.conv : to; Variant v; int foo() { return 42; } v = &foo; @@ -1486,6 +1492,7 @@ unittest unittest { + import std.conv : ConvException; // try it with an oddly small size VariantN!(1) test; assert(test.size > 1); @@ -1820,6 +1827,7 @@ unittest } static char[] t3(int p) { + import std.conv : text; return p.text.dup; } From 909c46251affbccb05e256cf630a080ddec69623 Mon Sep 17 00:00:00 2001 From: Jack Stouffer Date: Sun, 3 Jul 2016 19:37:41 -0400 Subject: [PATCH 2/3] Removed global std.exception import from std.variant --- std/variant.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/std/variant.d b/std/variant.d index 79967a0fc..eadf63cc7 100644 --- a/std/variant.d +++ b/std/variant.d @@ -65,7 +65,7 @@ Source: $(PHOBOSSRC std/_variant.d) */ module std.variant; -import core.stdc.string, std.exception, std.meta, std.traits, +import core.stdc.string, std.meta, std.traits, std.typecons; /++ @@ -474,12 +474,14 @@ private: static if (!isFunctionPointer!A && !isDelegate!A) { import std.conv : text; + import std.exception : enforce; enforce(0, text("Cannot apply `()' to a value of type `", A.stringof, "'.")); } else { import std.conv : text; + import std.exception : enforce; alias ParamTypes = Parameters!A; auto p = cast(Variant*) parm; auto argCount = p.get!size_t; @@ -803,6 +805,7 @@ public: } else { + import std.exception : enforce; enforce(false, text("Type ", type, " does not convert to ", typeid(T))); assert(0); @@ -1162,6 +1165,7 @@ public: else { import std.conv : text; + import std.exception : enforce; enforce(false, text("Variant type ", type, " not iterable with values of type ", A.stringof)); @@ -1493,6 +1497,7 @@ unittest unittest { import std.conv : ConvException; + import std.exception : assertThrown, collectException; // try it with an oddly small size VariantN!(1) test; assert(test.size > 1); @@ -1866,6 +1871,7 @@ unittest // Ordering comparisons of incompatible types, e.g. issue 7990. unittest { + import std.exception : assertThrown; assertThrown!VariantException(Variant(3) < "a"); assertThrown!VariantException("a" < Variant(3)); assertThrown!VariantException(Variant(3) < Variant("a")); @@ -1877,6 +1883,7 @@ unittest // Handling of unordered types, e.g. issue 9043. unittest { + import std.exception : assertThrown; static struct A { int a; } assert(Variant(A(3)) != A(4)); @@ -2118,6 +2125,7 @@ unittest unittest { + import std.exception : assertThrown; Algebraic!(int, string) variant; variant = 10; @@ -2309,6 +2317,7 @@ unittest } unittest { + import std.exception : assertThrown; // http://d.puremagic.com/issues/show_bug.cgi?id=7069 Variant v; @@ -2571,6 +2580,7 @@ unittest unittest { + import std.exception : assertThrown, assertNotThrown; // Make sure Variant can handle types with opDispatch but no length field. struct SWithNoLength { From 503e9f8cb3f0cc3c661dfa60ca77cbc18499127b Mon Sep 17 00:00:00 2001 From: Jack Stouffer Date: Sun, 3 Jul 2016 19:39:35 -0400 Subject: [PATCH 3/3] Removed global core.stdc.string import from std.variant --- std/variant.d | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/std/variant.d b/std/variant.d index eadf63cc7..1235895e8 100644 --- a/std/variant.d +++ b/std/variant.d @@ -65,8 +65,7 @@ Source: $(PHOBOSSRC std/_variant.d) */ module std.variant; -import core.stdc.string, std.meta, std.traits, - std.typecons; +import std.meta, std.traits, std.typecons; /++ Gives the $(D sizeof) the largest type given. @@ -597,6 +596,7 @@ public: static if (T.sizeof <= size) { + import core.stdc.string : memcpy; // If T is a class we're only copying the reference, so it // should be safe to cast away shared so the memcpy will work. // @@ -614,6 +614,7 @@ public: } else { + import core.stdc.string : memcpy; static if (__traits(compiles, {new T(T.init);})) { auto p = new T(rhs);