-
-
Notifications
You must be signed in to change notification settings - Fork 62
mut
reborrow?
#83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've been experimenting with this. The results are weirder... // error
fn xor0<'a, T: 'a, I: IntoIterator<Item = &'a T>>(inp: I, sbox: &mut [T])
where
T: core::ops::BitXorAssign<&'a T>,
{
for _ in 0..3 {
inp.into_iter().zip(sbox).for_each(|(i, s)| *s ^= i);
}
}
// error
fn xor1<I: Iterator<Item = u8> + Copy>(inp: I, sbox: &mut [u8]) {
for _ in 0..3 {
inp.zip(sbox).for_each(|(i, s)| *s ^= i);
}
}
fn drop_ref(sbox: &mut [u8]) {}
// works???
fn drop_multi(sbox: &mut [u8]) {
for _ in 0..3 {
// if sbox isn't `Copy`, then why does this compile?
// it should move into `drop_ref`, requiring a fresh reborrow
drop_ref(sbox); // replace by `drop` to trigger error
}
} |
Thank you for the suggestion! "Does it compile or not" flavor of questions do not tend to make good quiz questions so I would prefer not to include a question on this topic, but I appreciate the contribution. |
To anyone with the same confusion as me, I've found this blog which explains really well what's happening. See also. Related: rust-lang/reference#788 |
Does the following qualify? (Edition 2021)
Doesn't compile because
sbox
moves intozip
, so&mut *sbox
must be used instead. I find this silly, but "silly" isn't enough to be considered "obscure"The text was updated successfully, but these errors were encountered: