]> git.lizzy.rs Git - rust.git/blobdiff - library/core/tests/ptr.rs
Don't declare test_variadic_fnptr with two conflicting signatures
[rust.git] / library / core / tests / ptr.rs
index 9c65871ac4b4cfc9fa4190b76fbf9e01e8cf9b00..84d3ae03ef4a19d952c550aa4809635d5af2e98f 100644 (file)
@@ -289,16 +289,18 @@ fn test_const_nonnull_new() {
 }
 
 #[test]
-#[allow(warnings)]
-// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
-// ABI, or even point to an actual executable code, because the function itself is never invoked.
-#[no_mangle]
+#[cfg(any(unix, windows))] // printf may not be available on other platforms
+#[allow(deprecated)] // For SipHasher
 pub fn test_variadic_fnptr() {
+    use core::ffi;
     use core::hash::{Hash, SipHasher};
     extern "C" {
-        fn test_variadic_fnptr(_: u64, ...) -> f64;
+        // This needs to use the correct function signature even though it isn't called as some
+        // codegen backends make it UB to declare a function with multiple conflicting signatures
+        // (like LLVM) while others straight up return an error (like Cranelift).
+        fn printf(_: *const ffi::c_char, ...) -> ffi::c_int;
     }
-    let p: unsafe extern "C" fn(u64, ...) -> f64 = test_variadic_fnptr;
+    let p: unsafe extern "C" fn(*const ffi::c_char, ...) -> ffi::c_int = printf;
     let q = p.clone();
     assert_eq!(p, q);
     assert!(!(p < q));
@@ -550,7 +552,7 @@ fn dyn_metadata() {
     assert_eq!(meta.align_of(), std::mem::align_of::<Something>());
     assert_eq!(meta.layout(), std::alloc::Layout::new::<Something>());
 
-    assert!(format!("{:?}", meta).starts_with("DynMetadata(0x"));
+    assert!(format!("{meta:?}").starts_with("DynMetadata(0x"));
 }
 
 #[test]