Skip to content

Commit

Permalink
Merge pull request #8714 from WebFreak001/fix-22147
Browse files Browse the repository at this point in the history
 fix 22147: allow @disable this(this) T in DList!T
  • Loading branch information
RazvanN7 authored Mar 13, 2023
2 parents 2f8dd14 + 3b3757a commit 1b89dcf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
36 changes: 33 additions & 3 deletions std/container/dlist.d
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ struct DList(T)

this (BaseNode _base, T _payload)
{
import std.algorithm.mutation : move;

this._base = _base;
this._payload = _payload;
this._payload = move(_payload);
}

inout(BaseNode)* asBaseNode() inout @trusted
Expand All @@ -216,7 +218,9 @@ struct DList(T)
//Construct as new PayNode, and returns it as a BaseNode.
static BaseNode* createNode(Stuff)(auto ref Stuff arg, BaseNode* prev = null, BaseNode* next = null)
{
return (new PayNode(BaseNode(prev, next), arg)).asBaseNode();
import std.algorithm.mutation : move;

return (new PayNode(BaseNode(prev, next), move(arg))).asBaseNode();
}

void initialize() nothrow @safe pure
Expand Down Expand Up @@ -721,7 +725,9 @@ Complexity: $(BIGOH n)
*/
bool linearRemoveElement(T value)
{
auto n1 = findNodeByValue(_root, value);
import std.algorithm.mutation : move;

auto n1 = findNodeByValue(_root, move(value));
if (n1)
{
auto n2 = n1._next._next;
Expand Down Expand Up @@ -1118,3 +1124,27 @@ private:
a.insertFront(iota(0, 5)); // can insert range with non-ref front
assert(a.front == 0 && a.back == 4);
}

// https://issues.dlang.org/show_bug.cgi?id=22147
@safe unittest
{
import std.algorithm.mutation : move;

static struct Item
{
@disable this(this);

int x;
}

auto list = DList!Item();
list.insertFront(Item(1));
assert(list[].walkLength == 1);
assert(list.front.x == 1);
auto item = list.moveFront;
item.x = 2;
list.front = move(item);
assert(list.front.x == 2);
list.removeFront();
assert(list[].walkLength == 0);
}
6 changes: 3 additions & 3 deletions std/range/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -2313,12 +2313,12 @@ if (isInputRange!(Unqual!Range) &&
/// ditto
@property void front(ElementType!R v)
{
import std.algorithm.mutation : move;

assert(!empty,
"Attempting to assign to the front of an empty "
~ Take.stringof);
// This has to return auto instead of void because of
// https://issues.dlang.org/show_bug.cgi?id=4706
source.front = v;
source.front = move(v);
}

static if (hasMobileElements!R)
Expand Down
3 changes: 2 additions & 1 deletion std/range/primitives.d
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,8 @@ See_Also:
*/
enum bool isBidirectionalRange(R) = isForwardRange!R
&& is(typeof((R r) => r.popBack))
&& is(typeof((R r) { return r.back; } (R.init)) == ElementType!R);
&& (is(typeof((return ref R r) => r.back)) || is(typeof(ref (return ref R r) => r.back)))
&& is(typeof(R.init.back.init) == ElementType!R);

///
@safe unittest
Expand Down

0 comments on commit 1b89dcf

Please sign in to comment.