-
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
Error with autoderef on newtype wrapping FnMut #26186
Labels
Comments
I just ran into this problem too, here's a shorter example: use std::cell::RefCell;
use std::rc::Rc;
struct Foo(Rc<RefCell<FnMut()>>);
fn main() {
let a = Foo(Rc::new(RefCell::new(||{
println!("Hello, world!");
})));
a.0.borrow_mut()();
} And playpen link: https://is.gd/KQJ9ij |
Further reduced: use std::cell::RefCell;
use std::rc::Rc;
fn main() {
let a: Rc<RefCell<FnMut()>> = Rc::new(RefCell::new(||{}));
a.borrow_mut()();
} |
Another example from Stack Overflow: use std::ops::{Deref, DerefMut};
struct Foo;
impl Deref for Foo {
type Target = FnMut() + 'static;
fn deref(&self) -> &Self::Target {
unimplemented!()
}
}
impl DerefMut for Foo {
fn deref_mut(&mut self) -> &mut Self::Target {
unimplemented!()
}
}
fn main() {
let mut t = Foo;
t();
} |
And again experienced on Stack Overflow |
Just got this today, with what is almost identical to Mark-Simulacrum's reduced version. |
I've also run into this issue, with this example: use std::sync::Mutex;
struct FunctionIcon {
get_icon: Mutex<Box<dyn FnMut() -> u32>>,
}
impl FunctionIcon {
fn get_icon(&self) -> impl '_ + std::ops::DerefMut<Target=Box<dyn FnMut() -> u32>> {
self.get_icon.lock().unwrap()
}
fn load_icon(&self) {
let mut get_icon = self.get_icon();
let rgba_icon = (*get_icon)();
}
} and this error:
|
This error seems resolved. Examples above all work on stable. |
Patrick-Poitras
added a commit
to Patrick-Poitras/rust
that referenced
this issue
Dec 27, 2021
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Dec 27, 2021
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#90586 (Relax priv-in-pub lint on generic bounds and where clauses of trait impls.) - rust-lang#92112 (Fix the error of checking `base_expr` twice in type_changing_struct_update) - rust-lang#92147 (rustc_builtin_macros: make asm mod public for rustfmt) - rust-lang#92161 (resolve: Minor miscellaneous cleanups from rust-lang#89059) - rust-lang#92264 (Remove `maybe_uninit_extra` feature from Vec docs) - rust-lang#92303 (Add test cases for issue rust-lang#26186) - rust-lang#92307 (Fix minor typos) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testcase:
Yields:
Auto-deref should be picking DerefMut here, not Deref.
The text was updated successfully, but these errors were encountered: