Skip to content
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

Unparseable type suggested in error message #40859

Closed
mulkieran opened this issue Mar 27, 2017 · 2 comments
Closed

Unparseable type suggested in error message #40859

mulkieran opened this issue Mar 27, 2017 · 2 comments

Comments

@mulkieran
Copy link

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.

@nagisa
Copy link
Member

nagisa commented Mar 27, 2017

Duplicate of #40823.

@cuviper
Copy link
Member

cuviper commented Mar 28, 2017

#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

frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 29, 2017
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.

Fixes rust-lang#35937.
Fixes rust-lang#40823.
Fixes rust-lang#40859.

cc @estebank
r? @pnkfelix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants