Skip to content

Commit

Permalink
start PR over again
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc committed Feb 2, 2021
1 parent b81f581 commit 4d45f69
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
46 changes: 46 additions & 0 deletions library/core/src/backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! hi
#![unstable(feature = "core_backtrace", issue = "74465")]
use crate::fmt;

// perma(?)-unstable
#[unstable(feature = "core_backtrace", issue = "74465")]
///
pub trait RawBacktraceImpl: fmt::Debug + fmt::Display + 'static {
///
unsafe fn drop_and_free(self: *mut Self);
}

#[unstable(feature = "core_backtrace", issue = "74465")]
///
pub struct Backtrace {
inner: *mut dyn RawBacktraceImpl,
}

#[unstable(feature = "core_backtrace", issue = "74465")]
unsafe impl Send for Backtrace {}

#[unstable(feature = "core_backtrace", issue = "74465")]
unsafe impl Sync for Backtrace {}

#[unstable(feature = "core_backtrace", issue = "74465")]
impl Drop for Backtrace {
fn drop(&mut self) {
unsafe { RawBacktraceImpl::drop_and_free(self.inner) }
}
}

#[unstable(feature = "core_backtrace", issue = "74465")]
impl fmt::Debug for Backtrace {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let imp: &dyn RawBacktraceImpl = unsafe { &*self.inner };
fmt::Debug::fmt(imp, fmt)
}
}

#[unstable(feature = "core_backtrace", issue = "74465")]
impl fmt::Display for Backtrace {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let imp: &dyn RawBacktraceImpl = unsafe { &*self.inner };
fmt::Display::fmt(imp, fmt)
}
}
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub mod ops;
pub mod any;
pub mod array;
pub mod ascii;
pub mod backtrace;
pub mod cell;
pub mod char;
pub mod ffi;
Expand Down
10 changes: 7 additions & 3 deletions library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,20 @@ use crate::sync::Once;
use crate::sys_common::backtrace::{lock, output_filename};
use crate::vec::Vec;

pub use core::backtrace::Backtrace;

/// A captured OS thread stack backtrace.
///
/// This type represents a stack backtrace for an OS thread captured at a
/// previous point in time. In some instances the `Backtrace` type may
/// internally be empty due to configuration. For more information see
/// `Backtrace::capture`.
pub struct Backtrace {
struct BacktraceImpl {
inner: Inner,
}

impl core::backtrace::RawBacktraceImpl for BacktraceImpl {}

/// The current status of a backtrace, indicating whether it was captured or
/// whether it is empty for some other reason.
#[non_exhaustive]
Expand Down Expand Up @@ -173,7 +177,7 @@ enum BytesOrWide {
Wide(Vec<u16>),
}

impl fmt::Debug for Backtrace {
impl fmt::Debug for BacktraceImpl {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let capture = match &self.inner {
Inner::Unsupported => return fmt.write_str("<unsupported>"),
Expand Down Expand Up @@ -372,7 +376,7 @@ impl<'a> Backtrace {
}
}

impl fmt::Display for Backtrace {
impl fmt::Display for BacktraceImpl {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let capture = match &self.inner {
Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
#![feature(const_raw_ptr_deref)]
#![feature(const_ipv4)]
#![feature(container_error_extra)]
#![feature(core_backtrace)]
#![feature(core_intrinsics)]
#![feature(custom_test_frameworks)]
#![feature(decl_macro)]
Expand Down

0 comments on commit 4d45f69

Please sign in to comment.