Skip to content

Commit 823d14f

Browse files
committed
Auto merge of rust-lang#121655 - matthiaskrgr:rollup-qpx3kks, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#121598 (rename 'try' intrinsic to 'catch_unwind') - rust-lang#121639 (Update books) - rust-lang#121648 (Update Vec and String `{from,into}_raw_parts`-family docs) - rust-lang#121651 (Properly emit `expected ;` on `#[attr] expr`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ebf67e2 + ed4bb09 commit 823d14f

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

alloc/src/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl String {
864864
}
865865
}
866866

867-
/// Decomposes a `String` into its raw components.
867+
/// Decomposes a `String` into its raw components: `(pointer, length, capacity)`.
868868
///
869869
/// Returns the raw pointer to the underlying data, the length of
870870
/// the string (in bytes), and the allocated capacity of the data
@@ -896,7 +896,7 @@ impl String {
896896
self.vec.into_raw_parts()
897897
}
898898

899-
/// Creates a new `String` from a length, capacity, and pointer.
899+
/// Creates a new `String` from a pointer, a length and a capacity.
900900
///
901901
/// # Safety
902902
///

alloc/src/vec/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl<T> Vec<T> {
481481
Self::with_capacity_in(capacity, Global)
482482
}
483483

484-
/// Creates a `Vec<T>` directly from a pointer, a capacity, and a length.
484+
/// Creates a `Vec<T>` directly from a pointer, a length, and a capacity.
485485
///
486486
/// # Safety
487487
///
@@ -672,7 +672,7 @@ impl<T, A: Allocator> Vec<T, A> {
672672
Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 }
673673
}
674674

675-
/// Creates a `Vec<T, A>` directly from a pointer, a capacity, a length,
675+
/// Creates a `Vec<T, A>` directly from a pointer, a length, a capacity,
676676
/// and an allocator.
677677
///
678678
/// # Safety
@@ -786,7 +786,7 @@ impl<T, A: Allocator> Vec<T, A> {
786786
unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } }
787787
}
788788

789-
/// Decomposes a `Vec<T>` into its raw components.
789+
/// Decomposes a `Vec<T>` into its raw components: `(pointer, length, capacity)`.
790790
///
791791
/// Returns the raw pointer to the underlying data, the length of
792792
/// the vector (in elements), and the allocated capacity of the
@@ -824,7 +824,7 @@ impl<T, A: Allocator> Vec<T, A> {
824824
(me.as_mut_ptr(), me.len(), me.capacity())
825825
}
826826

827-
/// Decomposes a `Vec<T>` into its raw components.
827+
/// Decomposes a `Vec<T>` into its raw components: `(pointer, length, capacity, allocator)`.
828828
///
829829
/// Returns the raw pointer to the underlying data, the length of the vector (in elements),
830830
/// the allocated capacity of the data (in elements), and the allocator. These are the same

core/src/intrinsics.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
7575
unsafe { crate::ptr::drop_in_place(to_drop) }
7676
}
7777

78+
#[cfg(bootstrap)]
79+
pub use self::r#try as catch_unwind;
80+
7881
extern "rust-intrinsic" {
7982
// N.B., these intrinsics take raw pointers because they mutate aliased
8083
// memory, which is not valid for either `&` or `&mut`.
@@ -2382,16 +2385,24 @@ extern "rust-intrinsic" {
23822385
#[rustc_nounwind]
23832386
pub fn variant_count<T>() -> usize;
23842387

2385-
/// Rust's "try catch" construct which invokes the function pointer `try_fn`
2386-
/// with the data pointer `data`.
2387-
///
2388-
/// The third argument is a function called if a panic occurs. This function
2389-
/// takes the data pointer and a pointer to the target-specific exception
2390-
/// object that was caught. For more information see the compiler's
2391-
/// source as well as std's catch implementation.
2388+
/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
2389+
/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
23922390
///
23932391
/// `catch_fn` must not unwind.
2392+
///
2393+
/// The third argument is a function called if an unwind occurs (both Rust unwinds and foreign
2394+
/// unwinds). This function takes the data pointer and a pointer to the target-specific
2395+
/// exception object that was caught. For more information, see the compiler's source as well as
2396+
/// std's `catch_unwind` implementation.
2397+
///
2398+
/// The stable version of this intrinsic is `std::panic::catch_unwind`.
2399+
#[rustc_nounwind]
2400+
#[cfg(not(bootstrap))]
2401+
pub fn catch_unwind(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
2402+
2403+
/// For bootstrap only, see `catch_unwind`.
23942404
#[rustc_nounwind]
2405+
#[cfg(bootstrap)]
23952406
pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
23962407

23972408
/// Emits a `!nontemporal` store according to LLVM (see their docs).

panic_unwind/src/miri.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ type Payload = Box<Box<dyn Any + Send>>;
88

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

1414
pub unsafe fn panic(payload: Box<dyn Any + Send>) -> u32 {
15-
// The payload we pass to `miri_start_panic` will be exactly the argument we get
15+
// The payload we pass to `miri_start_unwind` will be exactly the argument we get
1616
// in `cleanup` below. So we just box it up once, to get something pointer-sized.
1717
let payload_box: Payload = Box::new(payload);
18-
miri_start_panic(Box::into_raw(payload_box) as *mut u8)
18+
miri_start_unwind(Box::into_raw(payload_box) as *mut u8)
1919
}
2020

2121
pub unsafe fn cleanup(payload_box: *mut u8) -> Box<dyn Any + Send> {

std/src/panicking.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
508508
// Access to the union's fields: this is `std` and we know that the `r#try`
509509
// intrinsic fills in the `r` or `p` union field based on its return value.
510510
//
511-
// The call to `intrinsics::r#try` is made safe by:
511+
// The call to `intrinsics::catch_unwind` is made safe by:
512512
// - `do_call`, the first argument, can be called with the initial `data_ptr`.
513513
// - `do_catch`, the second argument, can be called with the `data_ptr` as well.
514514
// See their safety preconditions for more information
515515
unsafe {
516-
return if intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
516+
return if intrinsics::catch_unwind(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
517517
Ok(ManuallyDrop::into_inner(data.r))
518518
} else {
519519
Err(ManuallyDrop::into_inner(data.p))
@@ -540,7 +540,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
540540
// Its must contains a valid `f` (type: F) value that can be use to fill
541541
// `data.r`.
542542
//
543-
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
543+
// This function cannot be marked as `unsafe` because `intrinsics::catch_unwind`
544544
// expects normal function pointers.
545545
#[inline]
546546
fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
@@ -562,7 +562,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
562562
// Since this uses `cleanup` it also hinges on a correct implementation of
563563
// `__rustc_panic_cleanup`.
564564
//
565-
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
565+
// This function cannot be marked as `unsafe` because `intrinsics::catch_unwind`
566566
// expects normal function pointers.
567567
#[inline]
568568
#[rustc_nounwind] // `intrinsic::r#try` requires catch fn to be nounwind

0 commit comments

Comments
 (0)