Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scope warnings, fix #196 #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions src/containers/hashmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
/**
* Returns: a range of the keys in this map.
*/
auto byKey(this This)() inout @trusted
auto byKey(this This)() inout @safe return scope
{
return MapRange!(This, IterType.key)(cast(Unqual!(This)*) &this);
return MapRange!(This, IterType.key)((() @trusted => cast(Unqual!(This)*) &this)());
Comment on lines +245 to +247
Copy link

Choose a reason for hiding this comment

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

You're returning &this, not this, so the correct lifetime annotation here is return ref (i.e., return, since the ref on this is implicit), not return scope.

}

/**
Expand All @@ -271,9 +271,9 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
/**
* Returns: a range of the values in this map.
*/
auto byValue(this This)() inout @trusted
auto byValue(this This)() inout @safe return scope
{
return MapRange!(This, IterType.value)(cast(Unqual!(This)*) &this);
return MapRange!(This, IterType.value)((() @trusted => cast(Unqual!(This)*) &this)());
Comment on lines +274 to +276
Copy link

Choose a reason for hiding this comment

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

Same here.

}

/// ditto
Expand Down Expand Up @@ -303,9 +303,9 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
* Returns: a range of the kev/value pairs in this map. The element type of
* this range is a struct with `key` and `value` fields.
*/
auto byKeyValue(this This)() inout @trusted
auto byKeyValue(this This)() inout @safe return scope
{
return MapRange!(This, IterType.both)(cast(Unqual!(This)*) &this);
return MapRange!(This, IterType.both)((() @trusted => cast(Unqual!(This)*) &this)());
Comment on lines +306 to +308
Copy link

Choose a reason for hiding this comment

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

Same here.

}

/**
Expand Down Expand Up @@ -431,7 +431,7 @@ private:

private:

this(Unqual!(MapType)* hm)
this(Unqual!(MapType)* hm) @safe
Copy link

Choose a reason for hiding this comment

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

The compiler should be able to infer this.

{
this.hm = hm;
this.bucketIndex = 0;
Expand Down
14 changes: 8 additions & 6 deletions src/containers/ttree.d
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ private:
return r;
}

void rotateLeft(ref Node* root, AllocatorType allocator) @safe
void rotateLeft(ref Node* root, AllocatorType allocator) @trusted
Copy link

Choose a reason for hiding this comment

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

Why does this need to be @trusted? How do we know that what it's doing is memory safe? Please add a comment for future maintainers.

{
Node* newRoot;
if (right.left !is null && right.right is null)
Expand Down Expand Up @@ -927,7 +927,7 @@ private:
cleanup(newRoot, root, allocator);
}

void rotateRight(ref Node* root, AllocatorType allocator) @safe
void rotateRight(ref Node* root, AllocatorType allocator) @trusted
Copy link

Choose a reason for hiding this comment

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

Same here.

{
Node* newRoot;
if (left.right !is null && left.left is null)
Expand Down Expand Up @@ -959,10 +959,12 @@ private:
{
if (newRoot.parent !is null)
{
if (newRoot.parent.right is &this)
newRoot.parent.right = newRoot;
else
newRoot.parent.left = newRoot;
(() @trusted {
Copy link

Choose a reason for hiding this comment

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

Same here.

if (newRoot.parent.right is &this)
newRoot.parent.right = newRoot;
else
newRoot.parent.left = newRoot;
})();
}
else
root = newRoot;
Expand Down