Skip to content

Commit 0b6739b

Browse files
committed
Move and update safety comment
1 parent fefc6d2 commit 0b6739b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

library/std/src/alloc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ fn default_alloc_error_hook(layout: Layout) {
394394
let mut lock = crate::sys::backtrace::lock();
395395

396396
match crate::panic::get_backtrace_style() {
397-
// SAFETY: we took out a lock just a second ago.
398397
Some(crate::panic::BacktraceStyle::Short) => {
399398
drop(lock.print(&mut out, crate::backtrace_rs::PrintFmt::Short))
400399
}

library/std/src/sys/backtrace.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ pub(crate) fn lock<'a>() -> BacktraceLock<'a> {
2020

2121
impl BacktraceLock<'_> {
2222
/// Prints the current backtrace.
23-
///
24-
/// NOTE: this function is not Sync. The caller must hold a mutex lock, or there must be only one thread in the program.
2523
pub(crate) fn print(&mut self, w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
2624
// There are issues currently linking libbacktrace into tests, and in
2725
// general during std's own unit tests we're not testing this path. In
@@ -36,13 +34,17 @@ impl BacktraceLock<'_> {
3634
}
3735
impl fmt::Display for DisplayBacktrace {
3836
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
37+
// SAFETY: the backtrace lock is held
3938
unsafe { _print_fmt(fmt, self.format) }
4039
}
4140
}
4241
write!(w, "{}", DisplayBacktrace { format })
4342
}
4443
}
4544

45+
/// # Safety
46+
///
47+
/// This function is not Sync. The caller must hold a mutex lock, or there must be only one thread in the program.
4648
unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::Result {
4749
// Always 'fail' to get the cwd when running under Miri -
4850
// this allows Miri to display backtraces in isolation mode

0 commit comments

Comments
 (0)