You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have encountered an issue which seems very unusual to me and I believe it might be a bug.
Below is a small example which illustrates the issue.
structCountDown{count:uint,// Including the vector causes `Some(self.current())` to fail later on.vector:Vec<uint>}implCountDown{fnnew() -> CountDown{CountDown{count:10,vector:vec!(3u,4,5)}}fncurrent(self) -> uint{self.count}}implIterator<uint>forCountDown{fnnext(&mutself) -> Option<uint>{self.count -= 1;ifself.count == 0{None}else{// Whether the vector is in the struct or not, this work://Some(self.count)// When the struct contains a vector, the following causes the error:// cannot move out of dereference of `&mut`-pointer// If the vector is not in the struct, this work fine.Some(self.current())}}}fnmain(){for n inCountDown::new(){println!("n = {}", n);}}
It appears to me quite strange that the presence of a Vector within the struct (even if it isn't used) causes the issue. It also seems strange to me that returning a struct field works, but returning a method which itself returns that struct field fails.
Admittedly, I don't really understand what cannot move out of dereference of '&mut'-pointer really means; a Google search doesn't yield very much, and the documentation doesn't seem to contain much regarding the error.
The text was updated successfully, but these errors were encountered:
This is a little subtle and comes down to moves vs. copies, due to current taking self by value.
fn current(self) -> uint{
If you change that to fn current(&self) -> uint, i.e. take self by reference it will work.
The reason it works when there is no Vec is CountDown becomes Copy, i.e. a by-value use doesn't have to consume the source, essentially it just duplicates the CountDown instance out of the &mut self in next giving current its own independent copy. As soon as you have a Vec this is illegal (see my linked stack overflow answer above), and so the compiler complains.
Thanks for filing, but this isn't a bug, closing. :)
Thank you for clarifying this for me. Sorry for bringing up a non-issue, though hopefully others with the same issue might stumble upon this and find their answer.
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Sep 18, 2023
internal: unpin serde
Serde no longer uses blobs as of
serde-rs/serde#2590
As such, there's no longer need for us to pin it.
Note that this doesn't upgrade serde version we use: I am fairly confident that the blobs are already there are fine, and now I am fairly confident that all future versions of serde will be fine as well.
I have encountered an issue which seems very unusual to me and I believe it might be a bug.
Below is a small example which illustrates the issue.
It appears to me quite strange that the presence of a Vector within the struct (even if it isn't used) causes the issue. It also seems strange to me that returning a struct field works, but returning a method which itself returns that struct field fails.
Admittedly, I don't really understand what
cannot move out of dereference of '&mut'-pointer
really means; a Google search doesn't yield very much, and the documentation doesn't seem to contain much regarding the error.The text was updated successfully, but these errors were encountered: