summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-16739.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /tests/ui/issues/issue-16739.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/issues/issue-16739.rs')
-rw-r--r--tests/ui/issues/issue-16739.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui/issues/issue-16739.rs b/tests/ui/issues/issue-16739.rs
new file mode 100644
index 000000000..b21ea4bcd
--- /dev/null
+++ b/tests/ui/issues/issue-16739.rs
@@ -0,0 +1,45 @@
+// run-pass
+#![feature(unboxed_closures, fn_traits)]
+
+// Test that unboxing shim for calling rust-call ABI methods through a
+// trait box works and does not cause an ICE.
+
+struct Foo { foo: u32 }
+
+impl FnMut<()> for Foo {
+ extern "rust-call" fn call_mut(&mut self, _: ()) -> u32 { self.foo }
+}
+
+impl FnOnce<()> for Foo {
+ type Output = u32;
+ extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
+}
+
+impl FnMut<(u32,)> for Foo {
+ extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
+}
+
+impl FnOnce<(u32,)> for Foo {
+ type Output = u32;
+ extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
+}
+
+impl FnMut<(u32,u32)> for Foo {
+ extern "rust-call" fn call_mut(&mut self, (x, y): (u32, u32)) -> u32 { self.foo + x + y }
+}
+
+impl FnOnce<(u32,u32)> for Foo {
+ type Output = u32;
+ extern "rust-call" fn call_once(mut self, args: (u32,u32)) -> u32 { self.call_mut(args) }
+}
+
+fn main() {
+ let mut f = Box::new(Foo { foo: 42 }) as Box<dyn FnMut() -> u32>;
+ assert_eq!(f.call_mut(()), 42);
+
+ let mut f = Box::new(Foo { foo: 40 }) as Box<dyn FnMut(u32) -> u32>;
+ assert_eq!(f.call_mut((2,)), 42);
+
+ let mut f = Box::new(Foo { foo: 40 }) as Box<dyn FnMut(u32, u32) -> u32>;
+ assert_eq!(f.call_mut((1, 1)), 42);
+}