-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Can turn immutable into mut with ref mut
#52240
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
Labels
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Comments
Fixed by Off: I wonder why we can't ship nll yet. It would solve so many issues right now, because of the match ergonomics sigh |
Yes #52232 correctly fixed this issue. $ rustup-toolchain-install-master 4700e1188f66fdb4086b7593416b678b8fe935f4
downloading <https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rustc-builds/4700e1188f66fdb4086b7593416b678b8fe935f4/rustc-nightly-x86_64-apple-darwin.tar.xz>...
completed
downloading <https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rustc-builds/4700e1188f66fdb4086b7593416b678b8fe935f4/rust-std-nightly-x86_64-apple-darwin.tar.xz>...
completed
toolchain `4700e1188f66fdb4086b7593416b678b8fe935f4` is successfully installed!
$ rustc +4700e1188f66fdb4086b7593416b678b8fe935f4 1.rs
error[E0596]: cannot borrow field of immutable binding as mutable
--> 1.rs:7:24
|
7 | if let (Some(Foo::Bar(ref mut val)), _) = (&arr.get(0), 0) {
| ^^^^^^^^^^^ cannot mutably borrow field of immutable binding
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`. |
memoryruins
added a commit
to memoryruins/rust
that referenced
this issue
Oct 12, 2018
memoryruins
added a commit
to memoryruins/rust
that referenced
this issue
Oct 12, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
This lets you get a mutable reference to an immutable value under a specific case.
Code:
From what I can tell, the tuple and at least two depths of Enums are necessary, along with an
&
on the right side. There's probably other variations, but that seems to work well enough.Expected output would be a compile error, instead output is
9001
This works on both stable
rustc 1.27.1 (5f2b325f6 2018-07-07)
and nightlyrustc 1.29.0-nightly (e5f6498d3 2018-07-10)
The text was updated successfully, but these errors were encountered: