Skip to content

Commit a6a9661

Browse files
committed
fix scope warnings, fix #196
1 parent c25a0eb commit a6a9661

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/containers/hashmap.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
242242
/**
243243
* Returns: a range of the keys in this map.
244244
*/
245-
auto byKey(this This)() inout @trusted
245+
auto byKey(this This)() inout @safe return scope
246246
{
247-
return MapRange!(This, IterType.key)(cast(Unqual!(This)*) &this);
247+
return MapRange!(This, IterType.key)((() @trusted => cast(Unqual!(This)*) &this)());
248248
}
249249

250250
/**
@@ -271,9 +271,9 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
271271
/**
272272
* Returns: a range of the values in this map.
273273
*/
274-
auto byValue(this This)() inout @trusted
274+
auto byValue(this This)() inout @safe return scope
275275
{
276-
return MapRange!(This, IterType.value)(cast(Unqual!(This)*) &this);
276+
return MapRange!(This, IterType.value)((() @trusted => cast(Unqual!(This)*) &this)());
277277
}
278278

279279
/// ditto
@@ -303,9 +303,9 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
303303
* Returns: a range of the kev/value pairs in this map. The element type of
304304
* this range is a struct with `key` and `value` fields.
305305
*/
306-
auto byKeyValue(this This)() inout @trusted
306+
auto byKeyValue(this This)() inout @safe return scope
307307
{
308-
return MapRange!(This, IterType.both)(cast(Unqual!(This)*) &this);
308+
return MapRange!(This, IterType.both)((() @trusted => cast(Unqual!(This)*) &this)());
309309
}
310310

311311
/**
@@ -431,7 +431,7 @@ private:
431431

432432
private:
433433

434-
this(Unqual!(MapType)* hm)
434+
this(Unqual!(MapType)* hm) @safe
435435
{
436436
this.hm = hm;
437437
this.bucketIndex = 0;
@@ -665,7 +665,7 @@ version(emsi_containers_unittest) unittest
665665

666666
void someFunc(const scope ref HashMap!(string,Foo) map) @safe
667667
{
668-
foreach (kv; map.byKeyValue())
668+
foreach (scope kv; map.byKeyValue())
669669
{
670670
assert (kv.key == "foo");
671671
assert (kv.value.name == "Foo");

src/containers/ttree.d

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ private:
899899
return r;
900900
}
901901

902-
void rotateLeft(ref Node* root, AllocatorType allocator) @safe
902+
void rotateLeft(ref Node* root, AllocatorType allocator) @trusted
903903
{
904904
Node* newRoot;
905905
if (right.left !is null && right.right is null)
@@ -927,7 +927,7 @@ private:
927927
cleanup(newRoot, root, allocator);
928928
}
929929

930-
void rotateRight(ref Node* root, AllocatorType allocator) @safe
930+
void rotateRight(ref Node* root, AllocatorType allocator) @trusted
931931
{
932932
Node* newRoot;
933933
if (left.right !is null && left.left is null)
@@ -959,10 +959,12 @@ private:
959959
{
960960
if (newRoot.parent !is null)
961961
{
962-
if (newRoot.parent.right is &this)
963-
newRoot.parent.right = newRoot;
964-
else
965-
newRoot.parent.left = newRoot;
962+
(() @trusted {
963+
if (newRoot.parent.right is &this)
964+
newRoot.parent.right = newRoot;
965+
else
966+
newRoot.parent.left = newRoot;
967+
})();
966968
}
967969
else
968970
root = newRoot;

0 commit comments

Comments
 (0)