Skip to content

Commit bca67fe

Browse files
reez12gMark-Simulacrum
authored andcommitted
Add #[track_caller] to track callers when initializing poisoned Once
1 parent 6d76841 commit bca67fe

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

library/std/src/sync/once.rs

+2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl Once {
256256
///
257257
/// [poison]: struct.Mutex.html#poisoning
258258
#[stable(feature = "rust1", since = "1.0.0")]
259+
#[track_caller]
259260
pub fn call_once<F>(&self, f: F)
260261
where
261262
F: FnOnce(),
@@ -390,6 +391,7 @@ impl Once {
390391
// currently no way to take an `FnOnce` and call it via virtual dispatch
391392
// without some allocation overhead.
392393
#[cold]
394+
#[track_caller]
393395
fn call_inner(&self, ignore_poisoning: bool, init: &mut dyn FnMut(&OnceState)) {
394396
let mut state_and_queue = self.state_and_queue.load(Ordering::Acquire);
395397
loop {

src/test/ui/issues/issue-87707.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// test for #87707
2+
// edition:2018
3+
// run-fail
4+
// check-run-results
5+
6+
use std::sync::Once;
7+
use std::panic;
8+
9+
fn main() {
10+
let o = Once::new();
11+
let _ = panic::catch_unwind(|| {
12+
o.call_once(|| panic!("Here Once instance is poisoned."));
13+
});
14+
o.call_once(|| {});
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
thread 'main' panicked at 'Here Once instance is poisoned.', $DIR/issue-87707.rs:12:24
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3+
thread 'main' panicked at 'Once instance has previously been poisoned', $DIR/issue-87707.rs:14:7

0 commit comments

Comments
 (0)