rust: upgrade to Rust 1.68.2 · herrnst/linux-asahi@3ed03f4

@@ -22,21 +22,24 @@ use core::marker::Destruct;

2222

mod tests;

23232424

extern "Rust" {

25-

// These are the magic symbols to call the global allocator. rustc generates

25+

// These are the magic symbols to call the global allocator. rustc generates

2626

// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute

2727

// (the code expanding that attribute macro generates those functions), or to call

28-

// the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)

28+

// the default implementations in std (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)

2929

// otherwise.

30-

// The rustc fork of LLVM also special-cases these function names to be able to optimize them

30+

// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them

3131

// like `malloc`, `realloc`, and `free`, respectively.

3232

#[rustc_allocator]

33-

#[rustc_allocator_nounwind]

33+

#[rustc_nounwind]

3434

fn __rust_alloc(size: usize, align: usize) -> *mut u8;

35-

#[rustc_allocator_nounwind]

35+

#[rustc_deallocator]

36+

#[rustc_nounwind]

3637

fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);

37-

#[rustc_allocator_nounwind]

38+

#[rustc_reallocator]

39+

#[rustc_nounwind]

3840

fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;

39-

#[rustc_allocator_nounwind]

41+

#[rustc_allocator_zeroed]

42+

#[rustc_nounwind]

4043

fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;

4144

}

4245

@@ -72,11 +75,14 @@ pub use std::alloc::Global;

7275

/// # Examples

7376

///

7477

/// ```

75-

/// use std::alloc::{alloc, dealloc, Layout};

78+

/// use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};

7679

///

7780

/// unsafe {

7881

/// let layout = Layout::new::<u16>();

7982

/// let ptr = alloc(layout);

83+

/// if ptr.is_null() {

84+

/// handle_alloc_error(layout);

85+

/// }

8086

///

8187

/// *(ptr as *mut u16) = 42;

8288

/// assert_eq!(*(ptr as *mut u16), 42);

@@ -349,7 +355,7 @@ pub(crate) const unsafe fn box_free<T: ?Sized, A: ~const Allocator + ~const Dest

349355350356

#[cfg(not(no_global_oom_handling))]

351357

extern "Rust" {

352-

// This is the magic symbol to call the global alloc error handler. rustc generates

358+

// This is the magic symbol to call the global alloc error handler. rustc generates

353359

// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the

354360

// default implementations below (`__rdl_oom`) otherwise.

355361

fn __rust_alloc_error_handler(size: usize, align: usize) -> !;

@@ -394,25 +400,24 @@ pub use std::alloc::handle_alloc_error;

394400

#[allow(unused_attributes)]

395401

#[unstable(feature = "alloc_internals", issue = "none")]

396402

pub mod __alloc_error_handler {

397-

use crate::alloc::Layout;

398-399-

// called via generated `__rust_alloc_error_handler`

400-401-

// if there is no `#[alloc_error_handler]`

403+

// called via generated `__rust_alloc_error_handler` if there is no

404+

// `#[alloc_error_handler]`.

402405

#[rustc_std_internal_symbol]

403-

pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! {

404-

panic!("memory allocation of {size} bytes failed")

405-

}

406-407-

// if there is an `#[alloc_error_handler]`

408-

#[rustc_std_internal_symbol]

409-

pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! {

410-

let layout = unsafe { Layout::from_size_align_unchecked(size, align) };

406+

pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {

411407

extern "Rust" {

412-

#[lang = "oom"]

413-

fn oom_impl(layout: Layout) -> !;

408+

// This symbol is emitted by rustc next to __rust_alloc_error_handler.

409+

// Its value depends on the -Zoom={panic,abort} compiler option.

410+

static __rust_alloc_error_handler_should_panic: u8;

411+

}

412+413+

#[allow(unused_unsafe)]

414+

if unsafe { __rust_alloc_error_handler_should_panic != 0 } {

415+

panic!("memory allocation of {size} bytes failed")

416+

} else {

417+

core::panicking::panic_nounwind_fmt(format_args!(

418+

"memory allocation of {size} bytes failed"

419+

))

414420

}

415-

unsafe { oom_impl(layout) }

416421

}

417422

}

418423