Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize the backtrace feature. #72981

Closed

Conversation

withoutboats
Copy link
Contributor

@withoutboats withoutboats commented Jun 4, 2020

Stabilization Report

This is a proposal to stabilize the backtrace feature in libstd. It would make these additional APIs available on stable:

pub mod backtrace {
    pub struct Backtrace {
    }

    enum BacktraceStatus {
        Unsupported,
        Disabled,
        Captured,
    }

    impl Backtrace {
        pub fn capture() -> Backtrace { }

        pub fn force_capture() -> Backtrace { }

        pub fn disabled() -> Backtrace { }

        pub fn status(&self) -> BacktraceState { }
    }

    impl Display for Backtrace { }
    impl Debug for Backtrace { }
}

pub mod error {
    pub trait Error {
        fn backtrace(&self) -> Option<&Backtrace> {
            None
        }
    }
}

The behavior of the backtrace type, especially as it connects to certain environment variables, is better documented in the module documentation: https://doc.rust-lang.org/std/backtrace/index.html

The internal details of how backtraces are captured and represented are platform specific and unspecified. A platform may not support backtraces at all. Libstd's backtrace type will do its best to report a backtrace to the caller of Backtrace::capture and Backtrace::force_capture.

Background and Motivation

This API was proposed as part of RFC 2504, which was merged in August 2018. The API was based on experience with the failure crate, released November 2017, and motivated by a longstanding user request for a standardized way to access backtraces, especially in connection with errors that have been raised. This API was implemented actually in September 2019.

In late 2019, many users began migrating from the failure crate to crates based on std::error::Error, because most of the API changes proposed in RFC 2504 had been stabilized, and new crates similar to failure but based on std Error had been implemented, most notably thiserror and anyhow by dtolnay. In early 2020, the failure crate was deprecated, and users were recommended to use anyhow and thiserror instead.

However, on stable, the user experience of anyhow and thiserror is not equivalent to the user experience of failure, because the backtrace component of RFC 2504 has not been stabilized. Some users have been left in the frustrating and confusing experience of watching the ecosystem move around them to a solution that does not have feature parity for them, because they were depending on the backtrace feature of failure. They are forced to either migrate from stable to nightly or manage compatibility issues with the rest of the ecosystem while staying on failure.

Even the anyhow crate only has meaningful backtraces with the backtrace feature of the crate turned on, which in turn depends on the backtrace feature of std.

Unresolved questions from RFC

One unresolved question was left over from the RFC regarding the API of capture: some proposed that rather than have backtraces which return a non-Captured status, the capture API return an Option. This was discussed at length on the RFC, and the RFC was ultimately merged with an unresolved question to confirm that the current design worked well. There has since been no discussion of that aspect of the RFC.

Two aspects complicate the idea of having a backtrace's non-pressence indicated with an option:

  • A backtrace can be absent for two reasons: the backtrace is disabled or the platform does not support backtraces. An Option could not represent that, requiring a new enum type, or a result and a new error type.
  • Use cases like Error::backtrace introduce a third reason a backtrace wouldn't be present: the concrete implementation did not try to capture a backtrace.

Combined we would be looking at an API like fn backtrace(&self) -> Option<&Result<Backtrace, BacktraceError>>, which becomes very unwieldy. For users who need to interrogate a backtrace's materiality, the BacktraceStatus provides a means of determining if the backtrace they've captured is not meaningful and why.

Issues raised during implementation period

Fmt representation #65280

Changes were made to the representation of the backtrace type, removing the header from the display representation & providing a debug implementation which is consistent with other Debug implementations.

However, #65280 also proposes providing a means of limiting the backtrace using something like the precision syntax. This has not been implemented. I propose that this is a desirable feature, but it is strictly add-on and it should not be a blocker on stabilizing backtrace.

Backtrace and Error in core

The main issue raised during implementation was the relationship of Error::backtrace and Error not being in core. The Error trait is already not in core for another reason: an inherent method on dyn Error requires the Box type, which is not in core, but stabilizing Error::backtrace would add a second dependence on a non-core type.

It is desirable for the Error trait to be available from core, and therefore users have expressed concern about adding a new dependency on a non-core type. However, this stabilization would not present any new challenge that could not be resolved as easily as the existing challenges:

  1. In order to add Error to core, we would need some "hook" that makes the non-core methods on Error not available in core, without breaking coherence. Such a "hook" could also be imagined for making the backtrace method not available in core.
  2. Alternatively (and probably better) we could make the backtrace type available in core, but its backtrace functionality disabled without std, with some hook to provide the platform-specific functionality that std fulfills, similar to global allocators, panic handlers, etc.
  3. Finally, we could do the proper thing and merge std and core into one library, instead of piling up an increasing tower of hacks to work aroud the misdesigned core/std split.

Because the existing issue with Error would already require a language-level change to allow std to add an inherent method to dyn Error, which multiple team members (me included) have expressed concern about doing, this does not seem to me to present a substantial increase in the amount of work needed to make Error available in core.

RFC 2895 and "generic member access"

Finally, there is the idea that RFC 2895 could supercede the Error::backtrace method. RFC 2895 provides an API for essentially a specialized dynamically dispatched "generic member" that errors could have, which is core-compatible. Such an API could then be used to provide the backtrace, or any other dynamically dispatched type, that an error could contain.

However, this RFC is not merged or in FCP, and is still in the early phases of design. We have already soft-regressed users, who have been relying on an existing API that has been in design for several years. Blocking the resolution of those users' problems on an RFC in early design stages would not be prudent.

The basic motivation of RFC 2895 is that it allows errors to provide many different kinds of contexts, not just a backtrace, and in a way which is open ended and extensible. This may be a desirable property for the std error trait, and RFC 2895 may eventually be merged, stabilized, etc. However, I would contend that even in such a case, preferential treatment for backtraces is still desirable. Backtraces are a standard feature provided not only in Rust but in many language ecosystems, which users have come to expect. Providing a first-class method for getting the backtrace, called backtrace, even if it delegates to a more generic "request for context" method in the long term, makes sense for the optimal user experience.

Future work

Other than the future work on the error trait discussed above, there is future work to be done on the backtrace type. In particular, the backtrace type currently provides no method of analysis other than debug and display printing the backtrace. It would be beneficial to provide a platform agnostic, standard API for iterating over the frames of the backtrace and the members of the frames in the long term. Such an API would justify a separate RFC.

@rust-highfive
Copy link
Collaborator

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 4, 2020
@withoutboats withoutboats added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 4, 2020
@withoutboats
Copy link
Contributor Author

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Jun 4, 2020

Team member @withoutboats has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jun 4, 2020
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 63'
Agent machine name: 'fv-az619'
Current agent version: '2.169.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200517.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200517.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/e446c02d-acba-487f-aa02-b37bd149c337.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/72981/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/72981/merge:refs/remotes/pull/72981/merge
---
 ---> 3adb0605cc65
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 28dbc326cb7f
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 537a01811900
Successfully built 537a01811900
Successfully tagged rust-ci:latest
Built container sha256:537a018119009dc218456238dec90b5530050db1e2a1e166550c218003f6159d
---
  local time: Thu Jun  4 14:24:29 UTC 2020
  network time: Thu, 04 Jun 2020 14:24:29 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/72981/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/72981/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (4890) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 64'
Agent machine name: 'fv-az578'
Current agent version: '2.169.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200517.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200517.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/94e0891a-004c-4369-a241-b52be08d447f.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/72981/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/72981/merge:refs/remotes/pull/72981/merge
---
 ---> 3adb0605cc65
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 28dbc326cb7f
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 537a01811900
Successfully built 537a01811900
Successfully tagged rust-ci:latest
Built container sha256:537a018119009dc218456238dec90b5530050db1e2a1e166550c218003f6159d
---
    Checking rustc_feature v0.0.0 (/checkout/src/librustc_feature)
    Checking fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
    Checking rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
    Checking rustc_hir v0.0.0 (/checkout/src/librustc_hir)
    Checking rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
    Checking chalk-rust-ir v0.10.0
    Checking rustc_parse v0.0.0 (/checkout/src/librustc_parse)
    Checking rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
    Checking rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---

error: could not compile `rustc_middle`.

To learn more, run the command again with --verbose.
command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--color" "always" "--features" " llvm" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json-render-diagnostics"
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
Build completed unsuccessfully in 0:04:50
== clock drift check ==
  local time: Thu Jun  4 14:34:56 UTC 2020
  local time: Thu Jun  4 14:34:56 UTC 2020
  network time: Thu, 04 Jun 2020 14:35:01 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/72981/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/72981/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (3856) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@SimonSapin
Copy link
Contributor

Thanks for the write-up! The one thing I would add is trait impls to the list of stabilized APIs. impl Display for Backtrace in particular is important since (as far as I can tell) it is the expected way to do anything useful with a Backtrace.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jun 4, 2020
@rfcbot
Copy link

rfcbot commented Jun 4, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@withoutboats
Copy link
Contributor Author

@bors r- (just noting this until end of full final comment period, so non team members can raise concerns)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 4, 2020
@kennytm
Copy link
Member

kennytm commented Jun 4, 2020

cc @yaahc rust-lang/rfcs#2895

@kennytm kennytm added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 4, 2020
@Amanieu
Copy link
Member

Amanieu commented Jun 4, 2020

The comments on how the Error trait can be supported in core are still quite vague and I am still unconvinced that stabilizing the backtrace function on the Error trait won't permanently prevent Error from being added to core.

I would like to see an implementation or at least a detailed design of the hooks that would enable backtrace support in libcore before we stabilize this.

@rfcbot concern Error in core

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jun 4, 2020
@withoutboats
Copy link
Contributor Author

withoutboats commented Jun 4, 2020

I am still unconvinced that stabilizing the backtrace function on the Error trait won't permanently prevent Error from being added to core.

Can you provide a positive statement of why the backtrace functionality would provide some unique difficulty? Asking others to prove a negative feels unfair.

I'm certainly not going to design hooks for this, though I think they would be useful even beyond getting this stabilized (presumably embedded devs do actually want backtraces and can sometimes have them). It's a big project it's not on anyone's roadmap. Meanwhile, real users are currently regressed.

The inherent impl issue is a much bigger blocker for moving Error to core. Despite the claim that we could "hack coherence" around it being accepted as a handwave solution, @sfackler has expressed concern about actually doing this and I agree. I certainly am not comfortable ending up in a situation where std defines inherent impls for core types, but they are separate crates, in any permanent capacity. I would be comfortable with that maybe only if it were strongly motivated by user need and coupled with an ongoing plan to merge core and std and remove the coherence hacks.

@yaahc
Copy link
Member

yaahc commented Jun 4, 2020

I would like to see an implementation or at least a detailed design of the hooks that would enable backtrace support in libcore before we stabilize this.

I'm would be happy to do a proof of concept to show how this would potentially work to verify that we could infact move Error to core to prove that it works. Am I correct though in assuming that this solution would still require coherence hacks for downcast? I want to make sure that @sfackler, @withoutboats, and anyone else who has expressed concern at such hacks is okay with the plan if we're planning on leaning on options 1 or 2.

Assuming we can show with reasonable confidence that we'd be able to move Error to core with fn backtrace I'm 100% onboard with this, I do agree that Backtrace will by far be the most used form of context for error reports captured by source errors, so it definitely makes sense to optimize for this.

@Amanieu
Copy link
Member

Amanieu commented Jun 4, 2020

My main concern that that this would require the Backtrace type to be in core, however this isn't possible since core is not allowed to depend on any other crate (in the case the backtrace crate).

@bstrie
Copy link
Contributor

bstrie commented Jan 25, 2021

To be clear, is the new proposal to fully stabilize std:::backtrace::Backtrace as it currently exists (implying that no changes need to be made to make it compatible with inclusion in core), while not yet stabilizing std::error::Error::backtrace?

@yaahc
Copy link
Member

yaahc commented Jan 25, 2021

To be clear, is the new proposal to fully stabilize std:::backtrace::Backtrace as it currently exists (implying that no changes need to be made to make it compatible with inclusion in core), while not yet stabilizing std::error::Error::backtrace?

Yes, because the only reason we currently have for moving Backtrace into core would be if it were added to the API of the Error trait. If we stabilize backtrace alone and find later reasons we cannot move it to core we will likely just revert the fn backtrace method on the error trait and rely on the Generic member access RFC for the same functionality.

@bjorn3
Copy link
Member

bjorn3 commented Jan 25, 2021

Could all methods to construct a backtrace be moved to an extension trait? That would make moving Backtrace to libcore much easier I think, but can't be done in a backwards compatible way later on.

@tmandry
Copy link
Member

tmandry commented Jan 26, 2021

One thing I haven't seen mentioned here is using the Backtrace API in signal handlers. It'd be extremely useful to have it there, especially for SIGSEGV and SIGABRT when you are doing a bunch of FFI with a memory-unsafe language. For example, #79153 is about handling this in the compiler.

Since signal handlers can't allocate, I think this boils down to having a core API.

@sfackler
Copy link
Member

That would also require the unwinder itself to be async signal safe, which this libunwind is, but I don't think that's specified to be the case for the C++ ABI unwinder that backtrace uses right now.

@KodrAus
Copy link
Contributor

KodrAus commented Jan 27, 2021

We discussed this at the recent Libs meeting and came to the conclusion that stabilizing Backtrace without Error::backtrace wouldn't be a useful direction, given that Backtrace is designed around being carried alongside Errors. So for now we can consider the stabilization blocked pending figuring out the last bits of what a pluggable (whether stably or not) backtrace would look like.

We can move design discussion over to #77384

@KodrAus KodrAus added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Jan 27, 2021
@bors
Copy link
Contributor

bors commented Feb 2, 2021

☔ The latest upstream changes (presumably #81660) made this pull request unmergeable. Please resolve the merge conflicts.

@m-ou-se m-ou-se removed I-nominated S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. labels Feb 10, 2021
dalcde added a commit to SpectralSequences/sseq that referenced this pull request Feb 27, 2021
This replaces the backtrace crate and removes quite a few recursive
dependencies. There was a proposal to stabilize backtrace, but it was
decided that it is better to wait until the interface with the Error
trait is decided. See
rust-lang/rust#72981
@jyn514
Copy link
Member

jyn514 commented Jul 7, 2021

We discussed this at the recent Libs meeting and came to the conclusion that stabilizing Backtrace without Error::backtrace wouldn't be a useful direction, given that Backtrace is designed around being carried alongside Errors. So for now we can consider the stabilization blocked pending figuring out the last bits of what a pluggable (whether stably or not) backtrace would look like.

I have a use case for Backtrace without Error: I want to print the stack in a panic handler.

@yaahc
Copy link
Member

yaahc commented Jul 7, 2021

We discussed this at the recent Libs meeting and came to the conclusion that stabilizing Backtrace without Error::backtrace wouldn't be a useful direction, given that Backtrace is designed around being carried alongside Errors. So for now we can consider the stabilization blocked pending figuring out the last bits of what a pluggable (whether stably or not) backtrace would look like.

I have a use case for Backtrace without Error: I want to print the stack in a panic handler.

I've nominated this for discussion but my first instinct is to suggest using backtrace-rs in this case. Is there a reason you need to use the std::backtrace::Backtrace type specifically?

@jyn514
Copy link
Member

jyn514 commented Jul 7, 2021

I guess backtrace would work. It would be nice to avoid the extra dependency.

Is the API for Backtrace still in flux? Or is it unstable only because Error is unstable?

@yaahc
Copy link
Member

yaahc commented Jul 8, 2021

I guess backtrace would work. It would be nice to avoid the extra dependency.

Is the API for Backtrace still in flux? Or is it unstable only because Error is unstable?

its still theoretically in flux, in case we decide that the hook based option for exposing the interface from core is not viable we could theoretically switch to a Backtrace trait object for the return type in the Error trait function, though at this point that seems unlikely.

@joshtriplett
Copy link
Member

We discussed this in today's @rust-lang/libs-api meeting. We felt that we should defer this to allow for a broader recommendation (encompassing this and other things) from the error-handling group, and we felt that there's currently a viable solution available (the backtrace crate). Given that, we don't want to stabilize this at this time.

@jonas-schievink jonas-schievink added the relnotes Marks issues that should be documented in the release notes of the next release. label Jul 17, 2021
@tbodt tbodt mentioned this pull request Jul 21, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 10, 2022
Stabilize backtrace

This PR stabilizes the std::backtrace module. As of rust-lang#99431, the std::Error::backtrace item has been removed, and so the rest of the backtrace feature is set to be stabilized.

Previous discussion can be found in rust-lang#72981, rust-lang#3156.

Stabilized API summary:
```rust
pub mod std {
    pub mod backtrace {
        pub struct Backtrace { }
        pub enum BacktraceStatus {
            Unsupported,
            Disabled,
            Captured,
        }
        impl fmt::Debug for Backtrace {}
        impl Backtrace {
            pub fn capture() -> Backtrace;
            pub fn force_capture() -> Backtrace;
            pub const fn disabled() -> Backtrace;
            pub fn status(&self) -> BacktraceStatus;
        }
        impl fmt::Display for Backtrace {}
    }
}
```

`@yaahc`
@daxpedda
Copy link
Contributor

I believe now that #99573 is merged, this can be closed?

@yaahc yaahc closed this Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PG-error-handling Project group: Error handling (https://github.com/rust-lang/project-error-handling) relnotes Marks issues that should be documented in the release notes of the next release. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.