Skip to content

Commit

Permalink
Unrolled build for rust-lang#123976
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rust-timer committed Apr 21, 2024
2 parents dbce3b4 + 89117f8 commit 2ec6bbd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///
Expand All @@ -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);
/// }
/// ```
///
Expand Down

0 comments on commit 2ec6bbd

Please sign in to comment.