about summary refs log tree commit diff
path: root/compiler/rustc_driver_impl
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-01-01 16:35:29 +1100
committerGitHub <noreply@github.com>2025-01-01 16:35:29 +1100
commitf4db757cb5bdb741b6b2b2113b9258ea46339464 (patch)
treed43b390d8ef16f7710a62c8d4522966b2661e530 /compiler/rustc_driver_impl
parent2085bce154867c3571b5482be53fe945aeed8c8b (diff)
parent1e10e503fe7e9d645f1ba3638eb17d8ac306093b (diff)
downloadrust-f4db757cb5bdb741b6b2b2113b9258ea46339464.tar.gz
rust-f4db757cb5bdb741b6b2b2113b9258ea46339464.zip
Rollup merge of #131439 - mu001999-contrib:cleanup/static-mut, r=estebank
Remove allowing static_mut_refs lint
Diffstat (limited to 'compiler/rustc_driver_impl')
-rw-r--r--compiler/rustc_driver_impl/src/signal_handler.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/rustc_driver_impl/src/signal_handler.rs b/compiler/rustc_driver_impl/src/signal_handler.rs
index d4f8199390c..08b7d937661 100644
--- a/compiler/rustc_driver_impl/src/signal_handler.rs
+++ b/compiler/rustc_driver_impl/src/signal_handler.rs
@@ -2,7 +2,7 @@
 //! Primarily used to extract a backtrace from stack overflow
 
 use std::alloc::{Layout, alloc};
-use std::{fmt, mem, ptr};
+use std::{fmt, mem, ptr, slice};
 
 use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
 
@@ -35,20 +35,22 @@ macro raw_errln($tokens:tt) {
 }
 
 /// Signal handler installed for SIGSEGV
-// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
-#[allow(static_mut_refs)]
-extern "C" fn print_stack_trace(_: libc::c_int) {
+///
+/// # Safety
+///
+/// Caller must ensure that this function is not re-entered.
+unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
     const MAX_FRAMES: usize = 256;
-    // Reserve data segment so we don't have to malloc in a signal handler, which might fail
-    // in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
-    static mut STACK_TRACE: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
     let stack = unsafe {
+        // Reserve data segment so we don't have to malloc in a signal handler, which might fail
+        // in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
+        static mut STACK_TRACE: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
         // Collect return addresses
-        let depth = libc::backtrace(STACK_TRACE.as_mut_ptr(), MAX_FRAMES as i32);
+        let depth = libc::backtrace(&raw mut STACK_TRACE as _, MAX_FRAMES as i32);
         if depth == 0 {
             return;
         }
-        &STACK_TRACE.as_slice()[0..(depth as _)]
+        slice::from_raw_parts(&raw const STACK_TRACE as _, depth as _)
     };
 
     // Just a stack trace is cryptic. Explain what we're doing.