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

Autoderef chooses deref() when deref_mut() is needed for ref mut pattern #15609

Closed
kmcallister opened this issue Jul 11, 2014 · 6 comments
Closed
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@kmcallister
Copy link
Contributor

use std::cell::RefCell;

struct S {
    node: E,
}

enum E {
    Foo(uint),
    Bar,
}

fn main() {
    let x = RefCell::new(S { node: Foo(0) });

    let mut b = x.borrow_mut();
    match b.node {
        Foo(ref mut n) => *n += 1,
        _ => (),
    }
}
$ rustc -v
rustc 0.11.0 (49bc17bfdd7143909aede81652d7d624cecd8a70 2014-07-07 17:16:34 +0000)
$ rustc foo.rs
foo.rs:17:13: 17:22 error: cannot borrow immutable anonymous field as mutable
foo.rs:17         Foo(ref mut n) => *n += 1,
                      ^~~~~~~~~

Changing to match b.deref_mut().node fixes the error.

@huonw
Copy link
Member

huonw commented Jul 23, 2014

This is possibly related to #12825.

@eddyb
Copy link
Member

eddyb commented Jul 26, 2014

Ah, I completely missed the fact that expressions matched over are lvalues that could require mutability (so they should always prefer DerefMut under the current scheme).

@japaric
Copy link
Member

japaric commented Nov 7, 2014

Triage: Still occurs with:

rustc 0.13.0-dev (97a57ec90 2014-11-07 11:31:25 +0000)

#12825 has been closed as fixed.

@steveklabnik
Copy link
Member

Triage: still happens

@SimonSapin
Copy link
Contributor

Still an issue in rustc 1.0.0-nightly (083b8a4 2015-04-05) (built 2015-04-05)

Kimundi added a commit to Kimundi/rust that referenced this issue Jun 9, 2015
bors added a commit that referenced this issue Jun 10, 2015
@bluss
Copy link
Member

bluss commented Jun 27, 2015

For those who wonder: The fix will be in Rust 1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

7 participants