-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Conversation
/// | ||
/// 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. | ||
/// |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
4a1868c
to
49eeec1
Compare
@dtolnay any chance of getting this merged? |
This crate in unusable for stable Rust in debug mode, but works in stable Rust release mode. Can we just finally make it possible? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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 thebacktrace
crate, so for 1.65+ compilers, enabling thebacktrace
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 thatstd::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
andcargo 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.