about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-27 21:42:29 +0100
committerGitHub <noreply@github.com>2021-12-27 21:42:29 +0100
commit052eab54eccbd116c7cdfc631136bbc5a2bb0426 (patch)
treef0cfcab7bf8e26799f34d246a78a1d71cc260391 /src
parent4d8ba2193ffbbbb5f592ae70793cfea6e21d9c5a (diff)
parentfe8012409858a137556af7870a6d4344f52cd091 (diff)
downloadrust-052eab54eccbd116c7cdfc631136bbc5a2bb0426.tar.gz
rust-052eab54eccbd116c7cdfc631136bbc5a2bb0426.zip
Rollup merge of #92303 - Patrick-Poitras:issue-26186, r=jackh726
Add test cases for issue #26186

Closes #26186

It seems that issue #26186 has been solved at some point since the issue has been last updated. I've merged together the examples that were supplied by `@Osspial,` `@Mark-Simulacrum,` `@Diggsey,` `@eefriedman` and `@shepmaster,` so that we can add this to the testing suite and prevent these issues from re-occurring.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/issues/issue-26186.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-26186.rs b/src/test/ui/issues/issue-26186.rs
new file mode 100644
index 00000000000..f93869352ea
--- /dev/null
+++ b/src/test/ui/issues/issue-26186.rs
@@ -0,0 +1,62 @@
+// check-pass
+use std::sync::Mutex;
+use std::cell::RefCell;
+use std::rc::Rc;
+use std::ops::*;
+
+//eefriedman example
+struct S<'a, T:FnMut() + 'static + ?Sized>(&'a mut T);
+impl<'a, T:?Sized + FnMut() + 'static> DerefMut for S<'a, T> {
+    fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
+}
+impl<'a, T:?Sized + FnMut() + 'static> Deref for S<'a, T> {
+    type Target = dyn FnMut() + 'a;
+    fn deref(&self) -> &Self::Target { &self.0 }
+}
+
+//Ossipal example
+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)();
+    }
+}
+
+//shepmaster example
+struct Foo;
+
+impl Deref for Foo {
+    type Target = dyn FnMut() + 'static;
+    fn deref(&self) -> &Self::Target {
+        unimplemented!()
+    }
+}
+
+impl DerefMut for Foo {
+    fn deref_mut(&mut self) -> &mut Self::Target {
+        unimplemented!()
+    }
+}
+
+fn main() {
+    //eefriedman example
+    let mut f = ||{};
+    let mut s = S(&mut f);
+    s();
+
+    //Diggsey/Mark-Simulacrum example
+    let a: Rc<RefCell<dyn FnMut()>> = Rc::new(RefCell::new(||{}));
+    a.borrow_mut()();
+
+    //shepmaster example
+    let mut t = Foo;
+    t();
+}