aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-12-29 20:32:39 -0800
committerHaibo Huang <hhb@google.com>2020-12-29 20:32:39 -0800
commitfb10bbc2d3d81849996d1e93c30a161a29eac663 (patch)
tree1309b4d74cfbc28a49e77d3e8f41d3d991335d6f
parent508dd7d7ef2aa2311a399ac13484ed84aa62c81b (diff)
downloadanyhow-fb10bbc2d3d81849996d1e93c30a161a29eac663.tar.gz
Upgrade rust/crates/anyhow to 1.0.37
Test: make Change-Id: Ibc6ae300f243375e5d9c9f6874f87e32c817c943
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA8
-rw-r--r--build.rs30
-rw-r--r--src/error.rs5
-rw-r--r--src/lib.rs27
-rw-r--r--src/macros.rs11
-rw-r--r--tests/test_ffi.rs18
-rw-r--r--tests/test_macros.rs9
-rw-r--r--tests/ui/temporary-value.rs5
-rw-r--r--tests/ui/temporary-value.stderr8
12 files changed, 112 insertions, 15 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 3a340ff..6c073fd 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "99c982128458fecb8d1d7aff9478dd77dac0ee3b"
+ "sha1": "d1ba145c92f8b690c4517f396af2677b08a28288"
}
}
diff --git a/Cargo.toml b/Cargo.toml
index e60d650..cc9bf30 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "anyhow"
-version = "1.0.34"
+version = "1.0.37"
authors = ["David Tolnay <dtolnay@gmail.com>"]
description = "Flexible concrete Error type built on std::error::Error"
documentation = "https://docs.rs/anyhow"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index c6f0bd1..ad85232 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "anyhow"
-version = "1.0.34" # remember to update html_root_url
+version = "1.0.37" # remember to update html_root_url
authors = ["David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
diff --git a/METADATA b/METADATA
index c025753..c99f99b 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/anyhow/anyhow-1.0.34.crate"
+ value: "https://static.crates.io/crates/anyhow/anyhow-1.0.37.crate"
}
- version: "1.0.34"
+ version: "1.0.37"
license_type: NOTICE
last_upgrade_date {
year: 2020
- month: 11
- day: 2
+ month: 12
+ day: 29
}
}
diff --git a/build.rs b/build.rs
index d20b072..a7dc8f2 100644
--- a/build.rs
+++ b/build.rs
@@ -2,6 +2,7 @@ use std::env;
use std::fs;
use std::path::Path;
use std::process::{Command, ExitStatus, Stdio};
+use std::str;
// This code exercises the surface area that we expect of the std Backtrace
// type. If the current toolchain is able to compile it, we go ahead and use
@@ -35,12 +36,20 @@ const PROBE: &str = r#"
"#;
fn main() {
- if !cfg!(feature = "std") {
- return;
+ if cfg!(feature = "std") {
+ match compile_probe() {
+ Some(status) if status.success() => println!("cargo:rustc-cfg=backtrace"),
+ _ => {}
+ }
}
- match compile_probe() {
- Some(status) if status.success() => println!("cargo:rustc-cfg=backtrace"),
- _ => {}
+
+ let rustc = match rustc_minor_version() {
+ Some(rustc) => rustc,
+ None => return,
+ };
+
+ if rustc < 38 {
+ println!("cargo:rustc-cfg=anyhow_no_macro_reexport");
}
}
@@ -61,3 +70,14 @@ fn compile_probe() -> Option<ExitStatus> {
.status()
.ok()
}
+
+fn rustc_minor_version() -> Option<u32> {
+ let rustc = env::var_os("RUSTC")?;
+ let output = Command::new(rustc).arg("--version").output().ok()?;
+ let version = str::from_utf8(&output.stdout).ok()?;
+ let mut pieces = version.split('.');
+ if pieces.next() != Some("rustc 1") {
+ return None;
+ }
+ pieces.next()?.parse().ok()
+}
diff --git a/src/error.rs b/src/error.rs
index 5ee9e41..2618814 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -329,6 +329,7 @@ impl Error {
/// }
/// ```
#[cfg(feature = "std")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn chain(&self) -> Chain {
self.inner.chain()
}
@@ -339,6 +340,7 @@ impl Error {
/// The root cause is the last error in the iterator produced by
/// [`chain()`][Error::chain].
#[cfg(feature = "std")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn root_cause(&self) -> &(dyn StdError + 'static) {
self.chain().last().unwrap()
}
@@ -456,6 +458,7 @@ impl Error {
}
#[cfg(feature = "std")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl<E> From<E> for Error
where
E: StdError + Send + Sync + 'static,
@@ -467,6 +470,7 @@ where
}
#[cfg(feature = "std")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl Deref for Error {
type Target = dyn StdError + Send + Sync + 'static;
@@ -476,6 +480,7 @@ impl Deref for Error {
}
#[cfg(feature = "std")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl DerefMut for Error {
fn deref_mut(&mut self) -> &mut Self::Target {
self.inner.error_mut()
diff --git a/src/lib.rs b/src/lib.rs
index a6bb634..825cc87 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -209,7 +209,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.34")]
+#![doc(html_root_url = "https://docs.rs/anyhow/1.0.37")]
#![cfg_attr(backtrace, feature(backtrace))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
@@ -361,6 +361,7 @@ pub use anyhow as format_err;
/// # Ok(())
/// }
/// ```
+#[repr(transparent)]
pub struct Error {
inner: ManuallyDrop<Box<ErrorImpl<()>>>,
}
@@ -385,6 +386,7 @@ pub struct Error {
/// }
/// ```
#[cfg(feature = "std")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[derive(Clone)]
pub struct Chain<'a> {
state: crate::chain::ChainState<'a>,
@@ -621,4 +623,27 @@ pub mod private {
{
Error::from_adhoc(message, backtrace!())
}
+
+ #[cfg(anyhow_no_macro_reexport)]
+ pub use crate::{__anyhow_concat as concat, __anyhow_stringify as stringify};
+ #[cfg(not(anyhow_no_macro_reexport))]
+ pub use core::{concat, stringify};
+
+ #[cfg(anyhow_no_macro_reexport)]
+ #[doc(hidden)]
+ #[macro_export]
+ macro_rules! __anyhow_concat {
+ ($($tt:tt)*) => {
+ concat!($($tt)*)
+ };
+ }
+
+ #[cfg(anyhow_no_macro_reexport)]
+ #[doc(hidden)]
+ #[macro_export]
+ macro_rules! __anyhow_stringify {
+ ($($tt:tt)*) => {
+ stringify!($($tt)*)
+ };
+ }
}
diff --git a/src/macros.rs b/src/macros.rs
index c4b4c80..a0f4cae 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -113,6 +113,12 @@ macro_rules! bail {
/// ```
#[macro_export]
macro_rules! ensure {
+ ($cond:expr $(,)?) => {
+ $crate::ensure!(
+ $cond,
+ $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`"),
+ )
+ };
($cond:expr, $msg:literal $(,)?) => {
if !$cond {
return $crate::private::Err($crate::anyhow!($msg));
@@ -167,8 +173,9 @@ macro_rules! anyhow {
};
($err:expr $(,)?) => ({
use $crate::private::kind::*;
- let error = $err;
- (&error).anyhow_kind().new(error)
+ match $err {
+ error => (&error).anyhow_kind().new(error),
+ }
});
($fmt:expr, $($arg:tt)*) => {
$crate::private::new_adhoc(format!($fmt, $($arg)*))
diff --git a/tests/test_ffi.rs b/tests/test_ffi.rs
new file mode 100644
index 0000000..0321fc1
--- /dev/null
+++ b/tests/test_ffi.rs
@@ -0,0 +1,18 @@
+#![deny(improper_ctypes, improper_ctypes_definitions)]
+
+use anyhow::anyhow;
+
+#[no_mangle]
+pub extern "C" fn anyhow1(err: anyhow::Error) {
+ println!("{:?}", err);
+}
+
+#[no_mangle]
+pub extern "C" fn anyhow2(err: &mut Option<anyhow::Error>) {
+ *err = Some(anyhow!("ffi error"));
+}
+
+#[no_mangle]
+pub extern "C" fn anyhow3() -> Option<anyhow::Error> {
+ Some(anyhow!("ffi error"))
+}
diff --git a/tests/test_macros.rs b/tests/test_macros.rs
index eb1503f..dd66973 100644
--- a/tests/test_macros.rs
+++ b/tests/test_macros.rs
@@ -32,4 +32,13 @@ fn test_ensure() {
Ok(())
};
assert!(f().is_err());
+
+ let f = || {
+ ensure!(v + v == 1);
+ Ok(())
+ };
+ assert_eq!(
+ f().unwrap_err().to_string(),
+ "Condition failed: `v + v == 1`",
+ );
}
diff --git a/tests/ui/temporary-value.rs b/tests/ui/temporary-value.rs
new file mode 100644
index 0000000..803809b
--- /dev/null
+++ b/tests/ui/temporary-value.rs
@@ -0,0 +1,5 @@
+use anyhow::anyhow;
+
+fn main() {
+ let _ = anyhow!(&String::new());
+}
diff --git a/tests/ui/temporary-value.stderr b/tests/ui/temporary-value.stderr
new file mode 100644
index 0000000..fa753d2
--- /dev/null
+++ b/tests/ui/temporary-value.stderr
@@ -0,0 +1,8 @@
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/temporary-value.rs:4:22
+ |
+4 | let _ = anyhow!(&String::new());
+ | ---------^^^^^^^^^^^^^-- temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary which is freed while still in use
+ | argument requires that borrow lasts for `'static`