you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 1 year ago (1 child)

I was under the impression that the compiler already optimizes out a lot of clones where the clone is primarily used to satisfy the borrow checker. Is that not the case?

  • source
  • hideshow 1 child comment
  • [–] [S] 3 points 1 year ago*

    I would say depends but generally I would think not? I mean say you clone a string because you move it in one place and also need to borrow it in another place. So you clone to avoid the borrow checker erroring out on that. As far as I know, there will be two different strings created with separate allocations and all (but I could be wrong).

  • source
  • parent