about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-04-20 21:45:35 +0100
committerGitHub <noreply@github.com>2024-04-20 21:45:35 +0100
commita73aabfa92404ee26cdc2db8dea782e20213be29 (patch)
treed201dce9a47fba23370d18521534c71d64413888
parentccd9880769304d41fefcdb028c1df646603bcc4e (diff)
parent89117f85e3f22d7e240a6237be100d7697ae2435 (diff)
downloadrust-a73aabfa92404ee26cdc2db8dea782e20213be29.tar.gz
rust-a73aabfa92404ee26cdc2db8dea782e20213be29.zip
Rollup merge of #123976 - ChrisDenton:no-libc-in-std-doc-tests, r=Mark-Simulacrum
Use fake libc in core test

The war on libc continues.

Some platforms may not need to link to the libc crate (and it's possible some may not even have a libc), therefore we shouldn't require it for tests. This creates dummy `malloc` and `free` implementations for use in the pointer docs, but, keeps the public documentation looking the same as before.
-rw-r--r--library/core/src/primitive_docs.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs
index e8e23f2a7ec..bda1ee6f457 100644
--- a/library/core/src/primitive_docs.rs
+++ b/library/core/src/primitive_docs.rs
@@ -537,7 +537,11 @@ impl () {}
 /// ## 4. Get it from C.
 ///
 /// ```
-/// # #![feature(rustc_private)]
+/// # mod libc {
+/// # pub unsafe fn malloc(_size: usize) -> *mut core::ffi::c_void { core::ptr::NonNull::dangling().as_ptr() }
+/// # pub unsafe fn free(_ptr: *mut core::ffi::c_void) {}
+/// # }
+/// # #[cfg(any())]
 /// #[allow(unused_extern_crates)]
 /// extern crate libc;
 ///
@@ -548,7 +552,7 @@ impl () {}
 ///     if my_num.is_null() {
 ///         panic!("failed to allocate memory");
 ///     }
-///     libc::free(my_num as *mut libc::c_void);
+///     libc::free(my_num as *mut core::ffi::c_void);
 /// }
 /// ```
 ///