Upfront I just want to say that I don't know how to make minimal (non)compilable example out of this, but let me explain the situation (last two lines are important, other code is provided as a context):
pub struct Panel {
tree_view_name: &'static str,
list_view: gtk::ColumnView,
bread_crumb: gtk::FlowBox,
current_path: PathBuf,
model: gtk::DirectoryList,
}
impl Panel {
fn set_file_info(&mut self, file_info: &gio::FileInfo) {...}
}
...inside some fn:
let mut rc_panel = Rc::new(RefCell::new(panel));
let mut rc_panel_clone = rc_panel.clone();
rc_panel
.borrow()
.list_view
.connect_activate(move |col_view, inx| {
println!("ColumnViewClicked:{},{}", col_view, inx);
let selection_model: gtk::SingleSelection =
col_view.model().unwrap().downcast().unwrap();
let sort_model = glib::object::Cast::dynamic_cast::<
gtk::SortListModel,
>(selection_model.model())
.unwrap();
let directory_list =
glib::object::Cast::dynamic_cast::<gtk::DirectoryList>(
sort_model.model().unwrap(),
)
.unwrap();
let file_info =
glib::object::Cast::dynamic_cast::<gio::FileInfo>(
selection_model.selected_item().unwrap(),
)
.unwrap();
let file_name = file_info.name();
1) let mut w = rc_panel_clone.borrow_mut();//If I only have this line I get proper error from compiler
2) w.set_file_info(&file_info);//if I add this line, I get incorrect error from compiler + the previous error disappears
});
The error with line 1) only:
error[E0596]: cannot borrow `rc_panel_clone` as mutable, as it is a captured variable in a `Fn` closure
--> src/main_application_window.rs:228:29
|
228 | let mut w = rc_panel_clone.borrow_mut();
| ^^^^^^^^^^^^^^ cannot borrow as mutable
The error with line 1) and 2):
w.set_file_info(&file_info);
| ^^^^^^^^^^^^^ method not found in `&mut Rc<RefCell<Panel>>`
So basically what happens is this:
If the line marked 1) is present without the line marked 2) we get proper compiler error.
If we add line marked 2) the compiler error is misleading telling us that the method doesn't exist in a type (which is not true), and also we don't get error about line number one, which is doubly confusing, because we are being told by the compiler that everything is fine with line 1) only the line 2) is problematic.