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

1.17 nightly Compiler suggests wrong syntax mut mut var #40823

Closed
yasammez opened this issue Mar 25, 2017 · 3 comments
Closed

1.17 nightly Compiler suggests wrong syntax mut mut var #40823

yasammez opened this issue Mar 25, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@yasammez
Copy link

When trying to compile

fn main() {
    let mut buf = &[1, 2, 3, 4];
    let mut dst = &[0, 0, 0, 0];
    for (x, y) in buf.iter_mut().zip(dst) {
        *y = *x
    }
}

the compiler rustc 1.17.0-nightly (3da4023 2017-03-24) throws an error together with a helpful suggestion

error: cannot borrow immutable borrowed content `*buf` as mutable
 --> <anon>:4:19
  |
2 |     let mut buf = &[1, 2, 3, 4];
  |         ------- consider changing this to `mut mut buf`
3 |     let mut dst = &[0, 0, 0, 0];
4 |     for (x, y) in buf.iter_mut().zip(dst) {
  |                   ^^^ cannot borrow as mutable

Here, the mut mut buf is obviously very very wrong. The stable and beta compilers don't suffer from this issue (they just provide no „consider …“ message at all).

@steveklabnik steveklabnik added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 25, 2017
@hanna-kruppe
Copy link
Contributor

hanna-kruppe commented Mar 25, 2017

I think this was introduced in #40445

arielb1 added a commit to arielb1/rust that referenced this issue Mar 26, 2017
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.
@therealprof
Copy link
Contributor

therealprof commented Mar 28, 2017

Also other incorrect mut changes are suggested:

error: cannot borrow immutable borrowed content `*parent` as mutable
   --> src/parser.rs:175:29
    |
174 |                         if let Some (&Node::RegularNode(ref parent)) = nodestack.last() {
    |                                                         ---------- consider changing this to `mut ref parent`
175 |                             parent.add_child (Node::RegularNode(node));
    |                             ^^^^^^ cannot borrow as mutable

which is also not valid and should be ref mut instead.

This happens with:

rustc 1.17.0-nightly (134c4a0 2017-03-20)

@cuviper
Copy link
Member

cuviper commented Mar 28, 2017

#40859 shows a similar bad suggestion even on stable. So maybe that problem has existed for a while, and the cases here just weren't making suggestions at all until recent nightlies.

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
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants