diff options
| author | Ralf Jung <post@ralfj.de> | 2024-12-20 15:03:51 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-12-20 15:03:51 +0100 |
| commit | 8b2b6359f97ee9ac8fb1b5c35e86211222d02574 (patch) | |
| tree | ef7f4f6d98b6367cfb92df5c4c48e2fd53ece29c | |
| parent | 5dfe648b45659db8dd0a673a806bba3df84aa3af (diff) | |
| download | rust-8b2b6359f97ee9ac8fb1b5c35e86211222d02574.tar.gz rust-8b2b6359f97ee9ac8fb1b5c35e86211222d02574.zip | |
mri: add track_caller to thread spawning methods for better backtraces
| -rw-r--r-- | library/std/src/sys/pal/unix/thread.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/pal/windows/thread.rs | 1 | ||||
| -rw-r--r-- | library/std/src/thread/mod.rs | 4 |
3 files changed, 6 insertions, 0 deletions
diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index 131a6e81b1e..e360ba0f6d7 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -45,6 +45,7 @@ unsafe impl Sync for Thread {} impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements + #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> { let p = Box::into_raw(Box::new(p)); let mut native: libc::pthread_t = mem::zeroed(); diff --git a/library/std/src/sys/pal/windows/thread.rs b/library/std/src/sys/pal/windows/thread.rs index 2c8ce42f414..45e52cf4d04 100644 --- a/library/std/src/sys/pal/windows/thread.rs +++ b/library/std/src/sys/pal/windows/thread.rs @@ -19,6 +19,7 @@ pub struct Thread { impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements + #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> { let p = Box::into_raw(Box::new(p)); diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index cfbf6548a38..85ee369ca2b 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -391,6 +391,7 @@ impl Builder { /// handler.join().unwrap(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where F: FnOnce() -> T, @@ -458,6 +459,7 @@ impl Builder { /// /// [`io::Result`]: crate::io::Result #[stable(feature = "thread_spawn_unchecked", since = "1.82.0")] + #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub unsafe fn spawn_unchecked<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where F: FnOnce() -> T, @@ -467,6 +469,7 @@ impl Builder { Ok(JoinHandle(unsafe { self.spawn_unchecked_(f, None) }?)) } + #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces unsafe fn spawn_unchecked_<'scope, F, T>( self, f: F, @@ -721,6 +724,7 @@ impl Builder { /// [`join`]: JoinHandle::join /// [`Err`]: crate::result::Result::Err #[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub fn spawn<F, T>(f: F) -> JoinHandle<T> where F: FnOnce() -> T, |
