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
fn m(var: &[&mut u8]) {
for i in var.iter_mut() {
**i = 4;
}
}
fn main() {
let mut a = 1;
let mut b = 2;
let mut c = 3;
let mut v = vec![&mut a, &mut b, &mut c];
m(&mut v);
println!("{:?}", v);
}
Gives error:
rustc 1.17.0-nightly (7846dbe0c 2017-03-26)
error: cannot borrow immutable borrowed content `*var` as mutable
--> <anon>:2:14
|
1 | fn m(var: &[&mut u8]) {
| ---------- use `&mut [&mut mut u8]` here to make mutable
2 | for i in var.iter_mut() {
| ^^^ cannot borrow as mutable
error: aborting due to previous error
It suggests the type &mut [&mut mut u8] but that is not a valid Rust type. Happens in stable, beta, nightly.
The text was updated successfully, but these errors were encountered:
#40823 says it only happens on nightly, but the example here does indeed have the same problem on stable and beta too, so maybe it's not actually a duplicate. Here it is on the playground.
rustc 1.16.0 (30cf806ef 2017-03-10)
error: cannot borrow immutable borrowed content `*var` as mutable
--> <anon>:2:14
|
1 | fn m(var: &[&mut u8]) {
| ---------- use `&mut [&mut mut u8]` here to make mutable
2 | for i in var.iter_mut() {
| ^^^ cannot borrow as mutable
error: aborting due to previous error
borrowck: consolidate `mut` suggestions
This converts all of borrowck's `mut` suggestions to a new
`mc::ImmutabilityBlame` API instead of the current mix of various hacks.
Fixesrust-lang#35937.
Fixesrust-lang#40823.
Fixesrust-lang#40859.
cc @estebank
r? @pnkfelix
Gives error:
It suggests the type
&mut [&mut mut u8]
but that is not a valid Rust type. Happens in stable, beta, nightly.The text was updated successfully, but these errors were encountered: