Skip to content

Commit 052eab5

Browse files
authored
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.
2 parents 4d8ba21 + fe80124 commit 052eab5

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Diff for: src/test/ui/issues/issue-26186.rs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// check-pass
2+
use std::sync::Mutex;
3+
use std::cell::RefCell;
4+
use std::rc::Rc;
5+
use std::ops::*;
6+
7+
//eefriedman example
8+
struct S<'a, T:FnMut() + 'static + ?Sized>(&'a mut T);
9+
impl<'a, T:?Sized + FnMut() + 'static> DerefMut for S<'a, T> {
10+
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
11+
}
12+
impl<'a, T:?Sized + FnMut() + 'static> Deref for S<'a, T> {
13+
type Target = dyn FnMut() + 'a;
14+
fn deref(&self) -> &Self::Target { &self.0 }
15+
}
16+
17+
//Ossipal example
18+
struct FunctionIcon {
19+
get_icon: Mutex<Box<dyn FnMut() -> u32>>,
20+
}
21+
22+
impl FunctionIcon {
23+
fn get_icon(&self) -> impl '_ + std::ops::DerefMut<Target=Box<dyn FnMut() -> u32>> {
24+
self.get_icon.lock().unwrap()
25+
}
26+
27+
fn load_icon(&self) {
28+
let mut get_icon = self.get_icon();
29+
let _rgba_icon = (*get_icon)();
30+
}
31+
}
32+
33+
//shepmaster example
34+
struct Foo;
35+
36+
impl Deref for Foo {
37+
type Target = dyn FnMut() + 'static;
38+
fn deref(&self) -> &Self::Target {
39+
unimplemented!()
40+
}
41+
}
42+
43+
impl DerefMut for Foo {
44+
fn deref_mut(&mut self) -> &mut Self::Target {
45+
unimplemented!()
46+
}
47+
}
48+
49+
fn main() {
50+
//eefriedman example
51+
let mut f = ||{};
52+
let mut s = S(&mut f);
53+
s();
54+
55+
//Diggsey/Mark-Simulacrum example
56+
let a: Rc<RefCell<dyn FnMut()>> = Rc::new(RefCell::new(||{}));
57+
a.borrow_mut()();
58+
59+
//shepmaster example
60+
let mut t = Foo;
61+
t();
62+
}

0 commit comments

Comments
 (0)