Closed
Description
The following code
struct A {
x: Box<dyn FnMut()>
}
fn test(a: &std::sync::Mutex<A>) {
let mut guard = a.lock().unwrap();
// This works: (&mut guard.x)();
(guard.x)();
}
produces the following error
error[E0596]: cannot borrow data in a dereference of `std::sync::MutexGuard<'_, A>` as mutable
--> src/lib.rs:7:5
|
7 | (guard.x)();
| ^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::sync::MutexGuard<'_, A>`
The help message is especially confusing, since DerefMut
is clearly implemeneted for std::sync::MutexGuard<'_, A>
. This might be related to #68590.