Skip to content

Commit 1a99257

Browse files
authored
Rollup merge of rust-lang#134560 - RalfJung:miri-thread-spawn, r=jhpratt
mri: add track_caller to thread spawning methods for better backtraces This is in preparation for rust-lang/miri#4093
2 parents 94b1b48 + 8b2b635 commit 1a99257

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

library/std/src/sys/pal/unix/thread.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ unsafe impl Sync for Thread {}
4545

4646
impl Thread {
4747
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
48+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4849
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
4950
let p = Box::into_raw(Box::new(p));
5051
let mut native: libc::pthread_t = mem::zeroed();

library/std/src/sys/pal/windows/thread.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Thread {
1919

2020
impl Thread {
2121
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
22+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
2223
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
2324
let p = Box::into_raw(Box::new(p));
2425

library/std/src/thread/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ impl Builder {
391391
/// handler.join().unwrap();
392392
/// ```
393393
#[stable(feature = "rust1", since = "1.0.0")]
394+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
394395
pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>>
395396
where
396397
F: FnOnce() -> T,
@@ -458,6 +459,7 @@ impl Builder {
458459
///
459460
/// [`io::Result`]: crate::io::Result
460461
#[stable(feature = "thread_spawn_unchecked", since = "1.82.0")]
462+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
461463
pub unsafe fn spawn_unchecked<F, T>(self, f: F) -> io::Result<JoinHandle<T>>
462464
where
463465
F: FnOnce() -> T,
@@ -467,6 +469,7 @@ impl Builder {
467469
Ok(JoinHandle(unsafe { self.spawn_unchecked_(f, None) }?))
468470
}
469471

472+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
470473
unsafe fn spawn_unchecked_<'scope, F, T>(
471474
self,
472475
f: F,
@@ -721,6 +724,7 @@ impl Builder {
721724
/// [`join`]: JoinHandle::join
722725
/// [`Err`]: crate::result::Result::Err
723726
#[stable(feature = "rust1", since = "1.0.0")]
727+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
724728
pub fn spawn<F, T>(f: F) -> JoinHandle<T>
725729
where
726730
F: FnOnce() -> T,

0 commit comments

Comments
 (0)