Skip to content

Commit a255e30

Browse files
committed
Add unsafe to extern build scripts in Cargo Book
1 parent 340d123 commit a255e30

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/doc/src/reference/build-script-examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void hello() {
252252
// Note the lack of the `#[link]` attribute. We’re delegating the responsibility
253253
// of selecting what to link over to the build script rather than hard-coding
254254
// it in the source file.
255-
extern { fn hello(); }
255+
unsafe extern { fn hello(); }
256256
257257
fn main() {
258258
unsafe { hello(); }
@@ -327,7 +327,7 @@ Let's round out the example with a basic FFI binding:
327327
328328
use std::os::raw::{c_uint, c_ulong};
329329
330-
extern "C" {
330+
unsafe extern "C" {
331331
pub fn crc32(crc: c_ulong, buf: *const u8, len: c_uint) -> c_ulong;
332332
}
333333

src/doc/src/reference/semver.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ pub struct SpecificLayout {
766766
// Example usage that will break.
767767
use updated_crate::SpecificLayout;
768768
769-
extern "C" {
769+
unsafe extern "C" {
770770
// This C function is assuming a specific layout defined in a C header.
771771
fn c_fn_get_b(x: &SpecificLayout) -> u32;
772772
}
@@ -820,7 +820,7 @@ pub struct SpecificLayout {
820820
// Example usage that will break.
821821
use updated_crate::SpecificLayout;
822822
823-
extern "C" {
823+
unsafe extern "C" {
824824
// This C function is assuming a specific layout defined in a C header.
825825
fn c_fn_get_b(x: &SpecificLayout) -> u32; // Error: is not FFI-safe
826826
}
@@ -941,7 +941,7 @@ pub struct Transparent<T>(T);
941941
#![deny(improper_ctypes)]
942942
use updated_crate::Transparent;
943943
944-
extern "C" {
944+
unsafe extern "C" {
945945
fn c_fn() -> Transparent<f64>; // Error: is not FFI-safe
946946
}
947947

0 commit comments

Comments
 (0)