Skip to content

Commit 1e10e50

Browse files
committed
Remove allowing static_mut_refs lint
1 parent 883f9a2 commit 1e10e50

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

compiler/rustc_driver_impl/src/signal_handler.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! Primarily used to extract a backtrace from stack overflow
33
44
use std::alloc::{Layout, alloc};
5-
use std::{fmt, mem, ptr};
5+
use std::{fmt, mem, ptr, slice};
66

77
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
88

@@ -35,20 +35,22 @@ macro raw_errln($tokens:tt) {
3535
}
3636

3737
/// Signal handler installed for SIGSEGV
38-
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
39-
#[allow(static_mut_refs)]
40-
extern "C" fn print_stack_trace(_: libc::c_int) {
38+
///
39+
/// # Safety
40+
///
41+
/// Caller must ensure that this function is not re-entered.
42+
unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
4143
const MAX_FRAMES: usize = 256;
42-
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
43-
// in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
44-
static mut STACK_TRACE: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
4544
let stack = unsafe {
45+
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
46+
// in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
47+
static mut STACK_TRACE: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
4648
// Collect return addresses
47-
let depth = libc::backtrace(STACK_TRACE.as_mut_ptr(), MAX_FRAMES as i32);
49+
let depth = libc::backtrace(&raw mut STACK_TRACE as _, MAX_FRAMES as i32);
4850
if depth == 0 {
4951
return;
5052
}
51-
&STACK_TRACE.as_slice()[0..(depth as _)]
53+
slice::from_raw_parts(&raw const STACK_TRACE as _, depth as _)
5254
};
5355

5456
// Just a stack trace is cryptic. Explain what we're doing.

library/panic_unwind/src/seh.rs

-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ cfg_if::cfg_if! {
288288
}
289289
}
290290

291-
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
292-
#[allow(static_mut_refs)]
293291
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
294292
use core::intrinsics::atomic_store_seqcst;
295293

0 commit comments

Comments
 (0)