Skip to content

Commit 7585bd5

Browse files
Rollup merge of #52261 - ljedrz:dyn_libpanic_unwind, r=alexcrichton
Deny bare trait objects in in src/libpanic_unwind Enforce `#![deny(bare_trait_objects)]` in `src/libpanic_unwind`.
2 parents e6f6608 + dbab06d commit 7585bd5

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

src/libpanic_unwind/dwarf/eh.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub const DW_EH_PE_indirect: u8 = 0x80;
4848
pub struct EHContext<'a> {
4949
pub ip: usize, // Current instruction pointer
5050
pub func_start: usize, // Address of the current function
51-
pub get_text_start: &'a Fn() -> usize, // Get address of the code section
52-
pub get_data_start: &'a Fn() -> usize, // Get address of the data section
51+
pub get_text_start: &'a dyn Fn() -> usize, // Get address of the code section
52+
pub get_data_start: &'a dyn Fn() -> usize, // Get address of the data section
5353
}
5454

5555
pub enum EHAction {

src/libpanic_unwind/emcc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ pub fn payload() -> *mut u8 {
2929
ptr::null_mut()
3030
}
3131

32-
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
32+
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
3333
assert!(!ptr.is_null());
3434
let ex = ptr::read(ptr as *mut _);
3535
__cxa_free_exception(ptr as *mut _);
3636
ex
3737
}
3838

39-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
39+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
4040
let sz = mem::size_of_val(&data);
4141
let exception = __cxa_allocate_exception(sz);
4242
if exception == ptr::null_mut() {
4343
return uw::_URC_FATAL_PHASE1_ERROR as u32;
4444
}
45-
let exception = exception as *mut Box<Any + Send>;
45+
let exception = exception as *mut Box<dyn Any + Send>;
4646
ptr::write(exception, data);
4747
__cxa_throw(exception as *mut _, ptr::null_mut(), ptr::null_mut());
4848

src/libpanic_unwind/gcc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ use dwarf::eh::{self, EHContext, EHAction};
6767
#[repr(C)]
6868
struct Exception {
6969
_uwe: uw::_Unwind_Exception,
70-
cause: Option<Box<Any + Send>>,
70+
cause: Option<Box<dyn Any + Send>>,
7171
}
7272

73-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
73+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
7474
let exception = Box::new(Exception {
7575
_uwe: uw::_Unwind_Exception {
7676
exception_class: rust_exception_class(),
@@ -94,7 +94,7 @@ pub fn payload() -> *mut u8 {
9494
ptr::null_mut()
9595
}
9696

97-
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
97+
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
9898
let my_ep = ptr as *mut Exception;
9999
let cause = (*my_ep).cause.take();
100100
uw::_Unwind_DeleteException(ptr as *mut _);

src/libpanic_unwind/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! More documentation about each implementation can be found in the respective
2323
//! module.
2424
25+
#![deny(bare_trait_objects)]
2526
#![no_std]
2627
#![unstable(feature = "panic_unwind", issue = "32837")]
2728
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@@ -117,6 +118,6 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
117118
#[no_mangle]
118119
#[unwind(allowed)]
119120
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
120-
let payload = payload as *mut &mut BoxMeUp;
121+
let payload = payload as *mut &mut dyn BoxMeUp;
121122
imp::panic(Box::from_raw((*payload).box_me_up()))
122123
}

src/libpanic_unwind/seh.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
//! throwing. Note that throwing an exception into Rust is undefined behavior
4444
//! anyway, so this should be fine.
4545
//! * We've got some data to transmit across the unwinding boundary,
46-
//! specifically a `Box<Any + Send>`. Like with Dwarf exceptions
46+
//! specifically a `Box<dyn Any + Send>`. Like with Dwarf exceptions
4747
//! these two pointers are stored as a payload in the exception itself. On
4848
//! MSVC, however, there's no need for an extra heap allocation because the
4949
//! call stack is preserved while filter functions are being executed. This
@@ -243,7 +243,7 @@ static mut TYPE_DESCRIPTOR2: _TypeDescriptor = _TypeDescriptor {
243243
name: imp::NAME2,
244244
};
245245

246-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
246+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
247247
use core::intrinsics::atomic_store;
248248

249249
// _CxxThrowException executes entirely on this stack frame, so there's no
@@ -297,7 +297,7 @@ pub fn payload() -> [u64; 2] {
297297
[0; 2]
298298
}
299299

300-
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<Any + Send> {
300+
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
301301
mem::transmute(raw::TraitObject {
302302
data: payload[0] as *mut _,
303303
vtable: payload[1] as *mut _,

src/libpanic_unwind/seh64_gnu.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ const RUST_PANIC: c::DWORD = ETYPE | (1 << 24) | MAGIC;
3737

3838
#[repr(C)]
3939
struct PanicData {
40-
data: Box<Any + Send>,
40+
data: Box<dyn Any + Send>,
4141
}
4242

43-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
43+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
4444
let panic_ctx = Box::new(PanicData { data: data });
4545
let params = [Box::into_raw(panic_ctx) as c::ULONG_PTR];
4646
c::RaiseException(RUST_PANIC,
@@ -54,7 +54,7 @@ pub fn payload() -> *mut u8 {
5454
ptr::null_mut()
5555
}
5656

57-
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
57+
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
5858
let panic_ctx = Box::from_raw(ptr as *mut PanicData);
5959
return panic_ctx.data;
6060
}

src/libpanic_unwind/wasm32.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ pub fn payload() -> *mut u8 {
2020
0 as *mut u8
2121
}
2222

23-
pub unsafe fn cleanup(_ptr: *mut u8) -> Box<Any + Send> {
23+
pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
2424
intrinsics::abort()
2525
}
2626

27-
pub unsafe fn panic(_data: Box<Any + Send>) -> u32 {
27+
pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
2828
intrinsics::abort()
2929
}

0 commit comments

Comments
 (0)