]> git.lizzy.rs Git - rust.git/commitdiff
new tests for new fn arg passing code
authorRalf Jung <post@ralfj.de>
Mon, 27 Aug 2018 15:08:42 +0000 (17:08 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 30 Aug 2018 08:42:18 +0000 (10:42 +0200)
tests/compile-fail/cast_fn_ptr.rs
tests/compile-fail/cast_fn_ptr2.rs
tests/compile-fail/cast_fn_ptr3.rs [new file with mode: 0644]
tests/compile-fail/cast_fn_ptr4.rs [new file with mode: 0644]
tests/run-pass/non_capture_closure_to_fn_ptr.rs

index 0a8f5ef752a6d48fe1b555a38e1958dd3c0c7c95..0add977bf97b417af68ce2957ec7d893dd74d104 100644 (file)
@@ -5,6 +5,5 @@ fn f() {}
         std::mem::transmute::<fn(), fn(i32)>(f)
     };
 
-    g(42) //~ ERROR constant evaluation error
-    //~^ NOTE tried to call a function with sig fn() through a function pointer of type fn(i32)
+    g(42) //~ ERROR tried to call a function with incorrect number of arguments
 }
index cb80521c60eeb8cbc88c9d19622382914b38dd3d..5af527016fb6fecd3bf4253fa6cfd453f744ccb1 100644 (file)
@@ -5,6 +5,5 @@ fn f(_ : (i32,i32)) {}
         std::mem::transmute::<fn((i32,i32)), fn(i32)>(f)
     };
 
-    g(42) //~ ERROR constant evaluation error
-    //~^ NOTE tried to call a function with sig fn((i32, i32)) through a function pointer of type fn(i32)
+    g(42) //~ ERROR tried to call a function with argument of type (i32, i32) passing data of type i32
 }
diff --git a/tests/compile-fail/cast_fn_ptr3.rs b/tests/compile-fail/cast_fn_ptr3.rs
new file mode 100644 (file)
index 0000000..29507e7
--- /dev/null
@@ -0,0 +1,10 @@
+fn main() {
+    fn f(_ : (i32,i32)) {}
+
+    let g = unsafe {
+        std::mem::transmute::<fn((i32,i32)), fn()>(f)
+    };
+
+    g() //~ ERROR tried to call a function with incorrect number of arguments
+}
+
diff --git a/tests/compile-fail/cast_fn_ptr4.rs b/tests/compile-fail/cast_fn_ptr4.rs
new file mode 100644 (file)
index 0000000..f9a2cf9
--- /dev/null
@@ -0,0 +1,9 @@
+fn main() {
+    fn f(_ : *const [i32]) {}
+
+    let g = unsafe {
+        std::mem::transmute::<fn(*const [i32]), fn(*const i32)>(f)
+    };
+
+    g(&42 as *const i32) //~ ERROR tried to call a function with argument of type *const [i32] passing data of type *const i32
+}
index c9daff9c9f46931c2fe3d718f0add767c0b5db84..d48c4df45944a12a6ddae736d1ccce87b4f4f9e8 100644 (file)
@@ -4,6 +4,9 @@
 #[allow(const_err)]
 static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) };
 
+// use to first make the closure FnOnce() before making it fn()
+fn magic<F: FnOnce()>(f: F) -> F { f }
+
 fn main() {
     FOO();
     BAR(44, 45);
@@ -11,4 +14,7 @@ fn main() {
     unsafe { bar(46, 47) };
     let boo: &Fn(i32, i32) = &BAR;
     boo(48, 49);
+
+    let f = magic(||{}) as fn();
+    f();
 }