#Use of moved value even when using reference?

9 messages · Page 1 of 1 (latest)

warped swallow
#

This is moving the reference (named cells) and not the Vec... Not sure how to explain that further. You can pass &mut cells instead, which creates a new reference each time the loop is started, instead of creating one reference at the beginning of the function.

The bare version works with shared references because they are Copy. Mut references aren't.

#

I think you can also do &mut *cells but not totally sure

#

Oh yeah if you don't need it mut. I didn't read that far lol

#

Yeah it'll give you something with the type &Vec<Cell>, which the for loop calls IntoIterator::into_iter on, and it gives you items of type &Cell.

#

It's the same. Methods do some deref magic so it'll really be calling Vec::iter(&*cells), which produces std::vec::Iter, and when the for loop calls IntoIterator::into_iter on that, it just returns itself.

#

That doesn't seem like it changes anything. You sure it doesn't give an error somewhere else instead?

#

Rust checks things in stages, so if you have a syntax error for example, you won't see any type errors.

#

Probably not, because it needs to know what you meant in order to check later things.

#

Btw if you ran cargo check on the original error, it would show more help than the IDE error.