Open
Description
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d77c477c52217e25856306f659a26e42
use std::cell::RefCell;
fn foo(cell: &RefCell<Option<Vec<()>>>) {
cell.borrow_mut().unwrap().pop().unwrap();
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[[E0507]](https://doc.rust-lang.org/nightly/error-index.html#E0507): cannot move out of dereference of `RefMut<'_, Option<Vec<()>>>`
[--> src/lib.rs:4:5
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d77c477c52217e25856306f659a26e42#) |
4 | cell.borrow_mut().unwrap().pop().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `Option<Vec<()>>`, which does not implement the `Copy` trait
|
help: consider borrowing the `Option`'s content
|
4 | cell.borrow_mut().unwrap().as_ref().pop().unwrap();
| +++++++++
For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` due to previous error
There are two separate issues here:
- The suggested
as_ref
is in the wrong place and should be after theborrow_mut()
, not after theunwrap()
. - The suggested
as_ref
really should be anas_mut