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

Enable backtrace support for >= 1.65 stable compilers #293

Merged
merged 1 commit into from
Dec 26, 2023

Conversation

LukasKalbertodt
Copy link
Contributor

Fixes #284

The std::backtrace APIs relevant for this crate were stabilized in 1.65. This commit makes anyhow use those API if possible. std::backtrace is preferred over the backtrace crate, so for 1.65+ compilers, enabling the backtrace crate feature does nothing essentially (except downloading the dependency, so don't do that).

Previously, when a nightly compiler was used, use of std::backtrace as well as the Provider API was enabled. This PR separates those two APIs such that std::backtrace is used for nightly OR 1.65+ stable compilers; and the Provider API is used for nightly compilers only.


I tested this for 1.64, 1.65, the current stable and the current nightly. For all, cargo test and cargo test --features=backtrace runs fine. I also wanted to test for older nightlies (which do not support the various APIs yet) but I couldn't get it to work as dependencies did not compile. It seems like everyone seems to only support the latest nightly. Which makes sense. So I assumed I could do the same here.

This also means that in my doc changes I simply say "for Rust >= 1.65" and don't mention nightly anymore, as that's "implied" if only the latest nightly is supported anyway.

I am not sure if this is the best approach. There are lots of options how to fix #284 I think. I like my approach as it results in a fairly small diff, does not bump the MSRV to 1.65, and still works for nightly (also enabling the provide API then). But I'm curious if you'd like this to use a different approach.

///
/// On stable compilers, this function is only available if the crate's
/// Standard library backtraces are only available when using Rust ≥ 1.65.
/// On older compilers, this function is only available if the crate's
/// "backtrace" feature is enabled, and will use the `backtrace` crate as
/// the underlying backtrace implementation.
///
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few lines down there is:

#[cfg_attr(doc_cfg, doc(cfg(any(nightly, feature = "backtrace"))))]

I don't know how to replace that :/
any(>=1.65, feature = "backtrace") surely won't work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose an alternative would be bumping the MSRV? (And maybe bumping the Rust edition as well)

The `std::backtrace` APIs relevant for this crate were stabilized in
1.65. This commit makes anyhow use those API if possible.
`std::backtrace` is preferred over the `backtrace` crate, so for 1.65+
compilers, enabling the `backtrace` crate feature does nothing
essentially.

Previously, when a nightly compiler was used, use of `std::backtrace`
as well as the Provider API was enabled. This commit separates those
two APIs such that `std::backtrace` is used for nightly OR 1.65+ stable
compilers; and the Provider API is used for nightly compilers only.
@bruwozniak
Copy link

@dtolnay any chance of getting this merged?

@iddm
Copy link

iddm commented Nov 17, 2023

This crate in unusable for stable Rust in debug mode, but works in stable Rust release mode. Can we just finally make it possible?

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit d6acd22 into dtolnay:master Dec 26, 2023
@LukasKalbertodt LukasKalbertodt deleted the use-stable-backtrace branch December 28, 2023 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use std::backtrace::Backtrace even on the stable channel
5 participants