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
fnmut_iter(_:&mutdynIterator<Item=u8>){}fnmain(){let v = vec![1,2,3];mut_iter(&mut v.iter().cloned());// this compiles finemut_iter(&mut v[..].iter().cloned());// this does notmut_iter(&mut(&v[..]).iter().cloned());// this also compiles fine}
gives this error:
error[E0596]: cannot borrow `v` asmutable,as it is not declaredasmutable
--> src/main.rs:6:19
|
4 | let v = vec![1,2,3];
| - help:consider changing this to be mutable: `mut v`
5 | mut_iter(&mut v.iter().cloned());6 | mut_iter(&mut v[..].iter().cloned());
| ^ cannot borrow asmutable
error: aborting due to previous error
In both cases, the only thing being mutably referenced is the iterator, not the vec or the slice itself. It's clear that the &mut is binding loosely to the whole remainder of the expression (as it should) because mut_iter is accepting a mutable reference as an argument, so there's no chance this is being parsed as (&mut v[..])....
What's going on here? Repros on both stable and nightly (with and without NLL, which means it's not just funkiness in AST borrowck, right?).
The text was updated successfully, but these errors were encountered:
Looking further, I'm guessing this has something to do with convert_place_derefs_to_mutable which will convert Index into IndexMut. Exactly why that's making it's way all the way down to the initial slice provided to the call is still a mystery, but it's not a stretch to imagine it recursing on the expression in some less-than-precise way.
gives this error:
In both cases, the only thing being mutably referenced is the iterator, not the vec or the slice itself. It's clear that the
&mut
is binding loosely to the whole remainder of the expression (as it should) becausemut_iter
is accepting a mutable reference as an argument, so there's no chance this is being parsed as(&mut v[..])...
.What's going on here? Repros on both stable and nightly (with and without NLL, which means it's not just funkiness in AST borrowck, right?).
The text was updated successfully, but these errors were encountered: