Skip to content

Commit 5a86d4a

Browse files
authored
Rollup merge of rust-lang#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 5b55d87 + 9265a3e commit 5a86d4a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/src/primitive_docs.rs

+6-2
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)