about summary refs log tree commit diff
path: root/library/std/src/backtrace
diff options
context:
space:
mode:
authorAshley Mannix <kodraus@hey.com>2021-01-06 10:04:05 +1000
committerAshley Mannix <kodraus@hey.com>2021-01-06 10:44:06 +1000
commitdb4585aa3b1ee56e4722710d7665ee011fc11145 (patch)
treedf39527b19724778422dc575ad70595068efc2e7 /library/std/src/backtrace
parentda305a2b00530aa34dea4e48389204c26fa35dbb (diff)
downloadrust-db4585aa3b1ee56e4722710d7665ee011fc11145.tar.gz
rust-db4585aa3b1ee56e4722710d7665ee011fc11145.zip
use Once instead of Mutex to manage capture resolution
This allows us to return borrows of the captured backtrace frames
that are tied to a borrow of the Backtrace itself, instead of to
some short-lived Mutex guard.

It also makes it semantically clearer what synchronization is needed
on the capture.
Diffstat (limited to 'library/std/src/backtrace')
-rw-r--r--library/std/src/backtrace/tests.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/library/std/src/backtrace/tests.rs b/library/std/src/backtrace/tests.rs
index f5f74d1eb9a..31cf0f70218 100644
--- a/library/std/src/backtrace/tests.rs
+++ b/library/std/src/backtrace/tests.rs
@@ -3,7 +3,7 @@ use super::*;
 #[test]
 fn test_debug() {
     let backtrace = Backtrace {
-        inner: Inner::Captured(Mutex::new(Capture {
+        inner: Inner::Captured(LazilyResolvedCapture::new(Capture {
             actual_start: 1,
             resolved: true,
             frames: vec![
@@ -54,4 +54,7 @@ fn test_debug() {
     \n]";
 
     assert_eq!(format!("{:#?}", backtrace), expected);
+
+    // Format the backtrace a second time, just to make sure lazily resolved state is stable
+    assert_eq!(format!("{:#?}", backtrace), expected);
 }