Skip to content

Commit a73aabf

Browse files
authored
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.
2 parents ccd9880 + 89117f8 commit a73aabf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/core/src/primitive_docs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,11 @@ impl () {}
537537
/// ## 4. Get it from C.
538538
///
539539
/// ```
540-
/// # #![feature(rustc_private)]
540+
/// # mod libc {
541+
/// # pub unsafe fn malloc(_size: usize) -> *mut core::ffi::c_void { core::ptr::NonNull::dangling().as_ptr() }
542+
/// # pub unsafe fn free(_ptr: *mut core::ffi::c_void) {}
543+
/// # }
544+
/// # #[cfg(any())]
541545
/// #[allow(unused_extern_crates)]
542546
/// extern crate libc;
543547
///
@@ -548,7 +552,7 @@ impl () {}
548552
/// if my_num.is_null() {
549553
/// panic!("failed to allocate memory");
550554
/// }
551-
/// libc::free(my_num as *mut libc::c_void);
555+
/// libc::free(my_num as *mut core::ffi::c_void);
552556
/// }
553557
/// ```
554558
///

0 commit comments

Comments
 (0)