Skip to content

Commit a4e7f8f

Browse files
Mark extern blocks as unsafe
1 parent 04bbc83 commit a4e7f8f

File tree

66 files changed

+132
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+132
-132
lines changed

library/alloc/src/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use core::hint;
1010
#[cfg(not(test))]
1111
use core::ptr::{self, NonNull};
1212

13-
extern "Rust" {
13+
unsafe extern "Rust" {
1414
// These are the magic symbols to call the global allocator. rustc generates
1515
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
1616
// (the code expanding that attribute macro generates those functions), or to call
@@ -355,7 +355,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
355355
// # Allocation error handler
356356

357357
#[cfg(not(no_global_oom_handling))]
358-
extern "Rust" {
358+
unsafe extern "Rust" {
359359
// This is the magic symbol to call the global alloc error handler. rustc generates
360360
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
361361
// default implementations below (`__rdl_oom`) otherwise.
@@ -426,7 +426,7 @@ pub mod __alloc_error_handler {
426426
// `#[alloc_error_handler]`.
427427
#[rustc_std_internal_symbol]
428428
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
429-
extern "Rust" {
429+
unsafe extern "Rust" {
430430
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
431431
// Its value depends on the -Zoom={panic,abort} compiler option.
432432
static __rust_alloc_error_handler_should_panic: u8;

library/alloc/src/ffi/c_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl CString {
397397
// information about the size of the allocation is correct on Rust's
398398
// side.
399399
unsafe {
400-
extern "C" {
400+
unsafe extern "C" {
401401
/// Provided by libc or compiler_builtins.
402402
fn strlen(s: *const c_char) -> usize;
403403
}

library/core/src/ffi/c_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ const unsafe fn strlen(ptr: *const c_char) -> usize {
731731

732732
len
733733
} else {
734-
extern "C" {
734+
unsafe extern "C" {
735735
/// Provided by libc or compiler_builtins.
736736
fn strlen(s: *const c_char) -> usize;
737737
}

library/core/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ impl fmt::Debug for c_void {
9090
cfg(not(target_feature = "crt-static"))
9191
)]
9292
#[link(name = "/defaultlib:libcmt", modifiers = "+verbatim", cfg(target_feature = "crt-static"))]
93-
extern "C" {}
93+
unsafe extern "C" {}

library/core/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4855,7 +4855,7 @@ pub const unsafe fn copysignf128(_x: f128, _y: f128) -> f128 {
48554855
#[cfg(miri)]
48564856
#[rustc_allow_const_fn_unstable(const_eval_select)]
48574857
pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize) {
4858-
extern "Rust" {
4858+
unsafe extern "Rust" {
48594859
/// Miri-provided extern function to promise that a given pointer is properly aligned for
48604860
/// "symbolic" alignment checks. Will fail if the pointer is not actually aligned or `align` is
48614861
/// not a power of two. Has no effect when alignment checks are concrete (which is the default).

library/core/src/panicking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
5959

6060
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
6161
// that gets resolved to the `#[panic_handler]` function.
62-
extern "Rust" {
62+
unsafe extern "Rust" {
6363
#[lang = "panic_impl"]
6464
fn panic_impl(pi: &PanicInfo<'_>) -> !;
6565
}
@@ -100,7 +100,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
100100

101101
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
102102
// that gets resolved to the `#[panic_handler]` function.
103-
extern "Rust" {
103+
unsafe extern "Rust" {
104104
#[lang = "panic_impl"]
105105
fn panic_impl(pi: &PanicInfo<'_>) -> !;
106106
}

library/core/src/ptr/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub struct DynMetadata<Dyn: ?Sized> {
155155
_phantom: crate::marker::PhantomData<Dyn>,
156156
}
157157

158-
extern "C" {
158+
unsafe extern "C" {
159159
/// Opaque type for accessing vtables.
160160
///
161161
/// Private implementation detail of `DynMetadata::size_of` etc.

library/coretests/tests/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ fn offset_of_dst() {
648648
z: dyn Trait,
649649
}
650650

651-
extern "C" {
651+
unsafe extern "C" {
652652
type Extern;
653653
}
654654

library/coretests/tests/num/flt2dec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn ldexp_f32(a: f32, b: i32) -> f32 {
8080
}
8181

8282
fn ldexp_f64(a: f64, b: i32) -> f64 {
83-
extern "C" {
83+
unsafe extern "C" {
8484
fn ldexp(x: f64, n: i32) -> f64;
8585
}
8686
// SAFETY: assuming a correct `ldexp` has been supplied, the given arguments cannot possibly

library/coretests/tests/ptr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn test_is_null() {
9797
let nmi: *mut dyn ToString = null_mut::<isize>();
9898
assert!(nmi.is_null());
9999

100-
extern "C" {
100+
unsafe extern "C" {
101101
type Extern;
102102
}
103103
let ec: *const Extern = null::<Extern>();
@@ -308,7 +308,7 @@ fn test_const_nonnull_new() {
308308
pub fn test_variadic_fnptr() {
309309
use core::ffi;
310310
use core::hash::{Hash, SipHasher};
311-
extern "C" {
311+
unsafe extern "C" {
312312
// This needs to use the correct function signature even though it isn't called as some
313313
// codegen backends make it UB to declare a function with multiple conflicting signatures
314314
// (like LLVM) while others straight up return an error (like Cranelift).
@@ -506,7 +506,7 @@ fn offset_from() {
506506
fn ptr_metadata() {
507507
struct Unit;
508508
struct Pair<A, B: ?Sized>(A, B);
509-
extern "C" {
509+
unsafe extern "C" {
510510
type Extern;
511511
}
512512
let () = metadata(&());

0 commit comments

Comments
 (0)