tensuremove3.nim 524 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. errormsg: "cannot move 'x', passing 'x' to a sink parameter introduces an implicit copy"
  3. matrix: "--cursorinference:on; --cursorinference:off"
  4. """
  5. block:
  6. type
  7. X = object
  8. s: string
  9. proc `=copy`(x: var X, y: X) =
  10. x.s = "copied " & y.s
  11. proc `=sink`(x: var X, y: X) =
  12. `=destroy`(x)
  13. wasMoved(x)
  14. x.s = "moved " & y.s
  15. proc consume(x: sink X) =
  16. discard x.s
  17. proc main =
  18. var s = "abcdefg"
  19. var x = X(s: ensureMove s)
  20. consume(ensureMove x)
  21. discard x
  22. main()