Snap for 8192848 from 21f2d70be2766bc2464ab26002d75ee9f24ca59f to tm-frc-os-statsd-release

Change-Id: I121e4a5368083f0e6ebf60e447710d946e0802cb
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 694bf81..e50dc09 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "704622f25d098b9e9925b93fbe2540745ff73f92"
+    "sha1": "6c97c59375b24dad08c624cf61d06338f4dc9c3e"
   }
 }
diff --git a/Android.bp b/Android.bp
index a1b2e3e..3df2e9b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -37,40 +37,34 @@
     ],
 }
 
-rust_defaults {
-    name: "anyhow_defaults",
+rust_test {
+    name: "anyhow_test_src_lib",
+    host_supported: true,
     crate_name: "anyhow",
+    cargo_env_compat: true,
+    cargo_pkg_version: "1.0.44",
     srcs: ["src/lib.rs"],
     test_suites: ["general-tests"],
     auto_gen_config: true,
+    test_options: {
+        unit_test: true,
+    },
     edition: "2018",
     features: [
         "default",
         "std",
     ],
-    cfgs: ["backtrace"],
     rustlibs: [
         "libfutures",
         "libthiserror",
     ],
 }
 
-rust_test_host {
-    name: "anyhow_host_test_src_lib",
-    defaults: ["anyhow_defaults"],
-    test_options: {
-        unit_test: true,
-    },
-}
-
-rust_test {
-    name: "anyhow_device_test_src_lib",
-    defaults: ["anyhow_defaults"],
-}
-
 rust_defaults {
-    name: "anyhow_defaults_anyhow",
+    name: "anyhow_test_defaults",
     crate_name: "anyhow",
+    cargo_env_compat: true,
+    cargo_pkg_version: "1.0.44",
     test_suites: ["general-tests"],
     auto_gen_config: true,
     edition: "2018",
@@ -78,7 +72,6 @@
         "default",
         "std",
     ],
-    cfgs: ["backtrace"],
     rustlibs: [
         "libanyhow",
         "libfutures",
@@ -86,9 +79,10 @@
     ],
 }
 
-rust_test_host {
-    name: "anyhow_host_test_tests_test_autotrait",
-    defaults: ["anyhow_defaults_anyhow"],
+rust_test {
+    name: "anyhow_test_tests_test_autotrait",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_autotrait.rs"],
     test_options: {
         unit_test: true,
@@ -96,14 +90,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_autotrait",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_autotrait.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_boxed",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_boxed",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_boxed.rs"],
     test_options: {
         unit_test: true,
@@ -111,14 +100,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_boxed",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_boxed.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_chain",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_chain",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_chain.rs"],
     test_options: {
         unit_test: true,
@@ -126,14 +110,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_chain",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_chain.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_context",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_context",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_context.rs"],
     test_options: {
         unit_test: true,
@@ -141,14 +120,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_context",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_context.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_convert",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_convert",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_convert.rs"],
     test_options: {
         unit_test: true,
@@ -156,14 +130,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_convert",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_convert.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_downcast",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_downcast",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_downcast.rs"],
     test_options: {
         unit_test: true,
@@ -171,29 +140,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_downcast",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_downcast.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_ffi",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_ffi.rs"],
-    test_options: {
-        unit_test: true,
-    },
-}
-
-rust_test {
-    name: "anyhow_device_test_tests_test_ffi",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_ffi.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_fmt",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_fmt",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_fmt.rs"],
     test_options: {
         unit_test: true,
@@ -201,14 +150,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_fmt",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_fmt.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_macros",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_macros",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_macros.rs"],
     test_options: {
         unit_test: true,
@@ -216,14 +160,9 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_macros",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_macros.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_repr",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_repr",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_repr.rs"],
     test_options: {
         unit_test: true,
@@ -231,70 +170,35 @@
 }
 
 rust_test {
-    name: "anyhow_device_test_tests_test_repr",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_repr.rs"],
-}
-
-rust_test_host {
-    name: "anyhow_host_test_tests_test_source",
-    defaults: ["anyhow_defaults_anyhow"],
+    name: "anyhow_test_tests_test_source",
+    defaults: ["anyhow_test_defaults"],
+    host_supported: true,
     srcs: ["tests/test_source.rs"],
     test_options: {
         unit_test: true,
     },
 }
 
-rust_test {
-    name: "anyhow_device_test_tests_test_source",
-    defaults: ["anyhow_defaults_anyhow"],
-    srcs: ["tests/test_source.rs"],
-}
-
 rust_library {
     name: "libanyhow",
     host_supported: true,
     crate_name: "anyhow",
+    cargo_env_compat: true,
+    cargo_pkg_version: "1.0.44",
     srcs: ["src/lib.rs"],
     edition: "2018",
     features: [
         "default",
         "std",
     ],
-    cfgs: ["backtrace"],
     apex_available: [
         "//apex_available:platform",
+        "com.android.bluetooth",
+        "com.android.compos",
         "com.android.resolv",
+        "com.android.uwb",
         "com.android.virt",
     ],
+    vendor_available: true,
     min_sdk_version: "29",
 }
-
-// dependent_library ["feature_list"]
-//   dissimilar-1.0.2
-//   futures-0.3.14
-//   futures-channel-0.3.14 "futures-sink,sink"
-//   futures-core-0.3.14
-//   futures-io-0.3.14
-//   futures-sink-0.3.14
-//   futures-task-0.3.14
-//   futures-util-0.3.14 "futures-sink,sink"
-//   glob-0.3.0
-//   itoa-0.4.7
-//   lazy_static-1.4.0
-//   pin-project-lite-0.2.6
-//   pin-utils-0.1.0
-//   proc-macro2-1.0.26 "default,proc-macro"
-//   quote-1.0.9 "default,proc-macro"
-//   rustversion-1.0.4
-//   ryu-1.0.5
-//   serde-1.0.125 "default,derive,serde_derive,std"
-//   serde_derive-1.0.125 "default"
-//   serde_json-1.0.64 "default,std"
-//   syn-1.0.70 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote"
-//   termcolor-1.1.2
-//   thiserror-1.0.24
-//   thiserror-impl-1.0.24
-//   toml-0.5.8 "default"
-//   trybuild-1.0.42 "diff,dissimilar"
-//   unicode-xid-0.2.1 "default"
diff --git a/Cargo.toml b/Cargo.toml
index 09c3dbf..881fc23 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,17 +3,16 @@
 # When uploading crates to the registry Cargo will automatically
 # "normalize" Cargo.toml files for maximal compatibility
 # with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
 #
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
 
 [package]
 edition = "2018"
 name = "anyhow"
-version = "1.0.40"
+version = "1.0.44"
 authors = ["David Tolnay <[email protected]>"]
 description = "Flexible concrete Error type built on std::error::Error"
 documentation = "https://docs.rs/anyhow"
@@ -25,7 +24,7 @@
 rustdoc-args = ["--cfg", "doc_cfg"]
 targets = ["x86_64-unknown-linux-gnu"]
 [dependencies.backtrace]
-version = "0.3"
+version = "0.3.51"
 optional = true
 [dev-dependencies.futures]
 version = "0.3"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index dca266a..97fe475 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "anyhow"
-version = "1.0.40" # remember to update html_root_url
+version = "1.0.44" # remember to update html_root_url
 authors = ["David Tolnay <[email protected]>"]
 edition = "2018"
 license = "MIT OR Apache-2.0"
@@ -15,7 +15,7 @@
 std = []
 
 [dependencies]
-backtrace = { version = "0.3", optional = true }
+backtrace = { version = "0.3.51", optional = true }
 
 [dev-dependencies]
 futures = { version = "0.3", default-features = false }
diff --git a/METADATA b/METADATA
index 5c77561..f97422f 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/anyhow/anyhow-1.0.40.crate"
+    value: "https://static.crates.io/crates/anyhow/anyhow-1.0.44.crate"
   }
-  version: "1.0.40"
+  version: "1.0.44"
   license_type: NOTICE
   last_upgrade_date {
     year: 2021
-    month: 4
-    day: 2
+    month: 9
+    day: 22
   }
 }
diff --git a/README.md b/README.md
index c6eb0f1..e10063f 100644
--- a/README.md
+++ b/README.md
@@ -75,10 +75,10 @@
   }
   ```
 
-- 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 using the nightly channel, or stable with `features = ["backtrace"]`, a
+  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/TEST_MAPPING b/TEST_MAPPING
index 2ef5af6..cb65989 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -2,49 +2,168 @@
 {
   "presubmit": [
     {
-      "name": "anyhow_device_test_tests_test_autotrait"
+      "name": "ZipFuseTest"
     },
     {
-      "name": "anyhow_device_test_tests_test_context"
+      "name": "anyhow_test_src_lib"
     },
     {
-      "name": "anyhow_device_test_tests_test_repr"
+      "name": "anyhow_test_tests_test_autotrait"
     },
     {
-      "name": "keystore2_test"
+      "name": "anyhow_test_tests_test_boxed"
     },
     {
-      "name": "anyhow_device_test_tests_test_chain"
+      "name": "anyhow_test_tests_test_chain"
     },
     {
-      "name": "anyhow_device_test_tests_test_fmt"
+      "name": "anyhow_test_tests_test_context"
     },
     {
-      "name": "anyhow_device_test_tests_test_convert"
+      "name": "anyhow_test_tests_test_convert"
     },
     {
-      "name": "anyhow_device_test_tests_test_downcast"
+      "name": "anyhow_test_tests_test_downcast"
     },
     {
-      "name": "anyhow_device_test_tests_test_macros"
+      "name": "anyhow_test_tests_test_fmt"
     },
     {
-      "name": "anyhow_device_test_tests_test_boxed"
+      "name": "anyhow_test_tests_test_macros"
+    },
+    {
+      "name": "anyhow_test_tests_test_repr"
+    },
+    {
+      "name": "anyhow_test_tests_test_source"
+    },
+    {
+      "name": "apkdmverity.test"
+    },
+    {
+      "name": "authfs_device_test_src_lib"
+    },
+    {
+      "name": "doh_unit_test"
+    },
+    {
+      "name": "keystore2_selinux_concurrency_test"
     },
     {
       "name": "keystore2_selinux_test"
     },
     {
-      "name": "anyhow_device_test_tests_test_source"
+      "name": "keystore2_test"
     },
     {
-      "name": "anyhow_device_test_src_lib"
+      "name": "keystore2_test_utils_test"
     },
     {
-      "name": "anyhow_device_test_tests_test_ffi"
+      "name": "keystore2_vintf_test"
     },
     {
-      "name": "vpnprofilestore_test"
+      "name": "legacykeystore_test"
+    },
+    {
+      "name": "libapkverify.integration_test"
+    },
+    {
+      "name": "libapkverify.test"
+    },
+    {
+      "name": "libidsig.test"
+    },
+    {
+      "name": "microdroid_manager_test"
+    },
+    {
+      "name": "open_then_run_module"
+    },
+    {
+      "name": "virtualizationservice_device_test"
+    }
+  ],
+  "presubmit-rust": [
+    {
+      "name": "ZipFuseTest"
+    },
+    {
+      "name": "anyhow_test_src_lib"
+    },
+    {
+      "name": "anyhow_test_tests_test_autotrait"
+    },
+    {
+      "name": "anyhow_test_tests_test_boxed"
+    },
+    {
+      "name": "anyhow_test_tests_test_chain"
+    },
+    {
+      "name": "anyhow_test_tests_test_context"
+    },
+    {
+      "name": "anyhow_test_tests_test_convert"
+    },
+    {
+      "name": "anyhow_test_tests_test_downcast"
+    },
+    {
+      "name": "anyhow_test_tests_test_fmt"
+    },
+    {
+      "name": "anyhow_test_tests_test_macros"
+    },
+    {
+      "name": "anyhow_test_tests_test_repr"
+    },
+    {
+      "name": "anyhow_test_tests_test_source"
+    },
+    {
+      "name": "apkdmverity.test"
+    },
+    {
+      "name": "authfs_device_test_src_lib"
+    },
+    {
+      "name": "doh_unit_test"
+    },
+    {
+      "name": "keystore2_selinux_concurrency_test"
+    },
+    {
+      "name": "keystore2_selinux_test"
+    },
+    {
+      "name": "keystore2_test"
+    },
+    {
+      "name": "keystore2_test_utils_test"
+    },
+    {
+      "name": "keystore2_vintf_test"
+    },
+    {
+      "name": "legacykeystore_test"
+    },
+    {
+      "name": "libapkverify.integration_test"
+    },
+    {
+      "name": "libapkverify.test"
+    },
+    {
+      "name": "libidsig.test"
+    },
+    {
+      "name": "microdroid_manager_test"
+    },
+    {
+      "name": "open_then_run_module"
+    },
+    {
+      "name": "virtualizationservice_device_test"
     }
   ]
 }
diff --git a/build.rs b/build.rs
index df2e73b..968e68f 100644
--- a/build.rs
+++ b/build.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::option_if_let_else)]
+
 use std::env;
 use std::fs;
 use std::path::Path;
@@ -67,17 +69,36 @@
     let out_dir = env::var_os("OUT_DIR")?;
     let probefile = Path::new(&out_dir).join("probe.rs");
     fs::write(&probefile, PROBE).ok()?;
-    Command::new(rustc)
-        .stderr(Stdio::null())
+
+    // Make sure to pick up Cargo rustc configuration.
+    let mut cmd = if let Some(wrapper) = env::var_os("CARGO_RUSTC_WRAPPER") {
+        let mut cmd = Command::new(wrapper);
+        // The wrapper's first argument is supposed to be the path to rustc.
+        cmd.arg(rustc);
+        cmd
+    } else {
+        Command::new(rustc)
+    };
+
+    cmd.stderr(Stdio::null())
         .arg("--edition=2018")
         .arg("--crate-name=anyhow_build")
         .arg("--crate-type=lib")
         .arg("--emit=metadata")
         .arg("--out-dir")
         .arg(out_dir)
-        .arg(probefile)
-        .status()
-        .ok()
+        .arg(probefile);
+
+    // If Cargo wants to set RUSTFLAGS, use that.
+    if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
+        if !rustflags.is_empty() {
+            for arg in rustflags.split('\x1f') {
+                cmd.arg(arg);
+            }
+        }
+    }
+
+    cmd.status().ok()
 }
 
 fn rustc_minor_version() -> Option<u32> {
diff --git a/cargo2android.json b/cargo2android.json
index e1dc8e8..0e4d86d 100644
--- a/cargo2android.json
+++ b/cargo2android.json
@@ -1,13 +1,25 @@
 {
   "apex-available": [
     "//apex_available:platform",
+    "com.android.bluetooth",
+    "com.android.compos",
     "com.android.resolv",
+    "com.android.uwb",
     "com.android.virt"
   ],
-  "min_sdk_version": "29",
   "dependencies": true,
+  "dependency-blocklist": [
+    "rustversion",
+    "syn",
+    "trybuild"
+  ],
   "device": true,
-  "patch": "patches/Android.bp.diff",
+  "min-sdk-version": "29",
   "run": true,
-  "tests": true
-}
\ No newline at end of file
+  "test-blocklist": [
+    "tests/compiletest.rs",
+    "tests/test_backtrace.rs"
+  ],
+  "tests": true,
+  "vendor-available": true
+}
diff --git a/patches/Android.bp.diff b/patches/Android.bp.diff
deleted file mode 100644
index 3745bac..0000000
--- a/patches/Android.bp.diff
+++ /dev/null
@@ -1,28 +0,0 @@
-diff --git a/Android.bp b/Android.bp
-index 1099708..a2e3476 100644
---- a/Android.bp
-+++ b/Android.bp
-@@ -54,11 +54,8 @@ rust_defaults {
-     ],
-     rustlibs: [
-         "libfutures",
--        "libsyn",
-         "libthiserror",
--        "libtrybuild",
-     ],
--    proc_macros: ["librustversion"],
- }
- 
- rust_test_host {
-@@ -91,11 +88,8 @@ rust_defaults {
-     rustlibs: [
-         "libanyhow",
-         "libfutures",
--        "libsyn",
-         "libthiserror",
--        "libtrybuild",
-     ],
--    proc_macros: ["librustversion"],
- }
- 
- rust_test_host {
diff --git a/patches/rustversion.diff b/patches/rustversion.diff
deleted file mode 100644
index 26d702d..0000000
--- a/patches/rustversion.diff
+++ /dev/null
@@ -1,22 +0,0 @@
-diff --git a/tests/test_backtrace.rs b/tests/test_backtrace.rs
-deleted file mode 100644
-index ce385f5..0000000
---- a/tests/test_backtrace.rs
-+++ /dev/null
-@@ -1,13 +0,0 @@
--#[rustversion::not(nightly)]
--#[ignore]
--#[test]
--fn test_backtrace() {}
--
--#[rustversion::nightly]
--#[test]
--fn test_backtrace() {
--    use anyhow::anyhow;
--
--    let error = anyhow!("oh no!");
--    let _ = error.backtrace();
--}
--- 
-2.30.0.478.g8a0d178c01-goog
-
diff --git a/patches/trybuild.diff b/patches/trybuild.diff
deleted file mode 100644
index 24df841..0000000
--- a/patches/trybuild.diff
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/tests/compiletest.rs b/tests/compiletest.rs
-deleted file mode 100644
-index 7974a62..0000000
---- a/tests/compiletest.rs
-+++ /dev/null
-@@ -1,7 +0,0 @@
--#[rustversion::attr(not(nightly), ignore)]
--#[cfg_attr(miri, ignore)]
--#[test]
--fn ui() {
--    let t = trybuild::TestCases::new();
--    t.compile_fail("tests/ui/*.rs");
--}
--- 
-2.30.0.478.g8a0d178c01-goog
-
diff --git a/src/chain.rs b/src/chain.rs
index 207e4f0..f7baff2 100644
--- a/src/chain.rs
+++ b/src/chain.rs
@@ -24,6 +24,7 @@
 }
 
 impl<'a> Chain<'a> {
+    #[cold]
     pub fn new(head: &'a (dyn StdError + 'static)) -> Self {
         Chain {
             state: ChainState::Linked { next: Some(head) },
diff --git a/src/error.rs b/src/error.rs
index f4f5bc2..3fa0835 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -25,6 +25,7 @@
     /// created here to ensure that a backtrace exists.
     #[cfg(feature = "std")]
     #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
+    #[cold]
     pub fn new<E>(error: E) -> Self
     where
         E: StdError + Send + Sync + 'static,
@@ -70,6 +71,7 @@
     ///         .await
     /// }
     /// ```
+    #[cold]
     pub fn msg<M>(message: M) -> Self
     where
         M: Display + Debug + Send + Sync + 'static,
@@ -78,6 +80,7 @@
     }
 
     #[cfg(feature = "std")]
+    #[cold]
     pub(crate) fn from_std<E>(error: E, backtrace: Option<Backtrace>) -> Self
     where
         E: StdError + Send + Sync + 'static,
@@ -100,6 +103,7 @@
         unsafe { Error::construct(error, vtable, backtrace) }
     }
 
+    #[cold]
     pub(crate) fn from_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> Self
     where
         M: Display + Debug + Send + Sync + 'static,
@@ -125,6 +129,7 @@
         unsafe { Error::construct(error, vtable, backtrace) }
     }
 
+    #[cold]
     pub(crate) fn from_display<M>(message: M, backtrace: Option<Backtrace>) -> Self
     where
         M: Display + Send + Sync + 'static,
@@ -151,6 +156,7 @@
     }
 
     #[cfg(feature = "std")]
+    #[cold]
     pub(crate) fn from_context<C, E>(context: C, error: E, backtrace: Option<Backtrace>) -> Self
     where
         C: Display + Send + Sync + 'static,
@@ -177,6 +183,7 @@
     }
 
     #[cfg(feature = "std")]
+    #[cold]
     pub(crate) fn from_boxed(
         error: Box<dyn StdError + Send + Sync>,
         backtrace: Option<Backtrace>,
@@ -207,6 +214,7 @@
     //
     // Unsafe because the given vtable must have sensible behavior on the error
     // value of type E.
+    #[cold]
     unsafe fn construct<E>(
         error: E,
         vtable: &'static ErrorVTable,
@@ -284,6 +292,7 @@
     ///     })
     /// }
     /// ```
+    #[cold]
     pub fn context<C>(self, context: C) -> Self
     where
         C: Display + Send + Sync + 'static,
@@ -373,6 +382,7 @@
     /// ```
     #[cfg(feature = "std")]
     #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
+    #[cold]
     pub fn chain(&self) -> Chain {
         unsafe { ErrorImpl::chain(self.inner.by_ref()) }
     }
@@ -515,6 +525,7 @@
 where
     E: StdError + Send + Sync + 'static,
 {
+    #[cold]
     fn from(error: E) -> Self {
         let backtrace = backtrace_if_absent!(error);
         Error::from_std(error, backtrace)
@@ -741,12 +752,11 @@
 where
     C: 'static,
 {
+    let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();
     if TypeId::of::<C>() == target {
-        let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();
         Some(Ref::new(&unerased._object.context).cast::<()>())
     } else {
         // Recurse down the context chain per the inner error's vtable.
-        let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();
         let source = &unerased._object.error;
         (vtable(source.inner.ptr).object_downcast)(source.inner.by_ref(), target)
     }
@@ -758,12 +768,11 @@
 where
     C: 'static,
 {
+    let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();
     if TypeId::of::<C>() == target {
-        let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();
         Some(Mut::new(&mut unerased._object.context).cast::<()>())
     } else {
         // Recurse down the context chain per the inner error's vtable.
-        let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();
         let source = &mut unerased._object.error;
         (vtable(source.inner.ptr).object_downcast_mut)(source.inner.by_mut(), target)
     }
@@ -881,6 +890,7 @@
             .expect("backtrace capture failed")
     }
 
+    #[cold]
     pub(crate) unsafe fn chain(this: Ref<Self>) -> Chain {
         Chain::new(Self::error(this))
     }
@@ -919,6 +929,7 @@
 }
 
 impl From<Error> for Box<dyn StdError + Send + Sync + 'static> {
+    #[cold]
     fn from(error: Error) -> Self {
         let outer = ManuallyDrop::new(error);
         unsafe {
diff --git a/src/kind.rs b/src/kind.rs
index eb8d604..5985705 100644
--- a/src/kind.rs
+++ b/src/kind.rs
@@ -62,6 +62,7 @@
 impl<T> AdhocKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {}
 
 impl Adhoc {
+    #[cold]
     pub fn new<M>(self, message: M) -> Error
     where
         M: Display + Debug + Send + Sync + 'static,
@@ -82,6 +83,7 @@
 impl<E> TraitKind for E where E: Into<Error> {}
 
 impl Trait {
+    #[cold]
     pub fn new<E>(self, error: E) -> Error
     where
         E: Into<Error>,
@@ -106,6 +108,7 @@
 
 #[cfg(feature = "std")]
 impl Boxed {
+    #[cold]
     pub fn new(self, error: Box<dyn StdError + Send + Sync>) -> Error {
         let backtrace = backtrace_if_absent!(error);
         Error::from_boxed(error, backtrace)
diff --git a/src/lib.rs b/src/lib.rs
index d6d70cf..2b7a0b1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -128,10 +128,11 @@
 //!   # ;
 //!   ```
 //!
-//! - 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 using the nightly channel, or stable with `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 you want panics and errors to both have backtraces, set
 //!     `RUST_BACKTRACE=1`;
@@ -209,7 +210,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.40")]
+#![doc(html_root_url = "https://docs.rs/anyhow/1.0.44")]
 #![cfg_attr(backtrace, feature(backtrace))]
 #![cfg_attr(doc_cfg, feature(doc_cfg))]
 #![cfg_attr(not(feature = "std"), no_std)]
@@ -625,6 +626,7 @@
         pub use crate::kind::BoxedKind;
     }
 
+    #[cold]
     pub fn new_adhoc<M>(message: M) -> Error
     where
         M: Display + Debug + Send + Sync + 'static,
diff --git a/tests/compiletest.rs b/tests/compiletest.rs
new file mode 100644
index 0000000..7974a62
--- /dev/null
+++ b/tests/compiletest.rs
@@ -0,0 +1,7 @@
+#[rustversion::attr(not(nightly), ignore)]
+#[cfg_attr(miri, ignore)]
+#[test]
+fn ui() {
+    let t = trybuild::TestCases::new();
+    t.compile_fail("tests/ui/*.rs");
+}
diff --git a/tests/test_backtrace.rs b/tests/test_backtrace.rs
new file mode 100644
index 0000000..ce385f5
--- /dev/null
+++ b/tests/test_backtrace.rs
@@ -0,0 +1,13 @@
+#[rustversion::not(nightly)]
+#[ignore]
+#[test]
+fn test_backtrace() {}
+
+#[rustversion::nightly]
+#[test]
+fn test_backtrace() {
+    use anyhow::anyhow;
+
+    let error = anyhow!("oh no!");
+    let _ = error.backtrace();
+}
diff --git a/tests/test_boxed.rs b/tests/test_boxed.rs
index 38a568f..fb1fb13 100644
--- a/tests/test_boxed.rs
+++ b/tests/test_boxed.rs
@@ -1,3 +1,8 @@
+#![allow(
+    // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
+    clippy::nonstandard_macro_braces,
+)]
+
 use anyhow::anyhow;
 use std::error::Error as StdError;
 use std::io;
diff --git a/tests/test_chain.rs b/tests/test_chain.rs
index b1c5a3d..12fd472 100644
--- a/tests/test_chain.rs
+++ b/tests/test_chain.rs
@@ -1,4 +1,4 @@
-use anyhow::{anyhow, Error};
+use anyhow::{anyhow, Chain, Error};
 
 fn error() -> Error {
     anyhow!(0).context(1).context(2).context(3)
@@ -33,13 +33,36 @@
     let e = error();
     let mut chain = e.chain();
     assert_eq!(4, chain.len());
+    assert_eq!((4, Some(4)), chain.size_hint());
     assert_eq!("3", chain.next().unwrap().to_string());
     assert_eq!(3, chain.len());
+    assert_eq!((3, Some(3)), chain.size_hint());
     assert_eq!("0", chain.next_back().unwrap().to_string());
     assert_eq!(2, chain.len());
+    assert_eq!((2, Some(2)), chain.size_hint());
     assert_eq!("2", chain.next().unwrap().to_string());
     assert_eq!(1, chain.len());
+    assert_eq!((1, Some(1)), chain.size_hint());
     assert_eq!("1", chain.next_back().unwrap().to_string());
     assert_eq!(0, chain.len());
+    assert_eq!((0, Some(0)), chain.size_hint());
     assert!(chain.next().is_none());
 }
+
+#[test]
+fn test_default() {
+    let mut c = Chain::default();
+    assert!(c.next().is_none());
+}
+
+#[test]
+fn test_clone() {
+    let e = error();
+    let mut chain = e.chain().clone();
+    assert_eq!("3", chain.next().unwrap().to_string());
+    assert_eq!("2", chain.next().unwrap().to_string());
+    assert_eq!("1", chain.next().unwrap().to_string());
+    assert_eq!("0", chain.next().unwrap().to_string());
+    assert!(chain.next().is_none());
+    assert!(chain.next_back().is_none());
+}
diff --git a/tests/test_context.rs b/tests/test_context.rs
index 44c1c70..e2d4a29 100644
--- a/tests/test_context.rs
+++ b/tests/test_context.rs
@@ -1,3 +1,8 @@
+#![allow(
+    // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
+    clippy::nonstandard_macro_braces,
+)]
+
 mod drop;
 
 use crate::drop::{DetectDrop, Flag};
@@ -157,3 +162,10 @@
     drop(err);
     assert!(dropped.all());
 }
+
+#[test]
+fn test_root_cause() {
+    let (err, _) = make_chain();
+
+    assert_eq!(err.root_cause().to_string(), "no such file or directory");
+}
diff --git a/tests/test_convert.rs b/tests/test_convert.rs
index aff64e2..6da171d 100644
--- a/tests/test_convert.rs
+++ b/tests/test_convert.rs
@@ -10,6 +10,26 @@
 fn test_convert() {
     let has_dropped = Flag::new();
     let error = Error::new(DetectDrop::new(&has_dropped));
+    let box_dyn = Box::<dyn StdError>::from(error);
+    assert_eq!("oh no!", box_dyn.to_string());
+    drop(box_dyn);
+    assert!(has_dropped.get());
+}
+
+#[test]
+fn test_convert_send() {
+    let has_dropped = Flag::new();
+    let error = Error::new(DetectDrop::new(&has_dropped));
+    let box_dyn = Box::<dyn StdError + Send>::from(error);
+    assert_eq!("oh no!", box_dyn.to_string());
+    drop(box_dyn);
+    assert!(has_dropped.get());
+}
+
+#[test]
+fn test_convert_send_sync() {
+    let has_dropped = Flag::new();
+    let error = Error::new(DetectDrop::new(&has_dropped));
     let box_dyn = Box::<dyn StdError + Send + Sync>::from(error);
     assert_eq!("oh no!", box_dyn.to_string());
     drop(box_dyn);
diff --git a/tests/test_downcast.rs b/tests/test_downcast.rs
index 6b93710..7fb063f 100644
--- a/tests/test_downcast.rs
+++ b/tests/test_downcast.rs
@@ -85,6 +85,15 @@
 }
 
 #[test]
+fn test_as_ref() {
+    let error = bail_error().unwrap_err();
+    let ref_dyn: &dyn StdError = error.as_ref();
+    assert_eq!("oh no!", ref_dyn.to_string());
+    let ref_dyn_send_sync: &(dyn StdError + Send + Sync) = error.as_ref();
+    assert_eq!("oh no!", ref_dyn_send_sync.to_string());
+}
+
+#[test]
 fn test_large_alignment() {
     #[repr(align(64))]
     #[derive(Debug)]
diff --git a/tests/ui/no-impl.stderr b/tests/ui/no-impl.stderr
index a4a829b..976b62c 100644
--- a/tests/ui/no-impl.stderr
+++ b/tests/ui/no-impl.stderr
@@ -18,4 +18,4 @@
           which is required by `&Error: anyhow::private::kind::AdhocKind`
           `&Error: Into<anyhow::Error>`
           which is required by `&Error: anyhow::private::kind::TraitKind`
-  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+  = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info)