-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Cannot call a Vec<Box<Fn()>> without explicit dereferencing #36786
Comments
The fact that this works for arrays, but not Vec suggests that it's probably related to associated types. It's possible that wherever the coercion from |
Aatch
added a commit
to Aatch/rust
that referenced
this issue
Sep 29, 2016
If the callee type is an associated type, then it needs to be normalized before trying to deref it. This matches the behaviour of `check_method_call` for autoderef behaviour in calls. Fixes rust-lang#36786
bors
added a commit
that referenced
this issue
Sep 30, 2016
Resolve the callee type in check_call before autoderef If the callee type is an associated type, then it needs to be normalized before trying to deref it. This matches the behaviour of `check_method_call` for autoderef behaviour in calls. Fixes #36786
jakllsch
pushed a commit
to jakllsch/rust
that referenced
this issue
Oct 1, 2016
If the callee type is an associated type, then it needs to be normalized before trying to deref it. This matches the behaviour of `check_method_call` for autoderef behaviour in calls. Fixes rust-lang#36786
This doesn't seem to be fully resolved: use std::sync::Mutex;
pub struct Foo(Mutex<Box<FnMut()>>);
impl Foo {
pub fn foo(&self) {
// self.0.lock().unwrap()(); // cannot borrow immutable `Box` content as mutable
// (*self.0.lock().unwrap())(); // cannot borrow immutable `Box` content as mutable
// (&mut self.0.lock().unwrap())(); // cannot borrow immutable `Box` content as mutable
(&mut *self.0.lock().unwrap())();
}
}
fn main() {
Foo(Mutex::new(Box::new(|| println!("called")))).foo()
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code works:
As does placing it in an array:
However, using a
Vec
fails:Instead, it must be explicitly dereferenced:
It's even more annoying for
Vec<Box<FnMut()>>
:The text was updated successfully, but these errors were encountered: