diff --git a/Cargo.toml b/Cargo.toml index 59b7b30..f5ae7cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,10 @@ default = ["std"] std = [] [dependencies] +# On compilers older than 1.65, features=["backtrace"] may be used to enable +# backtraces via the `backtrace` crate. This feature has no effect on 1.65+ +# besides bringing in an unused dependency, as `std::backtrace` is always +# preferred. backtrace = { version = "0.3.51", optional = true } [dev-dependencies] diff --git a/README.md b/README.md index a863cab..ccf3097 100644 --- a/README.md +++ b/README.md @@ -75,10 +75,10 @@ anyhow = "1.0" } ``` -- If using Rust ≥ 1.65 or `features = ["backtrace"]`, a backtrace is captured - and printed with the error if the underlying error type does not already - provide its own. In order to see backtraces, they must be enabled through the - environment variables described in [`std::backtrace`]: +- If using Rust ≥ 1.65, a backtrace is captured and printed with the error if + the underlying error type does not already provide its own. In order to see + backtraces, they must be enabled through the environment variables described + in [`std::backtrace`]: - If you want panics and errors to both have backtraces, set `RUST_BACKTRACE=1`; diff --git a/src/error.rs b/src/error.rs index 9aa2253..f24c4a6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -363,17 +363,17 @@ impl Error { /// /// # Stability /// - /// Standard library backtraces are only available when using Rust ≥ 1.65. - /// On older 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. + /// the underlying backtrace implementation. The return type of this + /// function on old compilers is `&(impl Debug + Display)`. /// /// ```toml /// [dependencies] /// anyhow = { version = "1.0", features = ["backtrace"] } /// ``` #[cfg(any(std_backtrace, feature = "backtrace"))] - #[cfg_attr(doc_cfg, doc(cfg(any(nightly, feature = "backtrace"))))] pub fn backtrace(&self) -> &impl_backtrace!() { unsafe { ErrorImpl::backtrace(self.inner.by_ref()) } } diff --git a/src/lib.rs b/src/lib.rs index 5d25310..c00baf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,10 +128,10 @@ //! # ; //! ``` //! -//! - If using Rust ≥ 1.65 or `features = ["backtrace"]`, a backtrace is captured -//! and printed with the error if the underlying error type does not already -//! provide its own. In order to see backtraces, they must be enabled through the -//! environment variables described in [`std::backtrace`]: +//! - If using Rust ≥ 1.65, a backtrace is captured and printed with the +//! error if the underlying error type does not already provide its own. In +//! order to see backtraces, they must be enabled through the environment +//! variables described in [`std::backtrace`]: //! //! - If you want panics and errors to both have backtraces, set //! `RUST_BACKTRACE=1`;