Skip to content

Some miscellaneous edition-related library tweaks #136705

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::hint;
#[cfg(not(test))]
use core::ptr::{self, NonNull};

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

#[cfg(not(no_global_oom_handling))]
extern "Rust" {
unsafe extern "Rust" {
// This is the magic symbol to call the global alloc error handler. rustc generates
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
// default implementations below (`__rdl_oom`) otherwise.
Expand Down Expand Up @@ -426,7 +426,7 @@ pub mod __alloc_error_handler {
// `#[alloc_error_handler]`.
#[rustc_std_internal_symbol]
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
extern "Rust" {
unsafe extern "Rust" {
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
// Its value depends on the -Zoom={panic,abort} compiler option.
static __rust_alloc_error_handler_should_panic: u8;
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/merge_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<I: Iterator> MergeIterInner<I> {
b_next = self.b.next();
}
}
if let (Some(ref a1), Some(ref b1)) = (&a_next, &b_next) {
if let (Some(a1), Some(b1)) = (&a_next, &b_next) {
match cmp(a1, b1) {
Ordering::Less => self.peeked = b_next.take().map(Peeked::B),
Ordering::Greater => self.peeked = a_next.take().map(Peeked::A),
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl CString {
// information about the size of the allocation is correct on Rust's
// side.
unsafe {
extern "C" {
unsafe extern "C" {
/// Provided by libc or compiler_builtins.
fn strlen(s: *const c_char) -> usize;
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ const unsafe fn strlen(ptr: *const c_char) -> usize {

len
} else {
extern "C" {
unsafe extern "C" {
/// Provided by libc or compiler_builtins.
fn strlen(s: *const c_char) -> usize;
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ impl fmt::Debug for c_void {
cfg(not(target_feature = "crt-static"))
)]
#[link(name = "/defaultlib:libcmt", modifiers = "+verbatim", cfg(target_feature = "crt-static"))]
extern "C" {}
unsafe extern "C" {}
2 changes: 1 addition & 1 deletion library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4855,7 +4855,7 @@ pub const unsafe fn copysignf128(_x: f128, _y: f128) -> f128 {
#[cfg(miri)]
#[rustc_allow_const_fn_unstable(const_eval_select)]
pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize) {
extern "Rust" {
unsafe extern "Rust" {
/// Miri-provided extern function to promise that a given pointer is properly aligned for
/// "symbolic" alignment checks. Will fail if the pointer is not actually aligned or `align` is
/// not a power of two. Has no effect when alignment checks are concrete (which is the default).
Expand Down
14 changes: 7 additions & 7 deletions library/core/src/iter/sources/once_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ use crate::iter::{FusedIterator, TrustedLen};
/// ```
#[inline]
#[stable(feature = "iter_once_with", since = "1.43.0")]
pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
OnceWith { gen: Some(gen) }
pub fn once_with<A, F: FnOnce() -> A>(make: F) -> OnceWith<F> {
OnceWith { make: Some(make) }
}

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

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

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

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.gen.iter().size_hint()
self.make.iter().size_hint()
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {

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

// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
// that gets resolved to the `#[panic_handler]` function.
extern "Rust" {
unsafe extern "Rust" {
#[lang = "panic_impl"]
fn panic_impl(pi: &PanicInfo<'_>) -> !;
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub struct DynMetadata<Dyn: ?Sized> {
_phantom: crate::marker::PhantomData<Dyn>,
}

extern "C" {
unsafe extern "C" {
/// Opaque type for accessing vtables.
///
/// Private implementation detail of `DynMetadata::size_of` etc.
Expand Down
2 changes: 1 addition & 1 deletion library/coretests/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ fn offset_of_dst() {
z: dyn Trait,
}

extern "C" {
unsafe extern "C" {
type Extern;
}

Expand Down
2 changes: 1 addition & 1 deletion library/coretests/tests/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn ldexp_f32(a: f32, b: i32) -> f32 {
}

fn ldexp_f64(a: f64, b: i32) -> f64 {
extern "C" {
unsafe extern "C" {
fn ldexp(x: f64, n: i32) -> f64;
}
// SAFETY: assuming a correct `ldexp` has been supplied, the given arguments cannot possibly
Expand Down
6 changes: 3 additions & 3 deletions library/coretests/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn test_is_null() {
let nmi: *mut dyn ToString = null_mut::<isize>();
assert!(nmi.is_null());

extern "C" {
unsafe extern "C" {
type Extern;
}
let ec: *const Extern = null::<Extern>();
Expand Down Expand Up @@ -308,7 +308,7 @@ fn test_const_nonnull_new() {
pub fn test_variadic_fnptr() {
use core::ffi;
use core::hash::{Hash, SipHasher};
extern "C" {
unsafe extern "C" {
// This needs to use the correct function signature even though it isn't called as some
// codegen backends make it UB to declare a function with multiple conflicting signatures
// (like LLVM) while others straight up return an error (like Cranelift).
Expand Down Expand Up @@ -506,7 +506,7 @@ fn offset_from() {
fn ptr_metadata() {
struct Unit;
struct Pair<A, B: ?Sized>(A, B);
extern "C" {
unsafe extern "C" {
type Extern;
}
let () = metadata(&());
Expand Down
4 changes: 2 additions & 2 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
))] {
unsafe fn abort() -> ! {
// call std::sys::abort_internal
extern "C" {
unsafe extern "C" {
pub fn __rust_abort() -> !;
}
__rust_abort();
Expand Down Expand Up @@ -87,7 +87,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
}
} else if #[cfg(target_os = "teeos")] {
mod teeos {
extern "C" {
unsafe extern "C" {
pub fn TEE_Panic(code: u32) -> !;
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/panic_abort/src/zkvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) {
return;
}

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

Expand Down
4 changes: 2 additions & 2 deletions library/panic_unwind/src/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct TypeInfo {
}
unsafe impl Sync for TypeInfo {}

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

extern "C" {
unsafe extern "C" {
fn __cxa_allocate_exception(thrown_size: libc::size_t) -> *mut libc::c_void;
fn __cxa_begin_catch(thrown_exception: *mut libc::c_void) -> *mut libc::c_void;
fn __cxa_end_catch();
Expand Down
4 changes: 2 additions & 2 deletions library/panic_unwind/src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use alloc::boxed::Box;
use core::any::Any;

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

pub(crate) unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
extern "C" {
unsafe extern "C" {
fn __rust_abort() -> !;
}
__rust_abort();
Expand Down
2 changes: 1 addition & 1 deletion library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ cfg_if::cfg_if! {
}
}

extern "C" {
unsafe extern "C" {
/// Handler in std called when a panic object is dropped outside of
/// `catch_unwind`.
fn __rust_drop_panic() -> !;
Expand Down
2 changes: 1 addition & 1 deletion library/panic_unwind/src/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::any::Any;
// Must be pointer-sized.
type Payload = Box<Box<dyn Any + Send>>;

extern "Rust" {
unsafe extern "Rust" {
/// Miri-provided extern function to begin unwinding.
fn miri_start_unwind(payload: *mut u8) -> !;
}
Expand Down
6 changes: 3 additions & 3 deletions library/panic_unwind/src/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod imp {
#[derive(Copy, Clone)]
pub(super) struct ptr_t(u32);

extern "C" {
unsafe extern "C" {
static __ImageBase: u8;
}

Expand Down Expand Up @@ -229,7 +229,7 @@ static mut CATCHABLE_TYPE: _CatchableType = _CatchableType {
copyFunction: ptr_t::null(),
};

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

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

Expand Down
8 changes: 4 additions & 4 deletions library/rtstartup/rsbegin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
#[cfg(all(target_os = "windows", target_arch = "x86", target_env = "gnu"))]
pub mod eh_frames {
#[no_mangle]
#[link_section = ".eh_frame"]
#[unsafe(link_section = ".eh_frame")]
// Marks beginning of the stack frame unwind info section
pub static __EH_FRAME_BEGIN__: [u8; 0] = [];

Expand All @@ -76,7 +76,7 @@ pub mod eh_frames {
}

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

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

#[link_section = ".dtors.65535"] // .dtors.* : C termination callbacks
#[unsafe(link_section = ".dtors.65535")] // .dtors.* : C termination callbacks
pub static P_UNINIT: unsafe extern "C" fn() = super::uninit;
}
}
2 changes: 1 addition & 1 deletion library/rtstartup/rsend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ pub mod eh_frames {
// Terminate the frame unwind info section with a 0 as a sentinel;
// this would be the 'length' field in a real FDE.
#[no_mangle]
#[link_section = ".eh_frame"]
#[unsafe(link_section = ".eh_frame")]
pub static __EH_FRAME_END__: u32 = 0;
}
2 changes: 1 addition & 1 deletion library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub fn take_alloc_error_hook() -> fn(Layout) {
}

fn default_alloc_error_hook(layout: Layout) {
extern "Rust" {
unsafe extern "Rust" {
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
// Its value depends on the -Zoom={panic,abort} compiler option.
static __rust_alloc_error_handler_should_panic: u8;
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ pub static EMPTY_PANIC: fn(&'static str) -> ! =
// One day this may look a little less ad-hoc with the compiler helping out to
// hook up these functions, but it is not this day!
#[allow(improper_ctypes)]
extern "C" {
unsafe extern "C" {
fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
}

extern "Rust" {
unsafe extern "Rust" {
/// `PanicPayload` lazily performs allocation only when needed (this avoids
/// allocations when using the "abort" panic runtime).
fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32;
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sync/mpmc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ impl<T> Sender<T> {
#[unstable(feature = "mpmc_channel", issue = "126840")]
pub fn same_channel(&self, other: &Sender<T>) -> bool {
match (&self.flavor, &other.flavor) {
(SenderFlavor::Array(ref a), SenderFlavor::Array(ref b)) => a == b,
(SenderFlavor::List(ref a), SenderFlavor::List(ref b)) => a == b,
(SenderFlavor::Zero(ref a), SenderFlavor::Zero(ref b)) => a == b,
(SenderFlavor::Array(a), SenderFlavor::Array(b)) => a == b,
(SenderFlavor::List(a), SenderFlavor::List(b)) => a == b,
(SenderFlavor::Zero(a), SenderFlavor::Zero(b)) => a == b,
_ => false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/alloc/xous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();

#[cfg(test)]
extern "Rust" {
unsafe extern "Rust" {
#[link_name = "_ZN16__rust_internals3std3sys4xous5alloc8DLMALLOCE"]
static mut DLMALLOC: dlmalloc::Dlmalloc;
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// These symbols are all defined by `libm`,
// or by `compiler-builtins` on unsupported platforms.
extern "C" {
unsafe extern "C" {
pub fn acos(n: f64) -> f64;
pub fn asin(n: f64) -> f64;
pub fn atan(n: f64) -> f64;
Expand Down
Loading
Loading