summary refs log tree commit diff stats
path: root/doc/destructors.rst
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2021-01-20 11:05:56 +0100
committerGitHub <noreply@github.com>2021-01-20 11:05:56 +0100
commitccb11a63fb7bf4cf44a23e1b42334fd4c0664422 (patch)
tree47c2ab350baa2323cf2d44a0aef765f02048110c /doc/destructors.rst
parent4fc7fcb775140dc774a713063917fbf7d1392bdf (diff)
downloadNim-ccb11a63fb7bf4cf44a23e1b42334fd4c0664422.tar.gz
Reboot of #16195 (#16746)
* fix #16185

* fix test

* fix comment

* fix comment

* better approach

* Add more tests and move sameLocation to injectdestructors

* Better and more strict sameLocation

* Small cleanup and preliminary spec clarification

* Fix

* Fix doc

* Expand test

Co-authored-by: Andrey R (cooldome) <ariabushenko@gmail.com>
Diffstat (limited to 'doc/destructors.rst')
-rw-r--r--doc/destructors.rst10
1 files changed, 8 insertions, 2 deletions
diff --git a/doc/destructors.rst b/doc/destructors.rst
index e48e360dd..c3a7e7744 100644
--- a/doc/destructors.rst
+++ b/doc/destructors.rst
@@ -376,8 +376,14 @@ it's subtle.
 
 The simple case of ``x = x`` cannot be turned
 into ``=sink(x, x); wasMoved(x)`` because that would lose ``x``'s value.
-The solution is that simple self-assignments are simply transformed into
-an empty statement that does nothing.
+The solution is that simple self-assignments that consist of
+
+- Symbols: ``x = x``
+- Field access: ``x.f = x.f``
+- Array, sequence or string access with indices known at compile-time: ``x[0] = x[0]``
+
+are transformed into an empty statement that does nothing.
+The compiler is free to optimize further cases.
 
 The complex case looks like a variant of ``x = f(x)``, we consider
 ``x = select(rand() < 0.5, x, y)`` here: