Skip to content

Commit 72f0205

Browse files
Rollup merge of rust-lang#136705 - compiler-errors:edition-library, r=jhpratt
Some miscellaneous edition-related library tweaks Some library edition tweaks that can be done separately from upgrading the whole standard library to edition 2024 (which is blocked on getting the submodules upgraded, for example)
2 parents f471ce3 + 4312d7b commit 72f0205

File tree

73 files changed

+156
-152
lines changed

Some content is hidden

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

73 files changed

+156
-152
lines changed

Diff for: library/alloc/src/alloc.rs

+3-3
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;

Diff for: library/alloc/src/collections/btree/merge_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<I: Iterator> MergeIterInner<I> {
7474
b_next = self.b.next();
7575
}
7676
}
77-
if let (Some(ref a1), Some(ref b1)) = (&a_next, &b_next) {
77+
if let (Some(a1), Some(b1)) = (&a_next, &b_next) {
7878
match cmp(a1, b1) {
7979
Ordering::Less => self.peeked = b_next.take().map(Peeked::B),
8080
Ordering::Greater => self.peeked = a_next.take().map(Peeked::A),

Diff for: library/alloc/src/ffi/c_str.rs

+1-1
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
}

Diff for: library/core/src/ffi/c_str.rs

+1-1
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
}

Diff for: library/core/src/ffi/mod.rs

+1-1
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" {}

Diff for: library/core/src/intrinsics/mod.rs

+1-1
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).

Diff for: library/core/src/iter/sources/once_with.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ use crate::iter::{FusedIterator, TrustedLen};
5858
/// ```
5959
#[inline]
6060
#[stable(feature = "iter_once_with", since = "1.43.0")]
61-
pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
62-
OnceWith { gen: Some(gen) }
61+
pub fn once_with<A, F: FnOnce() -> A>(make: F) -> OnceWith<F> {
62+
OnceWith { make: Some(make) }
6363
}
6464

6565
/// An iterator that yields a single element of type `A` by
@@ -70,13 +70,13 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
7070
#[derive(Clone)]
7171
#[stable(feature = "iter_once_with", since = "1.43.0")]
7272
pub struct OnceWith<F> {
73-
gen: Option<F>,
73+
make: Option<F>,
7474
}
7575

7676
#[stable(feature = "iter_once_with_debug", since = "1.68.0")]
7777
impl<F> fmt::Debug for OnceWith<F> {
7878
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79-
if self.gen.is_some() {
79+
if self.make.is_some() {
8080
f.write_str("OnceWith(Some(_))")
8181
} else {
8282
f.write_str("OnceWith(None)")
@@ -90,13 +90,13 @@ impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
9090

9191
#[inline]
9292
fn next(&mut self) -> Option<A> {
93-
let f = self.gen.take()?;
93+
let f = self.make.take()?;
9494
Some(f())
9595
}
9696

9797
#[inline]
9898
fn size_hint(&self) -> (usize, Option<usize>) {
99-
self.gen.iter().size_hint()
99+
self.make.iter().size_hint()
100100
}
101101
}
102102

@@ -110,7 +110,7 @@ impl<A, F: FnOnce() -> A> DoubleEndedIterator for OnceWith<F> {
110110
#[stable(feature = "iter_once_with", since = "1.43.0")]
111111
impl<A, F: FnOnce() -> A> ExactSizeIterator for OnceWith<F> {
112112
fn len(&self) -> usize {
113-
self.gen.iter().len()
113+
self.make.iter().len()
114114
}
115115
}
116116

Diff for: library/core/src/panicking.rs

+2-2
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
}

Diff for: library/core/src/ptr/metadata.rs

+1-1
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.

Diff for: library/coretests/tests/mem.rs

+1-1
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

Diff for: library/coretests/tests/num/flt2dec/mod.rs

+1-1
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

Diff for: library/coretests/tests/ptr.rs

+3-3
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(&());

Diff for: library/panic_abort/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
5454
))] {
5555
unsafe fn abort() -> ! {
5656
// call std::sys::abort_internal
57-
extern "C" {
57+
unsafe extern "C" {
5858
pub fn __rust_abort() -> !;
5959
}
6060
__rust_abort();
@@ -87,7 +87,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
8787
}
8888
} else if #[cfg(target_os = "teeos")] {
8989
mod teeos {
90-
extern "C" {
90+
unsafe extern "C" {
9191
pub fn TEE_Panic(code: u32) -> !;
9292
}
9393
}

Diff for: library/panic_abort/src/zkvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) {
1616
return;
1717
}
1818

19-
extern "C" {
19+
unsafe extern "C" {
2020
fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
2121
}
2222

Diff for: library/panic_unwind/src/emcc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct TypeInfo {
2121
}
2222
unsafe impl Sync for TypeInfo {}
2323

24-
extern "C" {
24+
unsafe extern "C" {
2525
// The leading `\x01` byte here is actually a magical signal to LLVM to
2626
// *not* apply any other mangling like prefixing with a `_` character.
2727
//
@@ -119,7 +119,7 @@ extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void {
119119
}
120120
}
121121

122-
extern "C" {
122+
unsafe extern "C" {
123123
fn __cxa_allocate_exception(thrown_size: libc::size_t) -> *mut libc::c_void;
124124
fn __cxa_begin_catch(thrown_exception: *mut libc::c_void) -> *mut libc::c_void;
125125
fn __cxa_end_catch();

Diff for: library/panic_unwind/src/hermit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use alloc::boxed::Box;
66
use core::any::Any;
77

88
pub(crate) unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
9-
extern "C" {
9+
unsafe extern "C" {
1010
fn __rust_abort() -> !;
1111
}
1212
__rust_abort();
1313
}
1414

1515
pub(crate) unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
16-
extern "C" {
16+
unsafe extern "C" {
1717
fn __rust_abort() -> !;
1818
}
1919
__rust_abort();

Diff for: library/panic_unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ cfg_if::cfg_if! {
7575
}
7676
}
7777

78-
extern "C" {
78+
unsafe extern "C" {
7979
/// Handler in std called when a panic object is dropped outside of
8080
/// `catch_unwind`.
8181
fn __rust_drop_panic() -> !;

Diff for: library/panic_unwind/src/miri.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::any::Any;
77
// Must be pointer-sized.
88
type Payload = Box<Box<dyn Any + Send>>;
99

10-
extern "Rust" {
10+
unsafe extern "Rust" {
1111
/// Miri-provided extern function to begin unwinding.
1212
fn miri_start_unwind(payload: *mut u8) -> !;
1313
}

Diff for: library/panic_unwind/src/seh.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod imp {
135135
#[derive(Copy, Clone)]
136136
pub(super) struct ptr_t(u32);
137137

138-
extern "C" {
138+
unsafe extern "C" {
139139
static __ImageBase: u8;
140140
}
141141

@@ -229,7 +229,7 @@ static mut CATCHABLE_TYPE: _CatchableType = _CatchableType {
229229
copyFunction: ptr_t::null(),
230230
};
231231

232-
extern "C" {
232+
unsafe extern "C" {
233233
// The leading `\x01` byte here is actually a magical signal to LLVM to
234234
// *not* apply any other mangling like prefixing with a `_` character.
235235
//
@@ -343,7 +343,7 @@ pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
343343
ptr_t::new(exception_copy as *mut u8).raw(),
344344
);
345345

346-
extern "system-unwind" {
346+
unsafe extern "system-unwind" {
347347
fn _CxxThrowException(pExceptionObject: *mut c_void, pThrowInfo: *mut u8) -> !;
348348
}
349349

Diff for: library/rtstartup/rsbegin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
5252
#[cfg(all(target_os = "windows", target_arch = "x86", target_env = "gnu"))]
5353
pub mod eh_frames {
5454
#[no_mangle]
55-
#[link_section = ".eh_frame"]
55+
#[unsafe(link_section = ".eh_frame")]
5656
// Marks beginning of the stack frame unwind info section
5757
pub static __EH_FRAME_BEGIN__: [u8; 0] = [];
5858

@@ -76,7 +76,7 @@ pub mod eh_frames {
7676
}
7777

7878
// Unwind info registration/deregistration routines.
79-
extern "C" {
79+
unsafe extern "C" {
8080
fn __register_frame_info(eh_frame_begin: *const u8, object: *mut u8);
8181
fn __deregister_frame_info(eh_frame_begin: *const u8, object: *mut u8);
8282
}
@@ -101,10 +101,10 @@ pub mod eh_frames {
101101
// end of the list. Since constructors are run in reverse order, this ensures that our
102102
// callbacks are the first and last ones executed.
103103

104-
#[link_section = ".ctors.65535"] // .ctors.* : C initialization callbacks
104+
#[unsafe(link_section = ".ctors.65535")] // .ctors.* : C initialization callbacks
105105
pub static P_INIT: unsafe extern "C" fn() = super::init;
106106

107-
#[link_section = ".dtors.65535"] // .dtors.* : C termination callbacks
107+
#[unsafe(link_section = ".dtors.65535")] // .dtors.* : C termination callbacks
108108
pub static P_UNINIT: unsafe extern "C" fn() = super::uninit;
109109
}
110110
}

Diff for: library/rtstartup/rsend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ pub mod eh_frames {
3232
// Terminate the frame unwind info section with a 0 as a sentinel;
3333
// this would be the 'length' field in a real FDE.
3434
#[no_mangle]
35-
#[link_section = ".eh_frame"]
35+
#[unsafe(link_section = ".eh_frame")]
3636
pub static __EH_FRAME_END__: u32 = 0;
3737
}

Diff for: library/std/src/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ pub fn take_alloc_error_hook() -> fn(Layout) {
345345
}
346346

347347
fn default_alloc_error_hook(layout: Layout) {
348-
extern "Rust" {
348+
unsafe extern "Rust" {
349349
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
350350
// Its value depends on the -Zoom={panic,abort} compiler option.
351351
static __rust_alloc_error_handler_should_panic: u8;

Diff for: library/std/src/panicking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ pub static EMPTY_PANIC: fn(&'static str) -> ! =
5454
// One day this may look a little less ad-hoc with the compiler helping out to
5555
// hook up these functions, but it is not this day!
5656
#[allow(improper_ctypes)]
57-
extern "C" {
57+
unsafe extern "C" {
5858
fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
5959
}
6060

61-
extern "Rust" {
61+
unsafe extern "Rust" {
6262
/// `PanicPayload` lazily performs allocation only when needed (this avoids
6363
/// allocations when using the "abort" panic runtime).
6464
fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32;

Diff for: library/std/src/sync/mpmc/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,9 @@ impl<T> Sender<T> {
616616
#[unstable(feature = "mpmc_channel", issue = "126840")]
617617
pub fn same_channel(&self, other: &Sender<T>) -> bool {
618618
match (&self.flavor, &other.flavor) {
619-
(SenderFlavor::Array(ref a), SenderFlavor::Array(ref b)) => a == b,
620-
(SenderFlavor::List(ref a), SenderFlavor::List(ref b)) => a == b,
621-
(SenderFlavor::Zero(ref a), SenderFlavor::Zero(ref b)) => a == b,
619+
(SenderFlavor::Array(a), SenderFlavor::Array(b)) => a == b,
620+
(SenderFlavor::List(a), SenderFlavor::List(b)) => a == b,
621+
(SenderFlavor::Zero(a), SenderFlavor::Zero(b)) => a == b,
622622
_ => false,
623623
}
624624
}

Diff for: library/std/src/sys/alloc/xous.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
88
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();
99

1010
#[cfg(test)]
11-
extern "Rust" {
11+
unsafe extern "Rust" {
1212
#[link_name = "_ZN16__rust_internals3std3sys4xous5alloc8DLMALLOCE"]
1313
static mut DLMALLOC: dlmalloc::Dlmalloc;
1414
}

Diff for: library/std/src/sys/cmath.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// These symbols are all defined by `libm`,
44
// or by `compiler-builtins` on unsupported platforms.
5-
extern "C" {
5+
unsafe extern "C" {
66
pub fn acos(n: f64) -> f64;
77
pub fn asin(n: f64) -> f64;
88
pub fn atan(n: f64) -> f64;

0 commit comments

Comments
 (0)