diff --git a/library/backtrace b/library/backtrace index af078ecc0b069..8b8ea53b56f51 160000 --- a/library/backtrace +++ b/library/backtrace @@ -1 +1 @@ -Subproject commit af078ecc0b069ec594982f92d4c6c58af99efbb5 +Subproject commit 8b8ea53b56f519dd7780defdd4254daaec892584 diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 95e18ef2a6543..aeaa5b7002021 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -103,6 +103,7 @@ use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use crate::sync::Once; use crate::sys_common::backtrace::{lock, output_filename}; use crate::vec::Vec; +use crate::marker::PhantomData; /// A captured OS thread stack backtrace. /// @@ -147,17 +148,31 @@ fn _assert_send_sync() { _assert::(); } -struct BacktraceFrame { +/// A single frame of a backtrace. +#[derive(Debug)] +#[unstable(feature = "backtrace_frames", issue = "79676")] +pub struct BacktraceFrame { frame: RawFrame, symbols: Vec, } +/// An iterator over the frames of a backtrace, created +/// by the [`frames`] method on [`Backtrace`]. +#[derive(Debug)] +#[unstable(feature = "backtrace_frames", issue = "79676")] +pub struct Frames<'a> { + inner: Vec, + _backtrace: PhantomData<&'a Backtrace> +} + +#[derive(Debug, Clone)] enum RawFrame { Actual(backtrace_rs::Frame), #[cfg(test)] Fake, } +#[derive(Clone)] struct BacktraceSymbol { name: Option>, filename: Option, @@ -165,6 +180,7 @@ struct BacktraceSymbol { colno: Option, } +#[derive(Clone)] enum BytesOrWide { Bytes(Vec), Wide(Vec), @@ -353,6 +369,25 @@ impl Backtrace { } } +impl<'a> Backtrace { + /// Returns an iterator over the backtrace frames. + #[unstable(feature = "backtrace_frames", issue = "79676")] + pub fn frames(&self) -> Frames<'a> { + if let Inner::Captured(captured) = &self.inner { + let frames = &captured.lock().unwrap().frames; + Frames { + inner: frames.iter().map(|frame| frame.clone()).collect::>(), + _backtrace: PhantomData + } + } else { + Frames { + inner: vec![], + _backtrace: PhantomData + } + } + } +} + impl fmt::Display for Backtrace { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let capture = match &self.inner { @@ -476,3 +511,24 @@ impl RawFrame { } } } + +#[unstable(feature = "backtrace_frames", issue = "79676")] +impl<'a> AsRef<[BacktraceFrame]> for Frames<'a> { + fn as_ref(&self) -> &[BacktraceFrame] { + &self.inner + } +} + + +#[unstable(feature = "backtrace_frames", issue = "79676")] +impl BacktraceFrame { + // Private clone method so that we don't expose a + // public BacktraceFrame.clone() by deriving Clone + fn clone(&self) -> Self { + BacktraceFrame { + frame: self.frame.clone(), + symbols: self.symbols.clone(), + } + } +} + diff --git a/library/std/src/backtrace/tests.rs b/library/std/src/backtrace/tests.rs index 31cf0f702185c..3d65ef1dabe95 100644 --- a/library/std/src/backtrace/tests.rs +++ b/library/std/src/backtrace/tests.rs @@ -44,7 +44,12 @@ fn test_debug() { }, ], })), - }; + } +} + +#[test] +fn test_debug() { + let backtrace = generate_fake_backtrace(); #[rustfmt::skip] let expected = "Backtrace [\ diff --git a/library/stdarch b/library/stdarch index 9c732a56f67f5..3c3664355ef46 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 9c732a56f67f54d12a0b4fd99993154906c95ea6 +Subproject commit 3c3664355ef46e788b53080e521d6542fbddfd84 diff --git a/src/doc/book b/src/doc/book index 5bb44f8b5b0aa..13e1c05420bca 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 5bb44f8b5b0aa105c8b22602e9b18800484afa21 +Subproject commit 13e1c05420bca86ecc79e4ba5b6d02de9bd53c62 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index ba34b8a968f95..ca8169e69b479 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit ba34b8a968f9531d38c4dc4411d5568b7c076bfe +Subproject commit ca8169e69b479f615855d0eece7e318138fcfc00 diff --git a/src/doc/nomicon b/src/doc/nomicon index a5a48441d411f..23c49f1d5ce47 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit a5a48441d411f61556b57d762b03d6874afe575d +Subproject commit 23c49f1d5ce4720bc5b7e3a920f47eccc8da6b63 diff --git a/src/doc/reference b/src/doc/reference index b278478b76617..a7de763c21329 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit b278478b766178491a8b6f67afa4bcd6b64d977a +Subproject commit a7de763c213292f5b44bf10acb87ffa38724814d diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 1cce0737d6a7d..1886fda6981b7 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 1cce0737d6a7d3ceafb139b4a206861fb1dcb2ab +Subproject commit 1886fda6981b723e4de637074455558f8bc1e83c diff --git a/src/llvm-project b/src/llvm-project index f9a8d70b6e036..ee1617457899e 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit f9a8d70b6e0365ac2172ca6b7f1de0341297458d +Subproject commit ee1617457899ef2eb55dcf7ee2758b4340b6533f diff --git a/src/tools/cargo b/src/tools/cargo index 329895f5b52a3..d5556aeb8405b 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 329895f5b52a358e5d9ecb26215708b5cb31d906 +Subproject commit d5556aeb8405b1fe696adb6e297ad7a1f2989b62 diff --git a/src/tools/miri b/src/tools/miri index a09f8b0c06c6b..30e0c303a0197 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit a09f8b0c06c6bb051bd1e104c6be56fbe51f3d86 +Subproject commit 30e0c303a019737cb0e22db464c774ac66b14e07 diff --git a/src/tools/rls b/src/tools/rls index 2cf84baa5e3c5..dab1468d6aeed 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 2cf84baa5e3c55ac02f42919e67440acb5417125 +Subproject commit dab1468d6aeed0e49f7d0569c1d2128b5a7751e0 diff --git a/src/tools/rust-installer b/src/tools/rust-installer index 5254dbfd25d52..d66f476b4d5e7 160000 --- a/src/tools/rust-installer +++ b/src/tools/rust-installer @@ -1 +1 @@ -Subproject commit 5254dbfd25d5284728ab624dca1969d61427a0db +Subproject commit d66f476b4d5e7fdf1ec215c9ac16c923dc292324 diff --git a/src/tools/rustfmt b/src/tools/rustfmt index acd94866fd0ff..eb894d5370812 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit acd94866fd0ff5eacb7e184ae21c19e5440fc5fb +Subproject commit eb894d53708122a67762de9489881c11aa8ce257