From c01ceafc879dfe29482fe33eb3f1d614ad27415e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 29 Feb 2020 20:47:26 -0800 Subject: [PATCH 01/10] Update ui tests to nightly-2020-03-01 --- tests/ui/no-impl.stderr | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/ui/no-impl.stderr b/tests/ui/no-impl.stderr index ab1d72c..be95737 100644 --- a/tests/ui/no-impl.stderr +++ b/tests/ui/no-impl.stderr @@ -1,16 +1,21 @@ error[E0599]: no method named `anyhow_kind` found for reference `&Error` in the current scope --> $DIR/no-impl.rs:7:13 | +4 | struct Error; + | ------------- + | | + | doesn't satisfy `Error: anyhow::kind::TraitKind` + | doesn't satisfy `Error: std::convert::Into` + | doesn't satisfy `Error: std::fmt::Display` +... 7 | let _ = anyhow!(Error); | ^^^^^^^^^^^^^^ method not found in `&Error` | = note: the method `anyhow_kind` exists but the following trait bounds were not satisfied: - `&Error : anyhow::kind::AdhocKind` - `&Error : anyhow::kind::TraitKind` - `Error : anyhow::kind::TraitKind` - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following traits define an item `anyhow_kind`, perhaps you need to implement one of them: - candidate #1: `anyhow::kind::AdhocKind` - candidate #2: `anyhow::kind::TraitKind` - candidate #3: `anyhow::kind::BoxedKind` + `Error: std::convert::Into` + which is required by `Error: anyhow::kind::TraitKind` + `Error: std::fmt::Display` + which is required by `&Error: anyhow::kind::AdhocKind` + `&Error: std::convert::Into` + which is required by `&Error: anyhow::kind::TraitKind` = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) From 4bebd2ab1ea2406731316ce28060e1965531d0d4 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Mar 2020 13:13:02 -0700 Subject: [PATCH 02/10] Explain backtrace env variable combinations --- README.md | 12 ++++++++++-- src/error.rs | 12 ++++++++++-- src/lib.rs | 13 +++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 16c0b42..f434e34 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,16 @@ anyhow = "1.0" ``` - 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, the - `RUST_LIB_BACKTRACE=1` environment variable must be defined. + 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`; + - If you want only errors to have backtraces, set `RUST_LIB_BACKTRACE=1`; + - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and + `RUST_LIB_BACKTRACE=0`. + + [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables - Anyhow works with any error type that has an impl of `std::error::Error`, including ones defined in your crate. We do not bundle a `derive(Error)` macro diff --git a/src/error.rs b/src/error.rs index 88526df..fbb8379 100644 --- a/src/error.rs +++ b/src/error.rs @@ -290,11 +290,19 @@ impl Error { /// Backtraces are only available on the nightly channel. Tracking issue: /// [rust-lang/rust#53487][tracking]. /// - /// In order for the backtrace to be meaningful, the environment variable - /// `RUST_LIB_BACKTRACE=1` must be defined. Backtraces are somewhat + /// In order for the backtrace to be meaningful, one of the two environment + /// variables `RUST_LIB_BACKTRACE=1` or `RUST_BACKTRACE=1` must be defined + /// and `RUST_LIB_BACKTRACE` must not be `0`. Backtraces are somewhat /// expensive to capture in Rust, so we don't necessarily want to be /// capturing them all over the place all the time. /// + /// - If you want panics and errors to both have backtraces, set + /// `RUST_BACKTRACE=1`; + /// - If you want only errors to have backtraces, set + /// `RUST_LIB_BACKTRACE=1`; + /// - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and + /// `RUST_LIB_BACKTRACE=0`. + /// /// [tracking]: https://github.com/rust-lang/rust/issues/53487 #[cfg(backtrace)] pub fn backtrace(&self) -> &Backtrace { diff --git a/src/lib.rs b/src/lib.rs index 39bd6a0..98f1aba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,8 +121,17 @@ //! ``` //! //! - 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, the -//! `RUST_LIB_BACKTRACE=1` environment variable must be defined. +//! 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`; +//! - If you want only errors to have backtraces, set `RUST_LIB_BACKTRACE=1`; +//! - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and +//! `RUST_LIB_BACKTRACE=0`. +//! +//! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables //! //! - Anyhow works with any error type that has an impl of `std::error::Error`, //! including ones defined in your crate. We do not bundle a `derive(Error)` From 44262533332575244fdfe02e0fe0d4cc60c717de Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Mar 2020 13:30:25 -0700 Subject: [PATCH 03/10] Disable dev dependency on futures executor All we need in the example code is futures::stream. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f0c1f8f..e872025 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ default = ["std"] std = [] [dev-dependencies] -futures = "0.3" +futures = { version = "0.3", default-features = false } rustversion = "1.0" thiserror = "1.0" trybuild = { version = "1.0.19", features = ["diff"] } From e7702aa4fcf38372c72d0a3e59741076dccd9236 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Mar 2020 13:36:20 -0700 Subject: [PATCH 04/10] Release 1.0.27 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e872025..fca13b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anyhow" -version = "1.0.26" # remember to update html_root_url +version = "1.0.27" # remember to update html_root_url authors = ["David Tolnay "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index 98f1aba..57cbf2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -186,7 +186,7 @@ //! will require an explicit `.map_err(Error::msg)` when working with a //! non-Anyhow error type inside a function that returns Anyhow's error type. -#![doc(html_root_url = "https://docs.rs/anyhow/1.0.26")] +#![doc(html_root_url = "https://docs.rs/anyhow/1.0.27")] #![cfg_attr(backtrace, feature(backtrace))] #![cfg_attr(not(feature = "std"), no_std)] #![allow( From ffc45d2d4246f2e2da458b05d5e3383556654523 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 17 Mar 2020 13:27:25 -0700 Subject: [PATCH 05/10] Select a single docs.rs build target --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index fca13b2..3891e39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,6 @@ futures = { version = "0.3", default-features = false } rustversion = "1.0" thiserror = "1.0" trybuild = { version = "1.0.19", features = ["diff"] } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] From a07b84b641c9eb1e147e7efde110e686e1eb2195 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Thu, 19 Mar 2020 22:31:33 -0700 Subject: [PATCH 06/10] Mention nightly in module docs --- README.md | 4 ++++ src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index f434e34..bad055f 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,11 @@ anyhow = "1.0" - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and `RUST_LIB_BACKTRACE=0`. + Backtraces are only available on the nightly channel. Tracking issue: + [rust-lang/rust#53487][tracking]. + [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables + [tracking]: https://github.com/rust-lang/rust/issues/53487 - Anyhow works with any error type that has an impl of `std::error::Error`, including ones defined in your crate. We do not bundle a `derive(Error)` macro diff --git a/src/lib.rs b/src/lib.rs index 57cbf2f..fc4335a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,7 +131,11 @@ //! - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and //! `RUST_LIB_BACKTRACE=0`. //! +//! Backtraces are only available on the nightly channel. Tracking issue: +//! [rust-lang/rust#53487][tracking]. +//! //! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables +//! [tracking]: https://github.com/rust-lang/rust/issues/53487 //! //! - Anyhow works with any error type that has an impl of `std::error::Error`, //! including ones defined in your crate. We do not bundle a `derive(Error)` From e46df9f4a55104dc19674360f148c4c2eb491bf0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 19 Mar 2020 23:08:52 -0700 Subject: [PATCH 07/10] Rephrase nightly backtrace note --- README.md | 12 ++++++------ src/lib.rs | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index bad055f..d27d008 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,10 @@ anyhow = "1.0" } ``` -- 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 the nightly channel, 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`; @@ -84,11 +85,10 @@ anyhow = "1.0" - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and `RUST_LIB_BACKTRACE=0`. - Backtraces are only available on the nightly channel. Tracking issue: - [rust-lang/rust#53487][tracking]. + The tracking issue for this feature is [rust-lang/rust#53487]. [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables - [tracking]: https://github.com/rust-lang/rust/issues/53487 + [rust-lang/rust#53487]: https://github.com/rust-lang/rust/issues/53487 - Anyhow works with any error type that has an impl of `std::error::Error`, including ones defined in your crate. We do not bundle a `derive(Error)` macro diff --git a/src/lib.rs b/src/lib.rs index fc4335a..436dec6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,10 +120,10 @@ //! # ; //! ``` //! -//! - 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 the nightly channel, 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`; @@ -131,11 +131,10 @@ //! - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and //! `RUST_LIB_BACKTRACE=0`. //! -//! Backtraces are only available on the nightly channel. Tracking issue: -//! [rust-lang/rust#53487][tracking]. +//! The tracking issue for this feature is [rust-lang/rust#53487]. //! //! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables -//! [tracking]: https://github.com/rust-lang/rust/issues/53487 +//! [rust-lang/rust#53487]: https://github.com/rust-lang/rust/issues/53487 //! //! - Anyhow works with any error type that has an impl of `std::error::Error`, //! including ones defined in your crate. We do not bundle a `derive(Error)` From d65ec5ed2fdba6e56f6bea831bb3180e056161af Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 30 Mar 2020 16:15:30 -0700 Subject: [PATCH 08/10] Use doc_cfg to mark Error::new --- Cargo.toml | 1 + src/error.rs | 1 + src/lib.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3891e39..e4bac0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,4 @@ trybuild = { version = "1.0.19", features = ["diff"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] +rustdoc-args = ["--cfg", "doc_cfg"] diff --git a/src/error.rs b/src/error.rs index fbb8379..80d879f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,6 +19,7 @@ impl Error { /// If the error type does not provide a backtrace, a backtrace will be /// created here to ensure that a backtrace exists. #[cfg(feature = "std")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub fn new(error: E) -> Self where E: StdError + Send + Sync + 'static, diff --git a/src/lib.rs b/src/lib.rs index 436dec6..5d72288 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,6 +191,7 @@ #![doc(html_root_url = "https://docs.rs/anyhow/1.0.27")] #![cfg_attr(backtrace, feature(backtrace))] +#![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(not(feature = "std"), no_std)] #![allow( clippy::needless_doctest_main, From 022f700a1c67c5cd663c34b8a3c11c6818ec0ecb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 30 Mar 2020 16:21:57 -0700 Subject: [PATCH 09/10] Release 1.0.28 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4bac0e..011c7c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anyhow" -version = "1.0.27" # remember to update html_root_url +version = "1.0.28" # remember to update html_root_url authors = ["David Tolnay "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index 5d72288..c6694ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -189,7 +189,7 @@ //! will require an explicit `.map_err(Error::msg)` when working with a //! non-Anyhow error type inside a function that returns Anyhow's error type. -#![doc(html_root_url = "https://docs.rs/anyhow/1.0.27")] +#![doc(html_root_url = "https://docs.rs/anyhow/1.0.28")] #![cfg_attr(backtrace, feature(backtrace))] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(not(feature = "std"), no_std)] From 150abf1270f0ed121e22c94e4333940bb30bedb5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 23 Apr 2020 10:36:31 -0700 Subject: [PATCH 10/10] Run clippy on latest nightly that has clippy --- .travis.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f1b4c7f..bdf66ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,12 @@ matrix: script: cargo check - rust: 1.36.0 script: cargo check --no-default-features - - rust: nightly - name: Clippy + - name: Clippy + install: + - CLIPPY_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/clippy) + - echo "Latest nightly with Clippy is $CLIPPY_NIGHTLY" + - rustup set profile minimal + - rustup default "$CLIPPY_NIGHTLY" + - rustup component add clippy script: - - rustup component add clippy || travis_terminate 0 - cargo clippy -- -Dclippy::all