From b20e9c90cebd29be1a89abcc1ac8d8cf7457af4e Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 31 Aug 2026 18:38:07 -0400 Subject: [PATCH 1/5] build: vendor Rust crate dependencies --- BUILD | 4 + Cargo.lock | 16 + Cargo.toml | 5 + MODULE.bazel | 6 +- src/machoke/BUILD | 1 + src/machoke/Cargo.lock | 7 - src/machoke/Cargo.toml | 1 + src/machoke/lib.rs | 6 +- src/machoke/main.rs | 5 +- third_party/BUILD | 16 + third_party/bazel-for-cargo-bazel.sh | 17 + third_party/crates/BUILD.bazel | 44 + third_party/crates/alias_rules.bzl | 47 + .../anyhow-1.0.104/.cargo-checksum.json | 1 + .../anyhow-1.0.104/.cargo_vcs_info.json | 6 + .../crates/anyhow-1.0.104/.github/FUNDING.yml | 1 + .../anyhow-1.0.104/.github/workflows/ci.yml | 146 +++ third_party/crates/anyhow-1.0.104/BUILD.bazel | 187 +++ third_party/crates/anyhow-1.0.104/Cargo.lock | 355 ++++++ third_party/crates/anyhow-1.0.104/Cargo.toml | 129 ++ .../crates/anyhow-1.0.104/Cargo.toml.orig | 36 + .../crates/anyhow-1.0.104/LICENSE-APACHE | 176 +++ third_party/crates/anyhow-1.0.104/LICENSE-MIT | 23 + third_party/crates/anyhow-1.0.104/README.md | 179 +++ third_party/crates/anyhow-1.0.104/build.rs | 194 +++ .../crates/anyhow-1.0.104/rust-toolchain.toml | 2 + .../crates/anyhow-1.0.104/src/backtrace.rs | 48 + .../crates/anyhow-1.0.104/src/chain.rs | 102 ++ .../crates/anyhow-1.0.104/src/context.rs | 193 +++ .../crates/anyhow-1.0.104/src/ensure.rs | 935 +++++++++++++++ .../crates/anyhow-1.0.104/src/error.rs | 1060 +++++++++++++++++ third_party/crates/anyhow-1.0.104/src/fmt.rs | 158 +++ third_party/crates/anyhow-1.0.104/src/kind.rs | 121 ++ third_party/crates/anyhow-1.0.104/src/lib.rs | 728 +++++++++++ .../crates/anyhow-1.0.104/src/macros.rs | 245 ++++ .../crates/anyhow-1.0.104/src/nightly.rs | 58 + third_party/crates/anyhow-1.0.104/src/ptr.rs | 187 +++ .../crates/anyhow-1.0.104/src/wrapper.rs | 84 ++ .../crates/anyhow-1.0.104/tests/common/mod.rs | 14 + .../anyhow-1.0.104/tests/compiletest.rs | 7 + .../crates/anyhow-1.0.104/tests/drop/mod.rs | 53 + .../anyhow-1.0.104/tests/test_autotrait.rs | 34 + .../anyhow-1.0.104/tests/test_backtrace.rs | 15 + .../crates/anyhow-1.0.104/tests/test_boxed.rs | 45 + .../crates/anyhow-1.0.104/tests/test_chain.rs | 69 ++ .../anyhow-1.0.104/tests/test_context.rs | 195 +++ .../anyhow-1.0.104/tests/test_convert.rs | 46 + .../anyhow-1.0.104/tests/test_downcast.rs | 123 ++ .../anyhow-1.0.104/tests/test_ensure.rs | 756 ++++++++++++ .../crates/anyhow-1.0.104/tests/test_ffi.rs | 19 + .../crates/anyhow-1.0.104/tests/test_fmt.rs | 93 ++ .../anyhow-1.0.104/tests/test_macros.rs | 97 ++ .../crates/anyhow-1.0.104/tests/test_repr.rs | 30 + .../anyhow-1.0.104/tests/test_source.rs | 62 + .../tests/ui/chained-comparison.rs | 8 + .../tests/ui/chained-comparison.stderr | 10 + .../anyhow-1.0.104/tests/ui/empty-ensure.rs | 6 + .../tests/ui/empty-ensure.stderr | 12 + .../anyhow-1.0.104/tests/ui/ensure-nonbool.rs | 40 + .../tests/ui/ensure-nonbool.stderr | 113 ++ .../anyhow-1.0.104/tests/ui/must-use.rs | 11 + .../anyhow-1.0.104/tests/ui/must-use.stderr | 15 + .../crates/anyhow-1.0.104/tests/ui/no-impl.rs | 8 + .../anyhow-1.0.104/tests/ui/no-impl.stderr | 32 + .../tests/ui/temporary-value.rs | 5 + .../tests/ui/temporary-value.stderr | 15 + .../tests/ui/wrong-interpolation.rs | 5 + .../tests/ui/wrong-interpolation.stderr | 5 + third_party/crates/crates.bzl | 436 +++++++ third_party/crates/defs.bzl | 23 + 70 files changed, 7920 insertions(+), 11 deletions(-) create mode 100644 BUILD create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 src/machoke/Cargo.lock create mode 100644 third_party/BUILD create mode 100755 third_party/bazel-for-cargo-bazel.sh create mode 100644 third_party/crates/BUILD.bazel create mode 100644 third_party/crates/alias_rules.bzl create mode 100644 third_party/crates/anyhow-1.0.104/.cargo-checksum.json create mode 100644 third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json create mode 100644 third_party/crates/anyhow-1.0.104/.github/FUNDING.yml create mode 100644 third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml create mode 100644 third_party/crates/anyhow-1.0.104/BUILD.bazel create mode 100644 third_party/crates/anyhow-1.0.104/Cargo.lock create mode 100644 third_party/crates/anyhow-1.0.104/Cargo.toml create mode 100644 third_party/crates/anyhow-1.0.104/Cargo.toml.orig create mode 100644 third_party/crates/anyhow-1.0.104/LICENSE-APACHE create mode 100644 third_party/crates/anyhow-1.0.104/LICENSE-MIT create mode 100644 third_party/crates/anyhow-1.0.104/README.md create mode 100644 third_party/crates/anyhow-1.0.104/build.rs create mode 100644 third_party/crates/anyhow-1.0.104/rust-toolchain.toml create mode 100644 third_party/crates/anyhow-1.0.104/src/backtrace.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/chain.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/context.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/ensure.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/error.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/fmt.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/kind.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/lib.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/macros.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/nightly.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/ptr.rs create mode 100644 third_party/crates/anyhow-1.0.104/src/wrapper.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/common/mod.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/compiletest.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/drop/mod.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_boxed.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_chain.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_context.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_convert.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_downcast.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_ensure.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_ffi.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_fmt.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_macros.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_repr.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/test_source.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs create mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr create mode 100644 third_party/crates/crates.bzl create mode 100644 third_party/crates/defs.bzl diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..adc03ca --- /dev/null +++ b/BUILD @@ -0,0 +1,4 @@ +exports_files([ + "Cargo.lock", + "Cargo.toml", +]) diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..f17f601 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "machoke" +version = "0.1.0" +dependencies = [ + "anyhow", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..52b87b4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +members = [ + "src/machoke", +] +resolver = "3" diff --git a/MODULE.bazel b/MODULE.bazel index 678fe4f..1e9e5c0 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,5 +1,9 @@ -module(name = "alexion", version = "0.1.0") +module( + name = "alexion", + version = "0.1.0", +) +bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "rules_rust", version = "0.74.0") rust = use_extension("//bazel:rust.bzl", "rust") diff --git a/src/machoke/BUILD b/src/machoke/BUILD index 5d0806d..aebba41 100644 --- a/src/machoke/BUILD +++ b/src/machoke/BUILD @@ -4,6 +4,7 @@ rust_library( name = "machoke_lib", crate_name = "machoke", srcs = ["lib.rs"], + deps = ["//third_party/crates:anyhow"], ) rust_binary( diff --git a/src/machoke/Cargo.lock b/src/machoke/Cargo.lock deleted file mode 100644 index 34a6f13..0000000 --- a/src/machoke/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "machoke" -version = "0.1.0" diff --git a/src/machoke/Cargo.toml b/src/machoke/Cargo.toml index 1beb8f9..184663e 100644 --- a/src/machoke/Cargo.toml +++ b/src/machoke/Cargo.toml @@ -11,3 +11,4 @@ name = "machoke" path = "main.rs" [dependencies] +anyhow = "1" diff --git a/src/machoke/lib.rs b/src/machoke/lib.rs index 33a6292..a91f24e 100644 --- a/src/machoke/lib.rs +++ b/src/machoke/lib.rs @@ -1,3 +1,5 @@ -pub fn greeting() -> &'static str { - "Hello from machoke" +use anyhow::Result; + +pub fn greeting() -> Result<&'static str> { + Ok("Hello from machoke") } diff --git a/src/machoke/main.rs b/src/machoke/main.rs index ddac719..7c52bab 100644 --- a/src/machoke/main.rs +++ b/src/machoke/main.rs @@ -1,3 +1,6 @@ fn main() { - println!("{}", machoke::greeting()); + println!( + "{}", + machoke::greeting().expect("greeting should be available") + ); } diff --git a/third_party/BUILD b/third_party/BUILD new file mode 100644 index 0000000..185241a --- /dev/null +++ b/third_party/BUILD @@ -0,0 +1,16 @@ +load("@rules_rust//crate_universe:defs.bzl", "crates_vendor") + +sh_binary( + name = "bazel_for_cargo_bazel", + srcs = ["bazel-for-cargo-bazel.sh"], +) + +crates_vendor( + name = "vendor_crates", + bazel = ":bazel_for_cargo_bazel", + cargo_lockfile = "//:Cargo.lock", + manifests = ["//:Cargo.toml"], + mode = "local", + tags = ["manual"], + vendor_path = "crates", +) diff --git a/third_party/bazel-for-cargo-bazel.sh b/third_party/bazel-for-cargo-bazel.sh new file mode 100755 index 0000000..5c6052e --- /dev/null +++ b/third_party/bazel-for-cargo-bazel.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +is_info=false +for argument in "$@"; do + if [[ "$argument" == "info" ]]; then + is_info=true + break + fi +done + +if $is_info; then + bazel "$@" | sed -E \ + 's/^release: release ([0-9]+\.[0-9]+\.[0-9]+).*/release: \1/' +else + exec bazel "$@" +fi diff --git a/third_party/crates/BUILD.bazel b/third_party/crates/BUILD.bazel new file mode 100644 index 0000000..54eaec5 --- /dev/null +++ b/third_party/crates/BUILD.bazel @@ -0,0 +1,44 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//third_party:vendor_crates +############################################################################### + +package(default_visibility = ["//visibility:public"]) + +exports_files( + [ + "cargo-bazel.json", + "crates.bzl", + "defs.bzl", + ] + glob( + include = ["*.bazel"], + allow_empty = True, + ), +) + +filegroup( + name = "srcs", + srcs = glob( + include = [ + "*.bazel", + "*.bzl", + ], + allow_empty = True, + ), +) + +# Workspace Member Dependencies +alias( + name = "anyhow-1.0.104", + actual = "//third_party/crates/anyhow-1.0.104:anyhow", + tags = ["manual"], +) + +alias( + name = "anyhow", + actual = "//third_party/crates/anyhow-1.0.104:anyhow", + tags = ["manual"], +) diff --git a/third_party/crates/alias_rules.bzl b/third_party/crates/alias_rules.bzl new file mode 100644 index 0000000..14b04c1 --- /dev/null +++ b/third_party/crates/alias_rules.bzl @@ -0,0 +1,47 @@ +"""Alias that transitions its target to `compilation_mode=opt`. Use `transition_alias="opt"` to enable.""" + +load("@rules_cc//cc:defs.bzl", "CcInfo") +load("@rules_rust//rust:rust_common.bzl", "COMMON_PROVIDERS") + +def _transition_alias_impl(ctx): + # `ctx.attr.actual` is a list of 1 item due to the transition + providers = [ctx.attr.actual[0][provider] for provider in COMMON_PROVIDERS] + if CcInfo in ctx.attr.actual[0]: + providers.append(ctx.attr.actual[0][CcInfo]) + return providers + +def _change_compilation_mode(compilation_mode): + def _change_compilation_mode_impl(_settings, _attr): + return { + "//command_line_option:compilation_mode": compilation_mode, + } + + return transition( + implementation = _change_compilation_mode_impl, + inputs = [], + outputs = [ + "//command_line_option:compilation_mode", + ], + ) + +def _transition_alias_rule(compilation_mode): + return rule( + implementation = _transition_alias_impl, + provides = COMMON_PROVIDERS, + attrs = { + "actual": attr.label( + mandatory = True, + doc = "`rust_library()` target to transition to `compilation_mode=opt`.", + providers = COMMON_PROVIDERS, + cfg = _change_compilation_mode(compilation_mode), + ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), + }, + doc = "Transitions a Rust library crate to the `compilation_mode=opt`.", + ) + +transition_alias_dbg = _transition_alias_rule("dbg") +transition_alias_fastbuild = _transition_alias_rule("fastbuild") +transition_alias_opt = _transition_alias_rule("opt") diff --git a/third_party/crates/anyhow-1.0.104/.cargo-checksum.json b/third_party/crates/anyhow-1.0.104/.cargo-checksum.json new file mode 100644 index 0000000..51b4065 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/.cargo-checksum.json @@ -0,0 +1 @@ +{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"9f5691d9965b8418415cfe8872a667089542a23a1d746bad08476ccda5e6269c",".github/FUNDING.yml":"b017158736b3c9751a2d21edfce7fe61c8954e2fced8da8dd3013c2f3e295bd9",".github/workflows/ci.yml":"40e9434834e8ba84207ef6a401da6b154fa4220a4847230284d6aae63d8a39ac","Cargo.lock":"c7b6dd9adcad0b26ce812afdb8539e1d93994a0735a90eb0dd7ce8535e3e7ffa","Cargo.toml":"249789761ff37004dda628765f0c9e60a61fa43cbbd2d364789dca0c789eeb59","Cargo.toml.orig":"1b03bd9d21f63835f0449cf1456e6143a15efd6b7803bc5b7787643db62b6f53","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"86f5b88c45b2b9b7eefa0ad66c11918a607319cad683f01123ff38db68b4a49b","build.rs":"89d1baedcff59822ed692d3a33f131c211a213bdec33c83f68b54110d9c64223","rust-toolchain.toml":"6bbb61302978c736b2da03e4fb40e3beab908f85d533ab46fd541e637b5f3e0f","src/backtrace.rs":"621ec5d9e2f31883d0384ae00fc536d1ea359da989d2e0d1be1ba03482c8f920","src/chain.rs":"85af447405f075633fab186b7f1c94d7f33a36474f239c50a961b2d6197d5426","src/context.rs":"8b106e43df7a66fbc3e85b87a4d7f8a780d43d3ee0cd1ae86c571950ecf07d13","src/ensure.rs":"709524741c8f9365e01cb36fc2349a8724513de02cf9e253809a93af8d6a7b6e","src/error.rs":"2a78ee4e5f8d6b4476c761f77473362b9ed12f5402e4701001e7d04d628ba030","src/fmt.rs":"2cca8c7f3cab636fdb17433ca2b1fda0e8d28bb20d4647b87c991dacd8f06cdf","src/kind.rs":"ddcabf15b3b47a4ef16ed361c45cc0cc82e7be90622995ff6c04b3fec78bb04f","src/lib.rs":"ea7f436f6bf4b356ff30ec922b50b40ead0ade28b123341a8de7f310311fd44c","src/macros.rs":"696e6a8aac614525a29697aedc7561e98beccf3d43aed3ada1cc93daa99da8ba","src/nightly.rs":"1c0aeadfcdbe22f8f807b185dec1a7448c378bddb37689714944b60473b58049","src/ptr.rs":"a114639d26f4feca7e186106342334cdf2e2176f892149aa331ace72e5d81410","src/wrapper.rs":"079218e1d8c9374f52311b1c7971f7fbdeba4d7af1b0749c0d535010f1232697","tests/common/mod.rs":"f9088c2d7afafa64ff730b629272045b776bfafc2f5957508242da630635f2e1","tests/compiletest.rs":"4e381aa8ca3eabb7ac14d1e0c3700b3223e47640547a6988cfa13ad68255f60f","tests/drop/mod.rs":"08c3e553c1cc0d2dbd936fc45f4b5b1105057186affd6865e8d261e05f0f0646","tests/test_autotrait.rs":"ba9bc18416115cb48fd08675a3e7fc89584de7926dad6b2be6645dc13d5931df","tests/test_backtrace.rs":"60afdd7ee5850dc22625ff486fe41c47fd322db874a93c4871ddfed2bf603930","tests/test_boxed.rs":"6b26db0e2eb72afe9af7352ea820837aab90f8d486294616dd5dc34c1b94038c","tests/test_chain.rs":"3a8a8d7569913bd98c0e27c69d0bda35101e7fde7c056ed57cdd8ed018e4cbcb","tests/test_context.rs":"a4cb7d9a6d488d902eb5ac516d2b5e4135f46caaa2d151580ed9ba83c2a90b57","tests/test_convert.rs":"7e7a8b4772a427a911014ac4d1083f9519000e786177f898808980dd9bdfde61","tests/test_downcast.rs":"797e69a72d125758c4c4897e5dc776d549d52cc9a6a633e0a33193f588a62b88","tests/test_ensure.rs":"6ef8823153d6aba31dda8438b9e51984e6b7377d585addbaf87162b39d733cd9","tests/test_ffi.rs":"c6e6bf39e6b2cf9aacea12e3e4da4e1e1edb7fc906d231e5baf45812a08de3c4","tests/test_fmt.rs":"0e49b48f08e4faaf03e2f202e1efc5250018876c4e1b01b8379d7a38ae8df870","tests/test_macros.rs":"3eb6ec9024cf8812da48de35b733d5a69ed942907fb4e6c67ec471cd4bcef562","tests/test_repr.rs":"034dee888abd08741e11ac2e95ef4fcb2ab3943d0a76e8e976db404658e1a252","tests/test_source.rs":"b80723cf635a4f8c4df21891b34bfab9ed2b2aa407e7a2f826d24e334cd5f88e","tests/ui/chained-comparison.rs":"6504b03d95b5acc232a7f4defc9f343b2be6733bf475fa0992e8e6545b912bd4","tests/ui/chained-comparison.stderr":"7f1d0a8c251b0ede2d30b3087ec157fc660945c97a642c4a5acf5a14ec58de34","tests/ui/empty-ensure.rs":"ab5bf37c846a0d689f26ce9257a27228411ed64154f9c950f1602d88a355d94b","tests/ui/empty-ensure.stderr":"315782f5f4246290fe190e3767b22c3dcaffaabc19c5ace0373537d53e765278","tests/ui/ensure-nonbool.rs":"7e57cb93fbcd82959b36586ed6bd2ad978b051fe5facd5274651fde6b1600905","tests/ui/ensure-nonbool.stderr":"e3dfbaedd66fdfc524f8462305760c7978c4268ca7e1cd872d7ecde5d3b455bd","tests/ui/must-use.rs":"fb59860b43f673bf4a430a6036ba463e95028844d8dd4243cfe5ebc7f2be582f","tests/ui/must-use.stderr":"8b1cb7fca632396a22bb3a642f2df3ab62b3e9a87951e20fa40bdd548d002162","tests/ui/no-impl.rs":"fab6cbf2f6ea510b86f567dfb3b7c31250a9fd71ae5d110dbb9188be569ec593","tests/ui/no-impl.stderr":"c472de95483aa234728c7f57039c88fc3456892838329976a75cd167c3c172c9","tests/ui/temporary-value.rs":"4dcc96271b2403e6372cf4cfc813445e5ce4365fc6e156b6bc38274098499a70","tests/ui/temporary-value.stderr":"7f99cd914d2d423d77274e1b859b5ad151cde8224e42687e50622c26118fd47f","tests/ui/wrong-interpolation.rs":"9c44d4674c2dccd27b9dedd03341346ec02d993b41793ee89b5755202e7e367e","tests/ui/wrong-interpolation.stderr":"301e60e2eb9401782c7dc0b3580613a4cb2aafd4cc8065734a630a62e1161aa5"},"package":"330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"} \ No newline at end of file diff --git a/third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json b/third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json new file mode 100644 index 0000000..6d990c1 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json @@ -0,0 +1,6 @@ +{ + "git": { + "sha1": "1dbe1862aae650423e3361fbd20b7d17c5109cc3" + }, + "path_in_vcs": "" +} \ No newline at end of file diff --git a/third_party/crates/anyhow-1.0.104/.github/FUNDING.yml b/third_party/crates/anyhow-1.0.104/.github/FUNDING.yml new file mode 100644 index 0000000..7507077 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/.github/FUNDING.yml @@ -0,0 +1 @@ +github: dtolnay diff --git a/third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml b/third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml new file mode 100644 index 0000000..d4e05d2 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml @@ -0,0 +1,146 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + schedule: [cron: "40 1 * * *"] + +permissions: + contents: read + +env: + RUSTFLAGS: -Dwarnings + +jobs: + pre_ci: + uses: dtolnay/.github/.github/workflows/pre_ci.yml@master + + test: + name: Rust ${{matrix.rust}} + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust: [nightly, beta, stable, 1.85.0] + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust}} + components: rust-src + - name: Enable type layout randomization + run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV + if: matrix.rust == 'nightly' + - name: Enable nightly-only tests + run: echo RUSTFLAGS=${RUSTFLAGS}\ --cfg=anyhow_nightly_testing >> $GITHUB_ENV + if: matrix.rust == 'nightly' + - run: cargo test + - run: cargo check --no-default-features + - run: cargo check + - uses: actions/upload-artifact@v7 + if: matrix.rust == 'nightly' && always() + with: + name: Cargo.lock + path: Cargo.lock + continue-on-error: true + + build: + name: Rust ${{matrix.rust}} + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust: [1.68.0] + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust}} + components: rust-src + - run: cargo check --manifest-path tests/crate/Cargo.toml + - run: cargo check --manifest-path tests/crate/Cargo.toml --no-default-features + + minimal: + name: Minimal versions + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@nightly + - run: cargo generate-lockfile -Z minimal-versions + - run: cargo check --locked + + windows: + name: Windows + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: windows-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@stable + with: + components: rust-src + - run: cargo check + + doc: + name: Documentation + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + timeout-minutes: 45 + env: + RUSTDOCFLAGS: -Dwarnings + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rust-src + - uses: dtolnay/install@cargo-docs-rs + - run: cargo docs-rs + + clippy: + name: Clippy + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@nightly + with: + components: clippy, rust-src + - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic + + miri: + name: Miri + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@miri + - run: cargo miri setup + - run: cargo miri test + env: + MIRIFLAGS: -Zmiri-strict-provenance + + outdated: + name: Outdated + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/install@cargo-outdated + - run: cargo outdated --workspace --exit-code 1 diff --git a/third_party/crates/anyhow-1.0.104/BUILD.bazel b/third_party/crates/anyhow-1.0.104/BUILD.bazel new file mode 100644 index 0000000..3b4d8af --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/BUILD.bazel @@ -0,0 +1,187 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//third_party:vendor_crates +############################################################################### + +load( + "@rules_rust//cargo:defs.bzl", + "cargo_build_script", + "cargo_toml_env_vars", +) +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +cargo_toml_env_vars( + name = "cargo_toml_env_vars", + src = "Cargo.toml", +) + +rust_library( + name = "anyhow", + srcs = glob( + include = ["**/*.rs"], + allow_empty = False, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + "std", + ], + crate_root = "src/lib.rs", + edition = "2021", + rustc_env_files = [ + ":cargo_toml_env_vars", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=anyhow", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-macabi": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-none": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:aarch64-unknown-uefi": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:arm-unknown-linux-musleabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:mips-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:sparc64-unknown-netbsd": [], + "@rules_rust//rust/platform:sparc64-unknown-openbsd": [], + "@rules_rust//rust/platform:thumbv6m-none-eabi": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv7em-none-eabihf": [], + "@rules_rust//rust/platform:thumbv7m-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [], + "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasip1": [], + "@rules_rust//rust/platform:wasm32-wasip1-threads": [], + "@rules_rust//rust/platform:wasm32-wasip2": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-apple-ios-macabi": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "@rules_rust//rust/platform:x86_64-unknown-uefi": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.104", + deps = [ + ":build_script_build", + ], +) + +cargo_build_script( + name = "_bs", + srcs = glob( + include = ["**/*.rs"], + allow_empty = False, + ), + build_script_env_files = [ + ":cargo_toml_env_vars", + ], + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + "**/*.rs", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + "std", + ], + crate_name = "build_script_build", + crate_root = "build.rs", + data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + edition = "2021", + emit_warnings = False, + pkg_name = "anyhow", + rustc_env_files = [ + ":cargo_toml_env_vars", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=anyhow", + "manual", + "noclippy", + "norustfmt", + ], + version = "1.0.104", + visibility = ["//visibility:private"], +) + +alias( + name = "build_script_build", + actual = ":_bs", + tags = ["manual"], +) diff --git a/third_party/crates/anyhow-1.0.104/Cargo.lock b/third_party/crates/anyhow-1.0.104/Cargo.lock new file mode 100644 index 0000000..e0d301e --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/Cargo.lock @@ -0,0 +1,355 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.104" +dependencies = [ + "futures", + "rustversion", + "syn 3.0.0", + "thiserror", + "trybuild", +] + +[[package]] +name = "dissimilar" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeda16ab4059c5fd2a83f2b9c9e9c981327b18aa8e3b313f7e6563799d4f093e" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "futures" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a88cf1f829d945f548cf8fec32c61b1f202b6d93b45848602fc02af4b12ad218" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "262590f4fe6afeb0bc83be1daa64e52657fe185690a958af7f3ad0e92085c5ae" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7" + +[[package]] +name = "futures-io" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4577ecaa3c4f96589d473f679a71b596316f6641bc350038b962a5daf0085d7a" + +[[package]] +name = "futures-sink" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e34418ac499d6305c2fb5ad0ed2f6ac998c5f8ca209b4510f7f94242c647e307" + +[[package]] +name = "futures-task" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109" + +[[package]] +name = "futures-util" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", +] + +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fac314a64dc9a36e61a9eb4261a5e9bbfbc922b27e518af97bc32b926cf967" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-triple" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3a6bfce3d99adfa72d24750a61f782f3036a81e7f86d8841ee1326deaebd171" + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "toml" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" + +[[package]] +name = "trybuild" +version = "1.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06649c6f63d86604ba0c8950d5a1829fc9a17afd70fc6629f481d75b6a624c78" +dependencies = [ + "dissimilar", + "glob", + "serde", + "serde_derive", + "serde_json", + "target-triple", + "termcolor", + "toml", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "winnow" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/third_party/crates/anyhow-1.0.104/Cargo.toml b/third_party/crates/anyhow-1.0.104/Cargo.toml new file mode 100644 index 0000000..d0b23cc --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/Cargo.toml @@ -0,0 +1,129 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# 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. +# +# 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 = "2021" +rust-version = "1.68" +name = "anyhow" +version = "1.0.104" +authors = ["David Tolnay "] +build = "build.rs" +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "Flexible concrete Error type built on std::error::Error" +documentation = "https://docs.rs/anyhow" +readme = "README.md" +keywords = [ + "error", + "error-handling", +] +categories = [ + "rust-patterns", + "no-std", +] +license = "MIT OR Apache-2.0" +repository = "https://github.com/dtolnay/anyhow" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +rustdoc-args = [ + "--generate-link-to-definition", + "--generate-macro-expansion", + "--extern-html-root-url=core=https://doc.rust-lang.org", + "--extern-html-root-url=alloc=https://doc.rust-lang.org", + "--extern-html-root-url=std=https://doc.rust-lang.org", +] + +[features] +backtrace = [] +default = ["std"] +std = [] + +[lib] +name = "anyhow" +path = "src/lib.rs" + +[[test]] +name = "compiletest" +path = "tests/compiletest.rs" + +[[test]] +name = "test_autotrait" +path = "tests/test_autotrait.rs" + +[[test]] +name = "test_backtrace" +path = "tests/test_backtrace.rs" + +[[test]] +name = "test_boxed" +path = "tests/test_boxed.rs" + +[[test]] +name = "test_chain" +path = "tests/test_chain.rs" + +[[test]] +name = "test_context" +path = "tests/test_context.rs" + +[[test]] +name = "test_convert" +path = "tests/test_convert.rs" + +[[test]] +name = "test_downcast" +path = "tests/test_downcast.rs" + +[[test]] +name = "test_ensure" +path = "tests/test_ensure.rs" + +[[test]] +name = "test_ffi" +path = "tests/test_ffi.rs" + +[[test]] +name = "test_fmt" +path = "tests/test_fmt.rs" + +[[test]] +name = "test_macros" +path = "tests/test_macros.rs" + +[[test]] +name = "test_repr" +path = "tests/test_repr.rs" + +[[test]] +name = "test_source" +path = "tests/test_source.rs" + +[dev-dependencies.futures] +version = "0.3" +default-features = false + +[dev-dependencies.rustversion] +version = "1.0.6" + +[dev-dependencies.syn] +version = "3" +features = ["full"] + +[dev-dependencies.thiserror] +version = "2" + +[dev-dependencies.trybuild] +version = "1.0.108" +features = ["diff"] diff --git a/third_party/crates/anyhow-1.0.104/Cargo.toml.orig b/third_party/crates/anyhow-1.0.104/Cargo.toml.orig new file mode 100644 index 0000000..37cdeb7 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/Cargo.toml.orig @@ -0,0 +1,36 @@ +[package] +name = "anyhow" +version = "1.0.104" +authors = ["David Tolnay "] +categories = ["rust-patterns", "no-std"] +description = "Flexible concrete Error type built on std::error::Error" +documentation = "https://docs.rs/anyhow" +edition = "2021" +keywords = ["error", "error-handling"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/dtolnay/anyhow" +rust-version = "1.68" + +[features] +default = ["std"] +std = [] +# THIS HAS NO EFFECT. This feature remains to preserve compatibility with the +# old `backtrace` optional dependency that this crate used to have. +backtrace = [] + +[dev-dependencies] +futures = { version = "0.3", default-features = false } +rustversion = "1.0.6" +syn = { version = "3", features = ["full"] } +thiserror = "2" +trybuild = { version = "1.0.108", features = ["diff"] } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +rustdoc-args = [ + "--generate-link-to-definition", + "--generate-macro-expansion", + "--extern-html-root-url=core=https://doc.rust-lang.org", + "--extern-html-root-url=alloc=https://doc.rust-lang.org", + "--extern-html-root-url=std=https://doc.rust-lang.org", +] diff --git a/third_party/crates/anyhow-1.0.104/LICENSE-APACHE b/third_party/crates/anyhow-1.0.104/LICENSE-APACHE new file mode 100644 index 0000000..1b5ec8b --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/third_party/crates/anyhow-1.0.104/LICENSE-MIT b/third_party/crates/anyhow-1.0.104/LICENSE-MIT new file mode 100644 index 0000000..31aa793 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/third_party/crates/anyhow-1.0.104/README.md b/third_party/crates/anyhow-1.0.104/README.md new file mode 100644 index 0000000..78225bb --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/README.md @@ -0,0 +1,179 @@ +Anyhow ¯\\\_(°ペ)\_/¯ +========================== + +[github](https://github.com/dtolnay/anyhow) +[crates.io](https://crates.io/crates/anyhow) +[docs.rs](https://docs.rs/anyhow) +[build status](https://github.com/dtolnay/anyhow/actions?query=branch%3Amaster) + +This library provides [`anyhow::Error`][Error], a trait object based error type +for easy idiomatic error handling in Rust applications. + +[Error]: https://docs.rs/anyhow/1.0/anyhow/struct.Error.html + +```toml +[dependencies] +anyhow = "1.0" +``` + +
+ +## Details + +- Use `Result`, or equivalently `anyhow::Result`, as the + return type of any fallible function. + + Within the function, use `?` to easily propagate any error that implements the + [`std::error::Error`] trait. + + ```rust + use anyhow::Result; + + fn get_cluster_info() -> Result { + let config = std::fs::read_to_string("cluster.json")?; + let map: ClusterMap = serde_json::from_str(&config)?; + Ok(map) + } + ``` + + [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html + +- Attach context to help the person troubleshooting the error understand where + things went wrong. A low-level error like "No such file or directory" can be + annoying to debug without more context about what higher level step the + application was in the middle of. + + ```rust + use anyhow::{Context, Result}; + + fn main() -> Result<()> { + ... + it.detach().context("Failed to detach the important thing")?; + + let content = std::fs::read(path) + .with_context(|| format!("Failed to read instrs from {}", path))?; + ... + } + ``` + + ```console + Error: Failed to read instrs from ./path/to/instrs.json + + Caused by: + No such file or directory (os error 2) + ``` + +- Downcasting is supported and can be by value, by shared reference, or by + mutable reference as needed. + + ```rust + // If the error was caused by redaction, then return a + // tombstone instead of the content. + match root_cause.downcast_ref::() { + Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), + None => Err(error), + } + ``` + +- 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`; + - 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 + but you can write the impls yourself or use a standalone macro like + [thiserror]. + + ```rust + use thiserror::Error; + + #[derive(Error, Debug)] + pub enum FormatError { + #[error("Invalid header (expected {expected:?}, got {found:?})")] + InvalidHeader { + expected: String, + found: String, + }, + #[error("Missing attribute: {0}")] + MissingAttribute(String), + } + ``` + +- One-off error messages can be constructed using the `anyhow!` macro, which + supports string interpolation and produces an `anyhow::Error`. + + ```rust + return Err(anyhow!("Missing attribute: {}", missing)); + ``` + + A `bail!` macro is provided as a shorthand for the same early return. + + ```rust + bail!("Missing attribute: {}", missing); + ``` + +
+ +## No-std support + +In no_std mode, almost all of the same API is available and works the same way. +To depend on Anyhow in no_std mode, disable our default enabled "std" feature in +Cargo.toml. A global allocator is required. + +```toml +[dependencies] +anyhow = { version = "1.0", default-features = false } +``` + +With versions of Rust older than 1.81, no_std mode may require an additional +`.map_err(Error::msg)` when working with a non-Anyhow error type inside a +function that returns Anyhow's error type, as the trait that `?`-based error +conversions are defined by is only available in std in those old versions. + +
+ +## Comparison to failure + +The `anyhow::Error` type works something like `failure::Error`, but unlike +failure ours is built around the standard library's `std::error::Error` trait +rather than a separate trait `failure::Fail`. The standard library has adopted +the necessary improvements for this to be possible as part of [RFC 2504]. + +[RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md + +
+ +## Comparison to thiserror + +Use Anyhow if you don't care what error type your functions return, you just +want it to be easy. This is common in application code. Use [thiserror] if you +are a library that wants to design your own dedicated error type(s) so that on +failures the caller gets exactly the information that you choose. + +[thiserror]: https://github.com/dtolnay/thiserror + +
+ +#### License + + +Licensed under either of Apache License, Version +2.0 or MIT license at your option. + + +
+ + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in this crate by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. + diff --git a/third_party/crates/anyhow-1.0.104/build.rs b/third_party/crates/anyhow-1.0.104/build.rs new file mode 100644 index 0000000..f4fbc94 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/build.rs @@ -0,0 +1,194 @@ +#![allow(clippy::uninlined_format_args)] + +use std::env; +use std::ffi::OsString; +use std::fs; +use std::io::ErrorKind; +use std::iter; +use std::path::Path; +use std::process::{self, Command, Stdio}; +use std::str; + +fn main() { + if cfg!(feature = "std") { + println!("cargo:rerun-if-changed=src/nightly.rs"); + + let error_generic_member_access; + let consider_rustc_bootstrap; + if compile_probe(false) { + // This is a nightly or dev compiler, so it supports unstable + // features regardless of RUSTC_BOOTSTRAP. No need to rerun build + // script if RUSTC_BOOTSTRAP is changed. + error_generic_member_access = true; + consider_rustc_bootstrap = false; + } else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") { + if compile_probe(true) { + // This is a stable or beta compiler for which the user has set + // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build + // script if they change it. + error_generic_member_access = true; + consider_rustc_bootstrap = true; + } else if rustc_bootstrap == "1" { + // This compiler does not support the generic member access API + // in the form that anyhow expects. No need to pay attention to + // RUSTC_BOOTSTRAP. + error_generic_member_access = false; + consider_rustc_bootstrap = false; + } else { + // This is a stable or beta compiler for which RUSTC_BOOTSTRAP + // is set to restrict the use of unstable features by this + // crate. + error_generic_member_access = false; + consider_rustc_bootstrap = true; + } + } else { + // Without RUSTC_BOOTSTRAP, this compiler does not support the + // generic member access API in the form that anyhow expects, but + // try again if the user turns on unstable features. + error_generic_member_access = false; + consider_rustc_bootstrap = true; + } + + if error_generic_member_access { + println!("cargo:rustc-cfg=error_generic_member_access"); + } + + if consider_rustc_bootstrap { + println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP"); + } + } + + let Some(rustc) = rustc_minor_version() else { + return; + }; + + if rustc >= 80 { + println!("cargo:rustc-check-cfg=cfg(anyhow_build_probe)"); + println!("cargo:rustc-check-cfg=cfg(anyhow_nightly_testing)"); + println!("cargo:rustc-check-cfg=cfg(anyhow_no_clippy_format_args)"); + println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_error)"); + println!("cargo:rustc-check-cfg=cfg(error_generic_member_access)"); + } + + if rustc < 81 { + // core::error::Error + // https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror + println!("cargo:rustc-cfg=anyhow_no_core_error"); + } + + if rustc < 85 { + // #[clippy::format_args] + // https://doc.rust-lang.org/1.85.1/clippy/attribs.html#clippyformat_args + println!("cargo:rustc-cfg=anyhow_no_clippy_format_args"); + } +} + +fn compile_probe(rustc_bootstrap: bool) -> bool { + if env::var_os("RUSTC_STAGE").is_some() { + // We are running inside rustc bootstrap. This is a highly non-standard + // environment with issues such as: + // + // https://github.com/rust-lang/cargo/issues/11138 + // https://github.com/rust-lang/rust/issues/114839 + // + // Let's just not use nightly features here. + return false; + } + + let rustc = cargo_env_var("RUSTC"); + let out_dir = cargo_env_var("OUT_DIR"); + let out_subdir = Path::new(&out_dir).join("probe"); + let probefile = Path::new("src").join("nightly.rs"); + + if let Err(err) = fs::create_dir(&out_subdir) { + if err.kind() != ErrorKind::AlreadyExists { + eprintln!("Failed to create {}: {}", out_subdir.display(), err); + process::exit(1); + } + } + + let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty()); + let rustc_workspace_wrapper = + env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty()); + let mut rustc = rustc_wrapper + .into_iter() + .chain(rustc_workspace_wrapper) + .chain(iter::once(rustc)); + let mut cmd = Command::new(rustc.next().unwrap()); + cmd.args(rustc); + + if !rustc_bootstrap { + cmd.env_remove("RUSTC_BOOTSTRAP"); + } + + cmd.stderr(Stdio::null()) + .arg("--cfg=anyhow_build_probe") + .arg("--edition=2018") + .arg("--crate-name=anyhow") + .arg("--crate-type=lib") + .arg("--cap-lints=allow") + .arg("--emit=dep-info,metadata") + .arg("--out-dir") + .arg(&out_subdir) + .arg(probefile); + + if let Some(target) = env::var_os("TARGET") { + cmd.arg("--target").arg(target); + } + + // 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); + } + } + } + + let success = match cmd.status() { + Ok(status) => status.success(), + Err(_) => false, + }; + + // Clean up to avoid leaving nondeterministic absolute paths in the dep-info + // file in OUT_DIR, which causes nonreproducible builds in build systems + // that treat the entire OUT_DIR as an artifact. + if let Err(err) = fs::remove_dir_all(&out_subdir) { + // libc::ENOTEMPTY + // Some filesystems (NFSv3) have timing issues under load where '.nfs*' + // dummy files can continue to get created for a short period after the + // probe command completes, breaking remove_dir_all. + // To be replaced with ErrorKind::DirectoryNotEmpty (Rust 1.83+). + const ENOTEMPTY: i32 = 39; + + if !(err.kind() == ErrorKind::NotFound + || (cfg!(target_os = "linux") && err.raw_os_error() == Some(ENOTEMPTY))) + { + eprintln!("Failed to clean up {}: {}", out_subdir.display(), err); + process::exit(1); + } + } + + success +} + +fn rustc_minor_version() -> Option { + let rustc = cargo_env_var("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() +} + +fn cargo_env_var(key: &str) -> OsString { + env::var_os(key).unwrap_or_else(|| { + eprintln!( + "Environment variable ${} is not set during execution of build script", + key, + ); + process::exit(1); + }) +} diff --git a/third_party/crates/anyhow-1.0.104/rust-toolchain.toml b/third_party/crates/anyhow-1.0.104/rust-toolchain.toml new file mode 100644 index 0000000..20fe888 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +components = ["rust-src"] diff --git a/third_party/crates/anyhow-1.0.104/src/backtrace.rs b/third_party/crates/anyhow-1.0.104/src/backtrace.rs new file mode 100644 index 0000000..d9ae520 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/backtrace.rs @@ -0,0 +1,48 @@ +#[cfg(feature = "std")] +pub(crate) use std::backtrace::Backtrace; + +#[cfg(not(feature = "std"))] +pub(crate) enum Backtrace {} + +#[cfg(feature = "std")] +macro_rules! backtrace { + () => { + Some(std::backtrace::Backtrace::capture()) + }; +} + +#[cfg(not(feature = "std"))] +macro_rules! backtrace { + () => { + None + }; +} + +#[cfg(error_generic_member_access)] +macro_rules! backtrace_if_absent { + ($err:expr) => { + match $crate::nightly::request_ref_backtrace($err as &dyn core::error::Error) { + Some(_) => None, + None => backtrace!(), + } + }; +} + +#[cfg(all(not(error_generic_member_access), feature = "std"))] +macro_rules! backtrace_if_absent { + ($err:expr) => { + backtrace!() + }; +} + +#[cfg(all(not(anyhow_no_core_error), not(feature = "std")))] +macro_rules! backtrace_if_absent { + ($err:expr) => { + None + }; +} + +fn _assert_send_sync() { + fn assert() {} + assert::(); +} diff --git a/third_party/crates/anyhow-1.0.104/src/chain.rs b/third_party/crates/anyhow-1.0.104/src/chain.rs new file mode 100644 index 0000000..e56bc66 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/chain.rs @@ -0,0 +1,102 @@ +use self::ChainState::*; +use crate::StdError; + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +use alloc::vec::{self, Vec}; + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +pub(crate) use crate::Chain; + +#[cfg(all(not(feature = "std"), anyhow_no_core_error))] +pub(crate) struct Chain<'a> { + state: ChainState<'a>, +} + +#[derive(Clone)] +pub(crate) enum ChainState<'a> { + Linked { + next: Option<&'a (dyn StdError + 'static)>, + }, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + Buffered { + rest: vec::IntoIter<&'a (dyn StdError + 'static)>, + }, +} + +impl<'a> Chain<'a> { + #[cold] + pub fn new(head: &'a (dyn StdError + 'static)) -> Self { + Chain { + state: ChainState::Linked { next: Some(head) }, + } + } +} + +impl<'a> Iterator for Chain<'a> { + type Item = &'a (dyn StdError + 'static); + + fn next(&mut self) -> Option { + match &mut self.state { + Linked { next } => { + let error = (*next)?; + *next = error.source(); + Some(error) + } + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + Buffered { rest } => rest.next(), + } + } + + fn size_hint(&self) -> (usize, Option) { + let len = self.len(); + (len, Some(len)) + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl DoubleEndedIterator for Chain<'_> { + fn next_back(&mut self) -> Option { + match &mut self.state { + Linked { mut next } => { + let mut rest = Vec::new(); + while let Some(cause) = next { + next = cause.source(); + rest.push(cause); + } + let mut rest = rest.into_iter(); + let last = rest.next_back(); + self.state = Buffered { rest }; + last + } + Buffered { rest } => rest.next_back(), + } + } +} + +impl ExactSizeIterator for Chain<'_> { + fn len(&self) -> usize { + match &self.state { + Linked { mut next } => { + let mut len = 0; + while let Some(cause) = next { + next = cause.source(); + len += 1; + } + len + } + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + Buffered { rest } => rest.len(), + } + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl Default for Chain<'_> { + fn default() -> Self { + Chain { + state: ChainState::Buffered { + rest: Vec::new().into_iter(), + }, + } + } +} diff --git a/third_party/crates/anyhow-1.0.104/src/context.rs b/third_party/crates/anyhow-1.0.104/src/context.rs new file mode 100644 index 0000000..52e6ab6 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/context.rs @@ -0,0 +1,193 @@ +use crate::error::ContextError; +use crate::{Context, Error, StdError}; +use core::convert::Infallible; +use core::fmt::{self, Debug, Display, Write}; + +#[cfg(error_generic_member_access)] +use crate::nightly::{self, Request}; + +mod ext { + use super::*; + + pub trait StdError { + fn ext_context(self, context: C) -> Error + where + C: Display + Send + Sync + 'static; + } + + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + impl StdError for E + where + E: crate::StdError + Send + Sync + 'static, + { + fn ext_context(self, context: C) -> Error + where + C: Display + Send + Sync + 'static, + { + let backtrace = backtrace_if_absent!(&self); + Error::construct_from_context(context, self, backtrace) + } + } + + impl StdError for Error { + fn ext_context(self, context: C) -> Error + where + C: Display + Send + Sync + 'static, + { + self.context(context) + } + } +} + +impl Context for Result +where + E: ext::StdError + Send + Sync + 'static, +{ + fn context(self, context: C) -> Result + where + C: Display + Send + Sync + 'static, + { + // Not using map_err to save 2 useless frames off the captured backtrace + // in ext_context. + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(error.ext_context(context)), + } + } + + fn with_context(self, context: F) -> Result + where + C: Display + Send + Sync + 'static, + F: FnOnce() -> C, + { + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(error.ext_context(context())), + } + } +} + +/// ``` +/// # type T = (); +/// # +/// use anyhow::{Context, Result}; +/// +/// fn maybe_get() -> Option { +/// # const IGNORE: &str = stringify! { +/// ... +/// # }; +/// # unimplemented!() +/// } +/// +/// fn demo() -> Result<()> { +/// let t = maybe_get().context("there is no T")?; +/// # const IGNORE: &str = stringify! { +/// ... +/// # }; +/// # unimplemented!() +/// } +/// ``` +impl Context for Option { + fn context(self, context: C) -> Result + where + C: Display + Send + Sync + 'static, + { + // Not using ok_or_else to save 2 useless frames off the captured + // backtrace. + match self { + Some(ok) => Ok(ok), + None => Err(Error::construct_from_display(context, backtrace!())), + } + } + + fn with_context(self, context: F) -> Result + where + C: Display + Send + Sync + 'static, + F: FnOnce() -> C, + { + match self { + Some(ok) => Ok(ok), + None => Err(Error::construct_from_display(context(), backtrace!())), + } + } +} + +impl Debug for ContextError +where + C: Display, + E: Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Error") + .field("context", &Quoted(&self.context)) + .field("source", &self.error) + .finish() + } +} + +impl Display for ContextError +where + C: Display, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&self.context, f) + } +} + +impl StdError for ContextError +where + C: Display, + E: StdError + 'static, +{ + fn source(&self) -> Option<&(dyn StdError + 'static)> { + Some(&self.error) + } + + #[cfg(error_generic_member_access)] + fn provide<'a>(&'a self, request: &mut Request<'a>) { + nightly::provide(&self.error, request); + } +} + +impl StdError for ContextError +where + C: Display, +{ + fn source(&self) -> Option<&(dyn StdError + 'static)> { + Some(unsafe { crate::ErrorImpl::error(self.error.inner.by_ref()) }) + } + + #[cfg(error_generic_member_access)] + fn provide<'a>(&'a self, request: &mut Request<'a>) { + Error::provide(&self.error, request); + } +} + +struct Quoted(C); + +impl Debug for Quoted +where + C: Display, +{ + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_char('"')?; + Quoted(&mut *formatter).write_fmt(format_args!("{}", self.0))?; + formatter.write_char('"')?; + Ok(()) + } +} + +impl Write for Quoted<&mut fmt::Formatter<'_>> { + fn write_str(&mut self, s: &str) -> fmt::Result { + Display::fmt(&s.escape_debug(), self.0) + } +} + +pub(crate) mod private { + use super::*; + + pub trait Sealed {} + + impl Sealed for Result where E: ext::StdError {} + impl Sealed for Option {} +} diff --git a/third_party/crates/anyhow-1.0.104/src/ensure.rs b/third_party/crates/anyhow-1.0.104/src/ensure.rs new file mode 100644 index 0000000..795757d --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/ensure.rs @@ -0,0 +1,935 @@ +use crate::Error; +use alloc::string::String; +use core::fmt::{self, Debug, Write}; +use core::mem::MaybeUninit; +use core::ptr; +use core::slice; +use core::str; + +#[doc(hidden)] +pub trait BothDebug { + fn __dispatch_ensure(self, msg: &'static str) -> Error; +} + +impl BothDebug for (A, B) +where + A: Debug, + B: Debug, +{ + fn __dispatch_ensure(self, msg: &'static str) -> Error { + render(msg, &self.0, &self.1) + } +} + +#[doc(hidden)] +pub trait NotBothDebug { + fn __dispatch_ensure(self, msg: &'static str) -> Error; +} + +impl NotBothDebug for &(A, B) { + fn __dispatch_ensure(self, msg: &'static str) -> Error { + Error::msg(msg) + } +} + +struct Buf { + bytes: [MaybeUninit; 40], + written: usize, +} + +impl Buf { + fn new() -> Self { + Buf { + bytes: [MaybeUninit::uninit(); 40], + written: 0, + } + } + + fn as_str(&self) -> &str { + unsafe { + str::from_utf8_unchecked(slice::from_raw_parts( + self.bytes.as_ptr().cast::(), + self.written, + )) + } + } +} + +impl Write for Buf { + fn write_str(&mut self, s: &str) -> fmt::Result { + if s.bytes().any(|b| b == b' ' || b == b'\n') { + return Err(fmt::Error); + } + + let remaining = self.bytes.len() - self.written; + if s.len() > remaining { + return Err(fmt::Error); + } + + unsafe { + ptr::copy_nonoverlapping( + s.as_ptr(), + self.bytes.as_mut_ptr().add(self.written).cast::(), + s.len(), + ); + } + self.written += s.len(); + Ok(()) + } +} + +fn render(msg: &'static str, lhs: &dyn Debug, rhs: &dyn Debug) -> Error { + let mut lhs_buf = Buf::new(); + if fmt::write(&mut lhs_buf, format_args!("{:?}", lhs)).is_ok() { + let mut rhs_buf = Buf::new(); + if fmt::write(&mut rhs_buf, format_args!("{:?}", rhs)).is_ok() { + let lhs_str = lhs_buf.as_str(); + let rhs_str = rhs_buf.as_str(); + // "{msg} ({lhs} vs {rhs})" + let len = msg.len() + 2 + lhs_str.len() + 4 + rhs_str.len() + 1; + let mut string = String::with_capacity(len); + string.push_str(msg); + string.push_str(" ("); + string.push_str(lhs_str); + string.push_str(" vs "); + string.push_str(rhs_str); + string.push(')'); + return Error::msg(string); + } + } + Error::msg(msg) +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __parse_ensure { + (atom () $bail:tt $fuel:tt {($($rhs:tt)+) ($($lhs:tt)+) $op:tt} $dup:tt $(,)?) => { + $crate::__fancy_ensure!($($lhs)+, $op, $($rhs)+) + }; + + // low precedence control flow constructs + + (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt return $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt break $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt continue $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt yield $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt move $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + // unary operators + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($deref:tt $($dup:tt)*) * $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $deref) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($not:tt $($dup:tt)*) ! $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $not) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($neg:tt $($dup:tt)*) - $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $neg) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($let:tt $($dup:tt)*) let $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $let) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($lifetime:tt $colon:tt $($dup:tt)*) $label:lifetime : $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $lifetime $colon) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) &mut $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $raw:tt $mut:tt $($dup:tt)*) &raw mut $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $raw $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $raw:tt $const:tt $($dup:tt)*) &raw const $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $raw $const) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $mut:tt $($dup:tt)*) &&mut $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $raw:tt $mut:tt $($dup:tt)*) &&raw mut $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $raw $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $raw:tt $const:tt $($dup:tt)*) &&raw const $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $raw $const) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $($dup:tt)*) && $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand) $($parse)*} ($($rest)*) $($rest)*) + }; + + // control flow constructs + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($if:tt $($dup:tt)*) if $($rest:tt)*) => { + $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $if) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($match:tt $($dup:tt)*) match $($rest:tt)*) => { + $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $match) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($while:tt $($dup:tt)*) while $($rest:tt)*) => { + $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $while) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($for:tt $($dup:tt)*) for $($rest:tt)*) => { + $crate::__parse_ensure!(pat (cond $stack) $bail ($($fuel)*) {($($buf)* $for) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom (cond $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($block:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(cond $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) + }; + + (cond $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($else:tt $if:tt $($dup:tt)*) else if $($rest:tt)*) => { + $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $else $if) $($parse)*} ($($rest)*) $($rest)*) + }; + + (cond $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($else:tt $brace:tt $($dup:tt)*) else {$($block:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $else $brace) $($parse)*} ($($rest)*) $($rest)*) + }; + + (cond $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + // atomic expressions + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($content:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($array:tt)*] $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($block:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($loop:tt $block:tt $($dup:tt)*) loop {$($body:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $loop $block) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($async:tt $block:tt $($dup:tt)*) async {$($body:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $async $block) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($async:tt $move:tt $block:tt $($dup:tt)*) async move {$($body:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $async $move $block) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($unsafe:tt $block:tt $($dup:tt)*) unsafe {$($body:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $unsafe $block) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($const:tt $block:tt $($dup:tt)*) const {$($body:tt)*} $($rest:tt)*) => { + // TODO: this is mostly useless due to https://github.com/rust-lang/rust/issues/86730 + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $const $block) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($literal:tt $($dup:tt)*) $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $literal) $($parse)*} ($($rest)*) $($rest)*) + }; + + // path expressions + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(epath (atom $stack) $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ident:tt $($dup:tt)*) $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(epath (atom $stack) $bail ($($fuel)*) {($($buf)* $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (epath (atom $stack))) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: < $($rest:tt)*) => { + $crate::__parse_ensure!(generic (epath $stack) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: << $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (tpath (arglist (epath $stack)))) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt :: <- - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $larrow:tt $($dup:tt)*) :: <- $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(generic (epath $stack) $bail ($($fuel)*) {($($buf)* $colons $larrow) $($parse)*} ($($dup)*) $($dup)*) + }; + + (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(epath $stack $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! ($($mac:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! [$($mac:tt)*] $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! {$($mac:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) + }; + + (epath (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + // trailer expressions + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($call:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($index:tt)*] $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($init:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($question:tt $($dup:tt)*) ? $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $question) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $ident:tt $colons:tt $langle:tt $($dup:tt)*) . $i:ident :: < $($rest:tt)*) => { + $crate::__parse_ensure!(generic (atom $stack) $bail ($($fuel)*) {($($buf)* $dot $ident $colons $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $ident:tt $colons:tt $langle:tt $($dup:tt)*) . $i:ident :: << $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (tpath (arglist (atom $stack)))) $bail ($($fuel)*) {($($buf)* $dot $ident $colons $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt . $i:ident :: <- - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $ident:tt $colons:tt $larrow:tt $($dup:tt)*) . $i:ident :: <- $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(generic (atom $stack) $bail ($($fuel)*) {($($buf)* $dot $ident $colons $larrow) $($parse)*} ($($dup)*) $($dup)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $field:tt $($dup:tt)*) . $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $dot $field) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt . - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $index:tt $($dup:tt)*) . $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $dot $index) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($as:tt $($dup:tt)*) as $($rest:tt)*) => { + $crate::__parse_ensure!(type (atom $stack) $bail ($($fuel)*) {($($buf)* $as) $($parse)*} ($($rest)*) $($rest)*) + }; + + // types + + (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($content:tt)*] $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($content:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($star:tt $const:tt $($dup:tt)*) *const $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $star $const) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($star:tt $mut:tt $($dup:tt)*) *mut $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $star $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $mut:tt $($dup:tt)*) & $l:lifetime mut $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) & mut $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $($dup:tt)*) & $l:lifetime $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $mut:tt $($dup:tt)*) && $l:lifetime mut $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) && mut $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $($dup:tt)*) && $l:lifetime $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) && $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt unsafe extern - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($unsafe:tt $(extern $($abi:literal)?)? fn $($dup:tt)*) unsafe $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $unsafe) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt extern - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($extern:tt $abi:tt fn $($dup:tt)*) extern $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $extern $abi) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($extern:tt fn $($dup:tt)*) extern $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $extern) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($fn:tt $paren:tt $arrow:tt $($dup:tt)*) fn ($($args:tt)*) -> $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $fn $paren $arrow) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($fn:tt $paren:tt $($dup:tt)*) fn ($($args:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $fn $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($impl:tt $($dup:tt)*) impl $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $impl) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dyn:tt $($dup:tt)*) dyn $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $dyn) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($wild:tt $($dup:tt)*) _ $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $wild) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($never:tt $($dup:tt)*) ! $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $never) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($for:tt $langle:tt $($dup:tt)*) for < $($rest:tt)*) => { + $crate::__parse_ensure!(generic (type $stack) $bail ($($fuel)*) {($($buf)* $for $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + // path types + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(tpath $stack $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ident:tt $($dup:tt)*) $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(tpath $stack $bail ($($fuel)*) {($($buf)* $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (tpath $stack)) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { + $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) << $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (tpath (arglist (tpath $stack)))) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt <- - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($larrow:tt $($dup:tt)*) <- $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $larrow) $($parse)*} ($($dup)*) $($dup)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: < $($rest:tt)*) => { + $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: << $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (tpath (arglist (tpath $stack)))) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt :: <- - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $larrow:tt $($dup:tt)*) :: <- $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $colons $larrow) $($parse)*} ($($dup)*) $($dup)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(tpath $stack $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $arrow:tt $($dup:tt)*) ($($args:tt)*) -> $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $paren $arrow) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($args:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!(object $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $paren:tt $arrow:tt $($dup:tt)*) :: ($($args:tt)*) -> $($rest:tt)*) => { + $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $colons $paren $arrow) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $paren:tt $($dup:tt)*) :: ($($args:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!(object $stack $bail ($($fuel)*) {($($buf)* $colons $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! ($($mac:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! [$($mac:tt)*] $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! {$($mac:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) + }; + + (tpath $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!(object $stack $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + // qualified paths + + (qpath (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $colons:tt $ident:tt $($dup:tt)*) >> :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (qpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $colons:tt $ident:tt $($dup:tt)*) > :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (qpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($as:tt $($dup:tt)*) as $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath $stack) $bail ($($fuel)*) {($($buf)* $as) $($parse)*} ($($rest)*) $($rest)*) + }; + + // trait objects + + (object (arglist $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($plus:tt $colons:tt $ident:tt $($dup:tt)*) + :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(tpath (arglist $stack) $bail ($($fuel)*) {($($buf)* $plus $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (object (arglist $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($plus:tt $ident:tt $($dup:tt)*) + $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(tpath (arglist $stack) $bail ($($fuel)*) {($($buf)* $plus $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (object (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + (object ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + // angle bracketed generic arguments + + (generic (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (generic ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) > $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (generic ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { + $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) {($($buf)*) $($parse)*} ($rangle $($rest)*) $rangle $($rest)*) + }; + + (generic $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($neg:tt $($dup:tt)*) - $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(generic $stack $bail ($($fuel)*) {($($buf)* $neg) $($parse)*} ($($dup)*) $($dup)*) + }; + + (generic $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($literal:tt $($dup:tt)*) $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $literal) $($parse)*} ($($rest)*) $($rest)*) + }; + + (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($block:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) + }; + + (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($lifetime:tt $($dup:tt)*) $l:lifetime $($rest:tt)*) => { + $crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $lifetime) $($parse)*} ($($rest)*) $($rest)*) + }; + + (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($assoc:tt $eq:tt $($dup:tt)*) $ident:ident = $($rest:tt)*) => { + $crate::__parse_ensure!(type (arglist $stack) $bail ($($fuel)*) {($($buf)* $assoc $eq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (generic $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { + $crate::__parse_ensure!(type (arglist $stack) $bail ($($fuel)*) $parse $dup $($rest)*) + }; + + (arglist $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($comma:tt $($dup:tt)*) , $($rest:tt)*) => { + $crate::__parse_ensure!(generic $stack $bail ($($fuel)*) {($($buf)* $comma) $($parse)*} ($($rest)*) $($rest)*) + }; + + (arglist (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)*) $rangle $($parse)*} ($($rest)*) $($rest)*) + }; + + (arglist ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) > $($rest:tt)*) => { + $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (arglist ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { + $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) {($($buf)*) $($parse)*} ($rangle $($rest)*) $rangle $($rest)*) + }; + + // patterns + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($pipe:tt $($dup:tt)*) | $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $pipe) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($eq:tt $($dup:tt)*) = $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $eq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($in:tt $($dup:tt)*) in $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $in) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ref:tt $($dup:tt)*) ref $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $ref) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($mut:tt $($dup:tt)*) mut $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $mut) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($at:tt $($dup:tt)*) @ $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $at) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($neg:tt $($dup:tt)*) - $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $neg) $($parse)*} ($($dup)*) $($dup)*) + }; + + (pat $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($literal:tt $($dup:tt)*) $lit:literal $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $literal) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($range:tt $($dup:tt)*) .. $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $range) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($range:tt $($dup:tt)*) ..= $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $range) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $($dup:tt)*) && $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $andand) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($content:tt)*) $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($content:tt)*] $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($content:tt)*} $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($wild:tt $($dup:tt)*) _ $($rest:tt)*) => { + $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $wild) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(epath (pat $stack) $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ident:tt $($dup:tt)*) $i:ident $($rest:tt)*) => { + $crate::__parse_ensure!(epath (pat $stack) $bail ($($fuel)*) {($($buf)* $ident) $($parse)*} ($($rest)*) $($rest)*) + }; + + (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { + $crate::__parse_ensure!(type (qpath (epath (pat $stack))) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) + }; + + // comparison binary operators + + (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($eq:tt $($dup:tt)*) == $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $eq} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($eq:tt $($dup:tt)*) == $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $eq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($le:tt $($dup:tt)*) <= $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $le} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($le:tt $($dup:tt)*) <= $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $le) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($lt:tt $($dup:tt)*) < $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $lt} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($lt:tt $($dup:tt)*) < $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $lt) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ne:tt $($dup:tt)*) != $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $ne} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($ne:tt $($dup:tt)*) != $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $ne) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ge:tt $($dup:tt)*) >= $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $ge} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($ge:tt $($dup:tt)*) >= $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $ge) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom (split ()) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt >> $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)* > ) > } ($($rest)*) $($rest)*) + }; + + (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($gt:tt $($dup:tt)*) > $($rest:tt)*) => { + $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $gt} ($($rest)*) $($rest)*) + }; + + (atom (split $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($gt:tt $($dup:tt)*) > $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $gt) $($parse)*} ($($rest)*) $($rest)*) + }; + + // high precedence binary operators + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($add:tt $($dup:tt)*) + $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $add) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($sub:tt $($dup:tt)*) - $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $sub) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($mul:tt $($dup:tt)*) * $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $mul) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($div:tt $($dup:tt)*) / $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $div) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rem:tt $($dup:tt)*) % $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $rem) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitxor:tt $($dup:tt)*) ^ $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $bitxor) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitand:tt $($dup:tt)*) & $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $bitand) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitor:tt $($dup:tt)*) | $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $bitor) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shl:tt $($dup:tt)*) << $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $shl) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shr:tt $($dup:tt)*) >> $($rest:tt)*) => { + $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $shr) $($parse)*} ($($rest)*) $($rest)*) + }; + + // low precedence binary operators + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) && $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($or:tt $($dup:tt)*) || $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $or) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($assign:tt $($dup:tt)*) = $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $assign) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($addeq:tt $($dup:tt)*) += $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $addeq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($subeq:tt $($dup:tt)*) -= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $subeq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($muleq:tt $($dup:tt)*) *= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $muleq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($diveq:tt $($dup:tt)*) /= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $diveq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($remeq:tt $($dup:tt)*) %= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $remeq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitxoreq:tt $($dup:tt)*) ^= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $bitxoreq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitandeq:tt $($dup:tt)*) &= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $bitandeq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitoreq:tt $($dup:tt)*) |= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $bitoreq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shleq:tt $($dup:tt)*) <<= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $shleq) $($parse)*} ($($rest)*) $($rest)*) + }; + + (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shreq:tt $($dup:tt)*) >>= $($rest:tt)*) => { + $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $shreq) $($parse)*} ($($rest)*) $($rest)*) + }; + + // unrecognized expression + + ($state:tt $stack:tt ($($bail:tt)*) $($rest:tt)*) => { + $crate::__fallback_ensure!($($bail)*) + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __fancy_ensure { + ($lhs:expr, $op:tt, $rhs:expr) => { + match (&$lhs, &$rhs) { + (lhs, rhs) => { + if !(lhs $op rhs) { + #[allow(unused_imports)] + use $crate::__private::{BothDebug, NotBothDebug}; + return Err((lhs, rhs).__dispatch_ensure( + $crate::__private::concat!( + "Condition failed: `", + $crate::__private::stringify!($lhs), + " ", + $crate::__private::stringify!($op), + " ", + $crate::__private::stringify!($rhs), + "`", + ), + )); + } + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __fallback_ensure { + ($cond:expr $(,)?) => { + if $crate::__private::not($cond) { + return $crate::__private::Err($crate::Error::msg( + $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`") + )); + } + }; + ($cond:expr, $msg:literal $(,)?) => { + if $crate::__private::not($cond) { + return $crate::__private::Err($crate::__anyhow!($msg)); + } + }; + ($cond:expr, $err:expr $(,)?) => { + if $crate::__private::not($cond) { + return $crate::__private::Err($crate::__anyhow!($err)); + } + }; + ($cond:expr, $fmt:expr, $($arg:tt)*) => { + if $crate::__private::not($cond) { + return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)); + } + }; +} diff --git a/third_party/crates/anyhow-1.0.104/src/error.rs b/third_party/crates/anyhow-1.0.104/src/error.rs new file mode 100644 index 0000000..d97df8c --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/error.rs @@ -0,0 +1,1060 @@ +use crate::backtrace::Backtrace; +use crate::chain::Chain; +#[cfg(error_generic_member_access)] +use crate::nightly::{self, Request}; +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +use crate::ptr::Mut; +use crate::ptr::{Own, Ref}; +use crate::{Error, StdError}; +use alloc::boxed::Box; +use core::any::TypeId; +use core::fmt::{self, Debug, Display}; +use core::mem::ManuallyDrop; +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +use core::ops::{Deref, DerefMut}; +use core::panic::{RefUnwindSafe, UnwindSafe}; +use core::ptr; +use core::ptr::NonNull; + +impl Error { + /// Create a new error object from any error type. + /// + /// The error type must be threadsafe and `'static`, so that the `Error` + /// will be as well. + /// + /// If the error type does not provide a backtrace, a backtrace will be + /// created here to ensure that a backtrace exists. + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[cold] + #[must_use] + pub fn new(error: E) -> Self + where + E: StdError + Send + Sync + 'static, + { + let backtrace = backtrace_if_absent!(&error); + Error::construct_from_std(error, backtrace) + } + + /// Create a new error object from a printable error message. + /// + /// If the argument implements std::error::Error, prefer `Error::new` + /// instead which preserves the underlying error's cause chain and + /// backtrace. If the argument may or may not implement std::error::Error + /// now or in the future, use `anyhow!(err)` which handles either way + /// correctly. + /// + /// `Error::msg("...")` is equivalent to `anyhow!("...")` but occasionally + /// convenient in places where a function is preferable over a macro, such + /// as iterator or stream combinators: + /// + /// ``` + /// # mod ffi { + /// # pub struct Input; + /// # pub struct Output; + /// # pub async fn do_some_work(_: Input) -> Result { + /// # unimplemented!() + /// # } + /// # } + /// # + /// # use ffi::{Input, Output}; + /// # + /// use anyhow::{Error, Result}; + /// use futures::stream::{Stream, StreamExt, TryStreamExt}; + /// + /// async fn demo(stream: S) -> Result> + /// where + /// S: Stream, + /// { + /// stream + /// .then(ffi::do_some_work) // returns Result + /// .map_err(Error::msg) + /// .try_collect() + /// .await + /// } + /// ``` + #[cold] + #[must_use] + pub fn msg(message: M) -> Self + where + M: Display + Debug + Send + Sync + 'static, + { + Error::construct_from_adhoc(message, backtrace!()) + } + + /// Construct an error object from a type-erased standard library error. + /// + /// This is mostly useful for interop with other error libraries. + /// + /// # Example + /// + /// Here is a skeleton of a library that provides its own error abstraction. + /// The pair of `From` impls provide bidirectional support for `?` + /// conversion between `Report` and `anyhow::Error`. + /// + /// ``` + /// use std::error::Error as StdError; + /// + /// pub struct Report {/* ... */} + /// + /// impl From for Report + /// where + /// E: Into, + /// Result<(), E>: anyhow::Context<(), E>, + /// { + /// fn from(error: E) -> Self { + /// let anyhow_error: anyhow::Error = error.into(); + /// let boxed_error: Box = anyhow_error.into(); + /// Report::from_boxed(boxed_error) + /// } + /// } + /// + /// impl From for anyhow::Error { + /// fn from(report: Report) -> Self { + /// let boxed_error: Box = report.into_boxed(); + /// anyhow::Error::from_boxed(boxed_error) + /// } + /// } + /// + /// impl Report { + /// fn from_boxed(boxed_error: Box) -> Self { + /// todo!() + /// } + /// fn into_boxed(self) -> Box { + /// todo!() + /// } + /// } + /// + /// // Example usage: can use `?` in both directions. + /// fn a() -> anyhow::Result<()> { + /// b()?; + /// Ok(()) + /// } + /// fn b() -> Result<(), Report> { + /// a()?; + /// Ok(()) + /// } + /// ``` + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[cold] + #[must_use] + pub fn from_boxed(boxed_error: Box) -> Self { + let backtrace = backtrace_if_absent!(&*boxed_error); + Error::construct_from_boxed(boxed_error, backtrace) + } + + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[cold] + pub(crate) fn construct_from_std(error: E, backtrace: Option) -> Self + where + E: StdError + Send + Sync + 'static, + { + let vtable = &ErrorVTable { + object_drop: object_drop::, + object_ref: object_ref::, + object_boxed: object_boxed::, + object_reallocate_boxed: object_reallocate_boxed::, + object_downcast: object_downcast::, + object_drop_rest: object_drop_front::, + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: no_backtrace, + }; + + // Safety: passing vtable that operates on the right type E. + unsafe { Error::construct(error, vtable, backtrace) } + } + + #[cold] + pub(crate) fn construct_from_adhoc(message: M, backtrace: Option) -> Self + where + M: Display + Debug + Send + Sync + 'static, + { + use crate::wrapper::MessageError; + let error: MessageError = MessageError(message); + let vtable = &ErrorVTable { + object_drop: object_drop::>, + object_ref: object_ref::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_boxed: object_boxed::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_reallocate_boxed: object_reallocate_boxed::>, + object_downcast: object_downcast::, + object_drop_rest: object_drop_front::, + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: no_backtrace, + }; + + // Safety: MessageError is repr(transparent) so it is okay for the + // vtable to allow casting the MessageError to M. + unsafe { Error::construct(error, vtable, backtrace) } + } + + #[cold] + pub(crate) fn construct_from_display(message: M, backtrace: Option) -> Self + where + M: Display + Send + Sync + 'static, + { + use crate::wrapper::DisplayError; + let error: DisplayError = DisplayError(message); + let vtable = &ErrorVTable { + object_drop: object_drop::>, + object_ref: object_ref::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_boxed: object_boxed::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_reallocate_boxed: object_reallocate_boxed::>, + object_downcast: object_downcast::, + object_drop_rest: object_drop_front::, + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: no_backtrace, + }; + + // Safety: DisplayError is repr(transparent) so it is okay for the + // vtable to allow casting the DisplayError to M. + unsafe { Error::construct(error, vtable, backtrace) } + } + + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[cold] + pub(crate) fn construct_from_context( + context: C, + error: E, + backtrace: Option, + ) -> Self + where + C: Display + Send + Sync + 'static, + E: StdError + Send + Sync + 'static, + { + let error: ContextError = ContextError { context, error }; + + let vtable = &ErrorVTable { + object_drop: object_drop::>, + object_ref: object_ref::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_boxed: object_boxed::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_reallocate_boxed: object_reallocate_boxed::>, + object_downcast: context_downcast::, + object_drop_rest: context_drop_rest::, + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: no_backtrace, + }; + + // Safety: passing vtable that operates on the right type. + unsafe { Error::construct(error, vtable, backtrace) } + } + + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[cold] + pub(crate) fn construct_from_boxed( + error: Box, + backtrace: Option, + ) -> Self { + use crate::wrapper::BoxedError; + let error = BoxedError(error); + let vtable = &ErrorVTable { + object_drop: object_drop::, + object_ref: object_ref::, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_boxed: object_boxed::, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_reallocate_boxed: object_reallocate_boxed::, + object_downcast: object_downcast::>, + object_drop_rest: object_drop_front::>, + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: no_backtrace, + }; + + // Safety: BoxedError is repr(transparent) so it is okay for the vtable + // to allow casting to Box. + unsafe { Error::construct(error, vtable, backtrace) } + } + + // Takes backtrace as argument rather than capturing it here so that the + // user sees one fewer layer of wrapping noise in the backtrace. + // + // Unsafe because the given vtable must have sensible behavior on the error + // value of type E. + #[cold] + unsafe fn construct( + error: E, + vtable: &'static ErrorVTable, + backtrace: Option, + ) -> Self + where + E: StdError + Send + Sync + 'static, + { + let inner: Box> = Box::new(ErrorImpl { + vtable, + backtrace, + _object: error, + }); + // Erase the concrete type of E from the compile-time type system. This + // is equivalent to the safe unsize coercion from Box> to + // Box> except that the + // result is a thin pointer. The necessary behavior for manipulating the + // underlying ErrorImpl is preserved in the vtable provided by the + // caller rather than a builtin fat pointer vtable. + let inner = Own::new(inner).cast::(); + Error { inner } + } + + /// Wrap the error value with additional context. + /// + /// For attaching context to a `Result` as it is propagated, the + /// [`Context`][crate::Context] extension trait may be more convenient than + /// this function. + /// + /// The primary reason to use `error.context(...)` instead of + /// `result.context(...)` via the `Context` trait would be if the context + /// needs to depend on some data held by the underlying error: + /// + /// ``` + /// # use std::fmt::{self, Debug, Display}; + /// # + /// # type T = (); + /// # + /// # impl std::error::Error for ParseError {} + /// # impl Debug for ParseError { + /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + /// # unimplemented!() + /// # } + /// # } + /// # impl Display for ParseError { + /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + /// # unimplemented!() + /// # } + /// # } + /// # + /// use anyhow::Result; + /// use std::fs::File; + /// use std::path::Path; + /// + /// struct ParseError { + /// line: usize, + /// column: usize, + /// } + /// + /// fn parse_impl(file: File) -> Result { + /// # const IGNORE: &str = stringify! { + /// ... + /// # }; + /// # unimplemented!() + /// } + /// + /// pub fn parse(path: impl AsRef) -> Result { + /// let file = File::open(&path)?; + /// parse_impl(file).map_err(|error| { + /// let context = format!( + /// "only the first {} lines of {} are valid", + /// error.line, path.as_ref().display(), + /// ); + /// anyhow::Error::new(error).context(context) + /// }) + /// } + /// ``` + #[cold] + #[must_use] + pub fn context(self, context: C) -> Self + where + C: Display + Send + Sync + 'static, + { + let error: ContextError = ContextError { + context, + error: self, + }; + + let vtable = &ErrorVTable { + object_drop: object_drop::>, + object_ref: object_ref::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_boxed: object_boxed::>, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_reallocate_boxed: object_reallocate_boxed::>, + object_downcast: context_chain_downcast::, + object_drop_rest: context_chain_drop_rest::, + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: context_backtrace::, + }; + + // As the cause is anyhow::Error, we already have a backtrace for it. + let backtrace = None; + + // Safety: passing vtable that operates on the right type. + unsafe { Error::construct(error, vtable, backtrace) } + } + + /// Get the backtrace for this Error. + /// + /// 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`. + /// + /// # Stability + /// + /// 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 return type of this + /// function on old compilers is `&(impl Debug + Display)`. + /// + /// ```toml + /// [dependencies] + /// anyhow = { version = "1.0", features = ["backtrace"] } + /// ``` + #[cfg(feature = "std")] + pub fn backtrace(&self) -> &Backtrace { + unsafe { ErrorImpl::backtrace(self.inner.by_ref()) } + } + + /// An iterator of the chain of source errors contained by this Error. + /// + /// This iterator will visit every error in the cause chain of this error + /// object, beginning with the error that this error object was created + /// from. + /// + /// # Example + /// + /// ``` + /// use anyhow::Error; + /// use std::io; + /// + /// pub fn underlying_io_error_kind(error: &Error) -> Option { + /// for cause in error.chain() { + /// if let Some(io_error) = cause.downcast_ref::() { + /// return Some(io_error.kind()); + /// } + /// } + /// None + /// } + /// ``` + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[cold] + pub fn chain(&self) -> Chain { + unsafe { ErrorImpl::chain(self.inner.by_ref()) } + } + + /// The lowest level cause of this error — this error's cause's + /// cause's cause etc. + /// + /// The root cause is the last error in the iterator produced by + /// [`chain()`][Error::chain]. + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[allow(clippy::double_ended_iterator_last)] + pub fn root_cause(&self) -> &(dyn StdError + 'static) { + self.chain().last().unwrap() + } + + /// Returns true if `E` is the type held by this error object. + /// + /// For errors with context, this method returns true if `E` matches the + /// type of the context `C` **or** the type of the error on which the + /// context has been attached. For details about the interaction between + /// context and downcasting, [see here]. + /// + /// [see here]: crate::Context#effect-on-downcasting + pub fn is(&self) -> bool + where + E: Display + Debug + Send + Sync + 'static, + { + self.downcast_ref::().is_some() + } + + /// Attempt to downcast the error object to a concrete type. + pub fn downcast(mut self) -> Result + where + E: Display + Debug + Send + Sync + 'static, + { + let target = TypeId::of::(); + let inner = self.inner.by_mut(); + unsafe { + // Use vtable to find NonNull<()> which points to a value of type E + // somewhere inside the data structure. + let addr = match (vtable(inner.ptr).object_downcast)(inner.by_ref(), target) { + Some(addr) => addr.by_mut().extend(), + None => return Err(self), + }; + + // Prepare to read E out of the data structure. We'll drop the rest + // of the data structure separately so that E is not dropped. + let outer = ManuallyDrop::new(self); + + // Read E from where the vtable found it. + let error = addr.cast::().read(); + + // Drop rest of the data structure outside of E. + (vtable(outer.inner.ptr).object_drop_rest)(outer.inner, target); + + Ok(error) + } + } + + /// Downcast this error object by reference. + /// + /// # Example + /// + /// ``` + /// # use anyhow::anyhow; + /// # use std::fmt::{self, Display}; + /// # use std::task::Poll; + /// # + /// # #[derive(Debug)] + /// # enum DataStoreError { + /// # Censored(()), + /// # } + /// # + /// # impl Display for DataStoreError { + /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + /// # unimplemented!() + /// # } + /// # } + /// # + /// # impl std::error::Error for DataStoreError {} + /// # + /// # const REDACTED_CONTENT: () = (); + /// # + /// # let error = anyhow!("..."); + /// # let root_cause = &error; + /// # + /// # let ret = + /// // If the error was caused by redaction, then return a tombstone instead + /// // of the content. + /// match root_cause.downcast_ref::() { + /// Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), + /// None => Err(error), + /// } + /// # ; + /// ``` + pub fn downcast_ref(&self) -> Option<&E> + where + E: Display + Debug + Send + Sync + 'static, + { + let target = TypeId::of::(); + unsafe { + // Use vtable to find NonNull<()> which points to a value of type E + // somewhere inside the data structure. + let addr = (vtable(self.inner.ptr).object_downcast)(self.inner.by_ref(), target)?; + Some(addr.cast::().deref()) + } + } + + /// Downcast this error object by mutable reference. + pub fn downcast_mut(&mut self) -> Option<&mut E> + where + E: Display + Debug + Send + Sync + 'static, + { + let target = TypeId::of::(); + unsafe { + // Use vtable to find NonNull<()> which points to a value of type E + // somewhere inside the data structure. + let addr = + (vtable(self.inner.ptr).object_downcast)(self.inner.by_ref(), target)?.by_mut(); + Some(addr.cast::().deref_mut()) + } + } + + /// Convert to a standard library error trait object. + /// + /// This is implemented as a cheap pointer cast that does not allocate or + /// deallocate memory. Like [`anyhow::Error::from_boxed`], it's useful for + /// interop with other error libraries. + /// + /// The same conversion is also available as + /// impl From<anyhow::Error> + /// for Box<dyn Error + Send + Sync + 'static>. + /// + /// If a backtrace was collected during construction of the `anyhow::Error`, + /// that backtrace remains accessible using the standard library `Error` + /// trait's provider API, but as a consequence, the resulting boxed error + /// can no longer be downcast to its original underlying type. + /// + /// ``` + #[cfg_attr(not(error_generic_member_access), doc = "# _ = stringify! {")] + /// #![feature(error_generic_member_access)] + /// + /// use anyhow::anyhow; + /// use std::backtrace::Backtrace; + /// use thiserror::Error; + /// + /// #[derive(Error, Debug)] + /// #[error("...")] + /// struct MyError; + /// + /// let anyhow_error = anyhow!(MyError); + /// println!("{}", anyhow_error.backtrace()); // has Backtrace + /// assert!(anyhow_error.downcast_ref::().is_some()); // can downcast + /// + /// let boxed_dyn_error = anyhow_error.into_boxed_dyn_error(); + /// assert!(std::error::request_ref::(&*boxed_dyn_error).is_some()); // has Backtrace + /// assert!(boxed_dyn_error.downcast_ref::().is_none()); // can no longer downcast + #[cfg_attr(not(error_generic_member_access), doc = "# };")] + /// ``` + /// + /// [`anyhow::Error::from_boxed`]: Self::from_boxed + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[must_use] + pub fn into_boxed_dyn_error(self) -> Box { + let outer = ManuallyDrop::new(self); + unsafe { + // Use vtable to attach ErrorImpl's native StdError vtable for + // the right original type E. + (vtable(outer.inner.ptr).object_boxed)(outer.inner) + } + } + + /// Convert to a standard library error trait object. + /// + /// Unlike `self.into_boxed_dyn_error()`, this method relocates the + /// underlying error into a new allocation in order to make it downcastable + /// to `&E` or `Box` for its original underlying error type. Any + /// backtrace collected during construction of the `anyhow::Error` is + /// discarded. + /// + /// ``` + #[cfg_attr(not(error_generic_member_access), doc = "# _ = stringify!{")] + /// #![feature(error_generic_member_access)] + /// + /// use anyhow::anyhow; + /// use std::backtrace::Backtrace; + /// use thiserror::Error; + /// + /// #[derive(Error, Debug)] + /// #[error("...")] + /// struct MyError; + /// + /// let anyhow_error = anyhow!(MyError); + /// println!("{}", anyhow_error.backtrace()); // has Backtrace + /// assert!(anyhow_error.downcast_ref::().is_some()); // can downcast + /// + /// let boxed_dyn_error = anyhow_error.reallocate_into_boxed_dyn_error_without_backtrace(); + /// assert!(std::error::request_ref::(&*boxed_dyn_error).is_none()); // Backtrace lost + /// assert!(boxed_dyn_error.downcast_ref::().is_some()); // can downcast to &MyError + /// assert!(boxed_dyn_error.downcast::().is_ok()); // can downcast to Box + #[cfg_attr(not(error_generic_member_access), doc = "# };")] + /// ``` + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[must_use] + pub fn reallocate_into_boxed_dyn_error_without_backtrace( + self, + ) -> Box { + let outer = ManuallyDrop::new(self); + unsafe { + // Use vtable to attach E's native StdError vtable for the right + // original type E. + (vtable(outer.inner.ptr).object_reallocate_boxed)(outer.inner) + } + } + + #[cfg(error_generic_member_access)] + pub(crate) fn provide<'a>(&'a self, request: &mut Request<'a>) { + unsafe { ErrorImpl::provide(self.inner.by_ref(), request) } + } + + // Called by thiserror when you have `#[source] anyhow::Error`. This provide + // implementation includes the anyhow::Error's Backtrace if any, unlike + // deref'ing to dyn Error where the provide implementation would include + // only the original error's Backtrace from before it got wrapped into an + // anyhow::Error. + #[cfg(error_generic_member_access)] + #[doc(hidden)] + pub fn thiserror_provide<'a>(&'a self, request: &mut Request<'a>) { + Self::provide(self, request); + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl From for Error +where + E: StdError + Send + Sync + 'static, +{ + #[cold] + fn from(error: E) -> Self { + let backtrace = backtrace_if_absent!(&error); + Error::construct_from_std(error, backtrace) + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl Deref for Error { + type Target = dyn StdError + Send + Sync + 'static; + + fn deref(&self) -> &Self::Target { + unsafe { ErrorImpl::error(self.inner.by_ref()) } + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl DerefMut for Error { + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { ErrorImpl::error_mut(self.inner.by_mut()) } + } +} + +impl Display for Error { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + unsafe { ErrorImpl::display(self.inner.by_ref(), formatter) } + } +} + +impl Debug for Error { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + unsafe { ErrorImpl::debug(self.inner.by_ref(), formatter) } + } +} + +impl Drop for Error { + fn drop(&mut self) { + unsafe { + // Invoke the vtable's drop behavior. + (vtable(self.inner.ptr).object_drop)(self.inner); + } + } +} + +struct ErrorVTable { + object_drop: unsafe fn(Own), + object_ref: unsafe fn(Ref) -> Ref, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_boxed: unsafe fn(Own) -> Box, + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + object_reallocate_boxed: unsafe fn(Own) -> Box, + object_downcast: unsafe fn(Ref, TypeId) -> Option>, + object_drop_rest: unsafe fn(Own, TypeId), + #[cfg(all(not(error_generic_member_access), feature = "std"))] + object_backtrace: unsafe fn(Ref) -> Option<&Backtrace>, +} + +// Safety: requires layout of *e to match ErrorImpl. +unsafe fn object_drop(e: Own) { + // Cast back to ErrorImpl so that the allocator receives the correct + // Layout to deallocate the Box's memory. + let unerased_own = e.cast::>(); + drop(unsafe { unerased_own.boxed() }); +} + +// Safety: requires layout of *e to match ErrorImpl. +unsafe fn object_drop_front(e: Own, target: TypeId) { + // Drop the fields of ErrorImpl other than E as well as the Box allocation, + // without dropping E itself. This is used by downcast after doing a + // ptr::read to take ownership of the E. + let _ = target; + let unerased_own = e.cast::>>(); + drop(unsafe { unerased_own.boxed() }); +} + +// Safety: requires layout of *e to match ErrorImpl. +unsafe fn object_ref(e: Ref) -> Ref +where + E: StdError + Send + Sync + 'static, +{ + // Attach E's native StdError vtable onto a pointer to self._object. + let unerased_ref = e.cast::>(); + Ref::from_raw(unsafe { + NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut()) + }) +} + +// Safety: requires layout of *e to match ErrorImpl. +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +unsafe fn object_boxed(e: Own) -> Box +where + E: StdError + Send + Sync + 'static, +{ + // Attach ErrorImpl's native StdError vtable. The StdError impl is below. + let unerased_own = e.cast::>(); + unsafe { unerased_own.boxed() } +} + +// Safety: requires layout of *e to match ErrorImpl. +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +unsafe fn object_reallocate_boxed(e: Own) -> Box +where + E: StdError + Send + Sync + 'static, +{ + // Attach E's native StdError vtable. + let unerased_own = e.cast::>(); + Box::new(unsafe { unerased_own.boxed() }._object) +} + +// Safety: requires layout of *e to match ErrorImpl. +unsafe fn object_downcast(e: Ref, target: TypeId) -> Option> +where + E: 'static, +{ + if TypeId::of::() == target { + // Caller is looking for an E pointer and e is ErrorImpl, take a + // pointer to its E field. + let unerased_ref = e.cast::>(); + Some( + Ref::from_raw(unsafe { + NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut()) + }) + .cast::<()>(), + ) + } else { + None + } +} + +#[cfg(all(not(error_generic_member_access), feature = "std"))] +fn no_backtrace(e: Ref) -> Option<&Backtrace> { + let _ = e; + None +} + +// Safety: requires layout of *e to match ErrorImpl>. +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +unsafe fn context_downcast(e: Ref, target: TypeId) -> Option> +where + C: 'static, + E: 'static, +{ + if TypeId::of::() == target { + let unerased_ref = e.cast::>>(); + let inner = unsafe { ptr::addr_of!((*unerased_ref.as_ptr())._object.context) }; + Some(Ref::from_raw(unsafe { NonNull::new_unchecked(inner.cast_mut()) }).cast::<()>()) + } else if TypeId::of::() == target { + let unerased_ref = e.cast::>>(); + let inner = unsafe { ptr::addr_of!((*unerased_ref.as_ptr())._object.error) }; + Some(Ref::from_raw(unsafe { NonNull::new_unchecked(inner.cast_mut()) }).cast::<()>()) + } else { + None + } +} + +// Safety: requires layout of *e to match ErrorImpl>. +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +unsafe fn context_drop_rest(e: Own, target: TypeId) +where + C: 'static, + E: 'static, +{ + // Called after downcasting by value to either the C or the E and doing a + // ptr::read to take ownership of that value. + if TypeId::of::() == target { + let unerased_own = e.cast::, E>>>(); + drop(unsafe { unerased_own.boxed() }); + } else { + let unerased_own = e.cast::>>>(); + drop(unsafe { unerased_own.boxed() }); + } +} + +// Safety: requires layout of *e to match ErrorImpl>. +unsafe fn context_chain_downcast(e: Ref, target: TypeId) -> Option> +where + C: 'static, +{ + let unerased_ref = e.cast::>>(); + if TypeId::of::() == target { + let inner = unsafe { ptr::addr_of!((*unerased_ref.as_ptr())._object.context) }; + Some(Ref::from_raw(unsafe { NonNull::new_unchecked(inner.cast_mut()) }).cast::<()>()) + } else { + // Recurse down the context chain per the inner error's vtable. + let unerased = unsafe { unerased_ref.deref() }; + let source = &unerased._object.error; + unsafe { (vtable(source.inner.ptr).object_downcast)(source.inner.by_ref(), target) } + } +} + +// Safety: requires layout of *e to match ErrorImpl>. +unsafe fn context_chain_drop_rest(e: Own, target: TypeId) +where + C: 'static, +{ + // Called after downcasting by value to either the C or one of the causes + // and doing a ptr::read to take ownership of that value. + if TypeId::of::() == target { + let unerased_own = e.cast::, Error>>>(); + // Drop the entire rest of the data structure rooted in the next Error. + drop(unsafe { unerased_own.boxed() }); + } else { + let unerased_own = e.cast::>>>(); + let unerased = unsafe { unerased_own.boxed() }; + // Read the Own from the next error. + let inner = unerased._object.error.inner; + drop(unerased); + let vtable = unsafe { vtable(inner.ptr) }; + // Recursively drop the next error using the same target typeid. + unsafe { (vtable.object_drop_rest)(inner, target) }; + } +} + +// Safety: requires layout of *e to match ErrorImpl>. +#[cfg(all(not(error_generic_member_access), feature = "std"))] +#[allow(clippy::unnecessary_wraps)] +unsafe fn context_backtrace(e: Ref) -> Option<&Backtrace> +where + C: 'static, +{ + let unerased_ref = e.cast::>>(); + let unerased = unsafe { unerased_ref.deref() }; + let backtrace = unsafe { ErrorImpl::backtrace(unerased._object.error.inner.by_ref()) }; + Some(backtrace) +} + +// NOTE: If working with `ErrorImpl<()>`, references should be avoided in favor +// of raw pointers and `NonNull`. +// repr C to ensure that E remains in the final position. +#[repr(C)] +pub(crate) struct ErrorImpl { + vtable: &'static ErrorVTable, + backtrace: Option, + // NOTE: Don't use directly. Use only through vtable. Erased type may have + // different alignment. + _object: E, +} + +// Reads the vtable out of `p`. This is the same as `p.as_ref().vtable`, but +// avoids converting `p` into a reference. +unsafe fn vtable(p: NonNull) -> &'static ErrorVTable { + // NOTE: This assumes that `ErrorVTable` is the first field of ErrorImpl. + unsafe { *(p.as_ptr() as *const &'static ErrorVTable) } +} + +// repr C to ensure that ContextError has the same layout as +// ContextError, E> and ContextError>. +#[repr(C)] +pub(crate) struct ContextError { + pub context: C, + pub error: E, +} + +impl ErrorImpl { + fn erase(&self) -> Ref { + // Erase the concrete type of E but preserve the vtable in self.vtable + // for manipulating the resulting thin pointer. This is analogous to an + // unsize coercion. + Ref::new(self).cast::() + } +} + +impl ErrorImpl { + pub(crate) unsafe fn error(this: Ref) -> &(dyn StdError + Send + Sync + 'static) { + // Use vtable to attach E's native StdError vtable for the right + // original type E. + unsafe { (vtable(this.ptr).object_ref)(this).deref() } + } + + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + pub(crate) unsafe fn error_mut(this: Mut) -> &mut (dyn StdError + Send + Sync + 'static) { + // Use vtable to attach E's native StdError vtable for the right + // original type E. + unsafe { + (vtable(this.ptr).object_ref)(this.by_ref()) + .by_mut() + .deref_mut() + } + } + + #[cfg(feature = "std")] + pub(crate) unsafe fn backtrace(this: Ref) -> &Backtrace { + // This unwrap can only panic if the underlying error's backtrace method + // is nondeterministic, which would only happen in maliciously + // constructed code. + unsafe { this.deref() } + .backtrace + .as_ref() + .or_else(|| { + #[cfg(error_generic_member_access)] + return nightly::request_ref_backtrace(unsafe { Self::error(this) }); + #[cfg(not(error_generic_member_access))] + return unsafe { (vtable(this.ptr).object_backtrace)(this) }; + }) + .expect("backtrace capture failed") + } + + #[cfg(error_generic_member_access)] + unsafe fn provide<'a>(this: Ref<'a, Self>, request: &mut Request<'a>) { + if let Some(backtrace) = unsafe { &this.deref().backtrace } { + nightly::provide_ref_backtrace(request, backtrace); + } + nightly::provide(unsafe { Self::error(this) }, request); + } + + #[cold] + pub(crate) unsafe fn chain(this: Ref) -> Chain { + Chain::new(unsafe { Self::error(this) }) + } +} + +impl StdError for ErrorImpl +where + E: StdError, +{ + fn source(&self) -> Option<&(dyn StdError + 'static)> { + unsafe { ErrorImpl::error(self.erase()).source() } + } + + #[cfg(error_generic_member_access)] + fn provide<'a>(&'a self, request: &mut Request<'a>) { + unsafe { ErrorImpl::provide(self.erase(), request) } + } +} + +impl Debug for ErrorImpl +where + E: Debug, +{ + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + unsafe { ErrorImpl::debug(self.erase(), formatter) } + } +} + +impl Display for ErrorImpl +where + E: Display, +{ + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + unsafe { Display::fmt(ErrorImpl::error(self.erase()), formatter) } + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl From for Box { + #[cold] + fn from(error: Error) -> Self { + error.into_boxed_dyn_error() + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl From for Box { + #[cold] + fn from(error: Error) -> Self { + error.into_boxed_dyn_error() + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl From for Box { + #[cold] + fn from(error: Error) -> Self { + error.into_boxed_dyn_error() + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl AsRef for Error { + fn as_ref(&self) -> &(dyn StdError + Send + Sync + 'static) { + &**self + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl AsRef for Error { + fn as_ref(&self) -> &(dyn StdError + 'static) { + &**self + } +} + +impl UnwindSafe for Error {} +impl RefUnwindSafe for Error {} diff --git a/third_party/crates/anyhow-1.0.104/src/fmt.rs b/third_party/crates/anyhow-1.0.104/src/fmt.rs new file mode 100644 index 0000000..9a108cb --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/fmt.rs @@ -0,0 +1,158 @@ +use crate::chain::Chain; +use crate::error::ErrorImpl; +use crate::ptr::Ref; +use core::fmt::{self, Debug, Write}; + +impl ErrorImpl { + pub(crate) unsafe fn display(this: Ref, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", unsafe { Self::error(this) })?; + + if f.alternate() { + let chain = unsafe { Self::chain(this) }; + for cause in chain.skip(1) { + write!(f, ": {}", cause)?; + } + } + + Ok(()) + } + + pub(crate) unsafe fn debug(this: Ref, f: &mut fmt::Formatter) -> fmt::Result { + let error = unsafe { Self::error(this) }; + + if f.alternate() { + return Debug::fmt(error, f); + } + + write!(f, "{}", error)?; + + if let Some(cause) = error.source() { + write!(f, "\n\nCaused by:")?; + let multiple = cause.source().is_some(); + for (n, error) in Chain::new(cause).enumerate() { + writeln!(f)?; + let mut indented = Indented { + inner: f, + number: if multiple { Some(n) } else { None }, + started: false, + }; + write!(indented, "{}", error)?; + } + } + + #[cfg(feature = "std")] + { + use alloc::string::ToString; + use std::backtrace::BacktraceStatus; + + let backtrace = unsafe { Self::backtrace(this) }; + if let BacktraceStatus::Captured = backtrace.status() { + let mut backtrace = backtrace.to_string(); + write!(f, "\n\n")?; + if backtrace.starts_with("stack backtrace:") { + // Capitalize to match "Caused by:" + backtrace.replace_range(0..1, "S"); + } else { + // "stack backtrace:" prefix was removed in + // https://github.com/rust-lang/backtrace-rs/pull/286 + writeln!(f, "Stack backtrace:")?; + } + backtrace.truncate(backtrace.trim_end().len()); + write!(f, "{}", backtrace)?; + } + } + + Ok(()) + } +} + +struct Indented<'a, D> { + inner: &'a mut D, + number: Option, + started: bool, +} + +impl Write for Indented<'_, T> +where + T: Write, +{ + fn write_str(&mut self, s: &str) -> fmt::Result { + for (i, line) in s.split('\n').enumerate() { + if !self.started { + self.started = true; + match self.number { + Some(number) => write!(self.inner, "{: >5}: ", number)?, + None => self.inner.write_str(" ")?, + } + } else if i > 0 { + self.inner.write_char('\n')?; + if self.number.is_some() { + self.inner.write_str(" ")?; + } else { + self.inner.write_str(" ")?; + } + } + + self.inner.write_str(line)?; + } + + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use alloc::string::String; + + #[test] + fn one_digit() { + let input = "verify\nthis"; + let expected = " 2: verify\n this"; + let mut output = String::new(); + + Indented { + inner: &mut output, + number: Some(2), + started: false, + } + .write_str(input) + .unwrap(); + + assert_eq!(expected, output); + } + + #[test] + fn two_digits() { + let input = "verify\nthis"; + let expected = " 12: verify\n this"; + let mut output = String::new(); + + Indented { + inner: &mut output, + number: Some(12), + started: false, + } + .write_str(input) + .unwrap(); + + assert_eq!(expected, output); + } + + #[test] + fn no_digits() { + let input = "verify\nthis"; + let expected = " verify\n this"; + let mut output = String::new(); + + Indented { + inner: &mut output, + number: None, + started: false, + } + .write_str(input) + .unwrap(); + + assert_eq!(expected, output); + } +} diff --git a/third_party/crates/anyhow-1.0.104/src/kind.rs b/third_party/crates/anyhow-1.0.104/src/kind.rs new file mode 100644 index 0000000..a9f40c3 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/kind.rs @@ -0,0 +1,121 @@ +// Tagged dispatch mechanism for resolving the behavior of `anyhow!($expr)`. +// +// When anyhow! is given a single expr argument to turn into anyhow::Error, we +// want the resulting Error to pick up the input's implementation of source() +// and backtrace() if it has a std::error::Error impl, otherwise require nothing +// more than Display and Debug. +// +// Expressed in terms of specialization, we want something like: +// +// trait AnyhowNew { +// fn new(self) -> Error; +// } +// +// impl AnyhowNew for T +// where +// T: Display + Debug + Send + Sync + 'static, +// { +// default fn new(self) -> Error { +// /* no std error impl */ +// } +// } +// +// impl AnyhowNew for T +// where +// T: std::error::Error + Send + Sync + 'static, +// { +// fn new(self) -> Error { +// /* use std error's source() and backtrace() */ +// } +// } +// +// Since specialization is not stable yet, instead we rely on autoref behavior +// of method resolution to perform tagged dispatch. Here we have two traits +// AdhocKind and TraitKind that both have an anyhow_kind() method. AdhocKind is +// implemented whether or not the caller's type has a std error impl, while +// TraitKind is implemented only when a std error impl does exist. The ambiguity +// is resolved by AdhocKind requiring an extra autoref so that it has lower +// precedence. +// +// The anyhow! macro will set up the call in this form: +// +// #[allow(unused_imports)] +// use $crate::__private::{AdhocKind, TraitKind}; +// let error = $msg; +// (&error).anyhow_kind().new(error) + +use crate::Error; +use core::fmt::{Debug, Display}; + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +use crate::StdError; +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +use alloc::boxed::Box; + +pub struct Adhoc; + +#[doc(hidden)] +pub trait AdhocKind: Sized { + #[inline] + fn anyhow_kind(&self) -> Adhoc { + Adhoc + } +} + +impl AdhocKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {} + +impl Adhoc { + #[cold] + pub fn new(self, message: M) -> Error + where + M: Display + Debug + Send + Sync + 'static, + { + Error::construct_from_adhoc(message, backtrace!()) + } +} + +pub struct Trait; + +#[doc(hidden)] +pub trait TraitKind: Sized { + #[inline] + fn anyhow_kind(&self) -> Trait { + Trait + } +} + +impl TraitKind for E where E: Into {} + +impl Trait { + #[cold] + pub fn new(self, error: E) -> Error + where + E: Into, + { + error.into() + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +pub struct Boxed; + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +#[doc(hidden)] +pub trait BoxedKind: Sized { + #[inline] + fn anyhow_kind(&self) -> Boxed { + Boxed + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl BoxedKind for Box {} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl Boxed { + #[cold] + pub fn new(self, error: Box) -> Error { + let backtrace = backtrace_if_absent!(&*error); + Error::construct_from_boxed(error, backtrace) + } +} diff --git a/third_party/crates/anyhow-1.0.104/src/lib.rs b/third_party/crates/anyhow-1.0.104/src/lib.rs new file mode 100644 index 0000000..2b5760d --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/lib.rs @@ -0,0 +1,728 @@ +//! [![github]](https://github.com/dtolnay/anyhow) [![crates-io]](https://crates.io/crates/anyhow) [![docs-rs]](https://docs.rs/anyhow) +//! +//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github +//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust +//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs +//! +//!
+//! +//! This library provides [`anyhow::Error`][Error], a trait object based error +//! type for easy idiomatic error handling in Rust applications. +//! +//!
+//! +//! # Details +//! +//! - Use `Result`, or equivalently `anyhow::Result`, as +//! the return type of any fallible function. +//! +//! Within the function, use `?` to easily propagate any error that implements +//! the [`std::error::Error`] trait. +//! +//! ``` +//! # pub trait Deserialize {} +//! # +//! # mod serde_json { +//! # use super::Deserialize; +//! # use std::io; +//! # +//! # pub fn from_str(json: &str) -> io::Result { +//! # unimplemented!() +//! # } +//! # } +//! # +//! # struct ClusterMap; +//! # +//! # impl Deserialize for ClusterMap {} +//! # +//! use anyhow::Result; +//! +//! fn get_cluster_info() -> Result { +//! let config = std::fs::read_to_string("cluster.json")?; +//! let map: ClusterMap = serde_json::from_str(&config)?; +//! Ok(map) +//! } +//! # +//! # fn main() {} +//! ``` +//! +//! - Attach context to help the person troubleshooting the error understand +//! where things went wrong. A low-level error like "No such file or +//! directory" can be annoying to debug without more context about what higher +//! level step the application was in the middle of. +//! +//! ``` +//! # struct It; +//! # +//! # impl It { +//! # fn detach(&self) -> Result<()> { +//! # unimplemented!() +//! # } +//! # } +//! # +//! use anyhow::{Context, Result}; +//! +//! fn main() -> Result<()> { +//! # return Ok(()); +//! # +//! # const _: &str = stringify! { +//! ... +//! # }; +//! # +//! # let it = It; +//! # let path = "./path/to/instrs.json"; +//! # +//! it.detach().context("Failed to detach the important thing")?; +//! +//! let content = std::fs::read(path) +//! .with_context(|| format!("Failed to read instrs from {}", path))?; +//! # +//! # const _: &str = stringify! { +//! ... +//! # }; +//! # +//! # Ok(()) +//! } +//! ``` +//! +//! ```console +//! Error: Failed to read instrs from ./path/to/instrs.json +//! +//! Caused by: +//! No such file or directory (os error 2) +//! ``` +//! +//! - Downcasting is supported and can be by value, by shared reference, or by +//! mutable reference as needed. +//! +//! ``` +//! # use anyhow::anyhow; +//! # use std::fmt::{self, Display}; +//! # use std::task::Poll; +//! # +//! # #[derive(Debug)] +//! # enum DataStoreError { +//! # Censored(()), +//! # } +//! # +//! # impl Display for DataStoreError { +//! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { +//! # unimplemented!() +//! # } +//! # } +//! # +//! # impl std::error::Error for DataStoreError {} +//! # +//! # const REDACTED_CONTENT: () = (); +//! # +//! # let error = anyhow!("..."); +//! # let root_cause = &error; +//! # +//! # let ret = +//! // If the error was caused by redaction, then return a +//! // tombstone instead of the content. +//! match root_cause.downcast_ref::() { +//! Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), +//! None => Err(error), +//! } +//! # ; +//! ``` +//! +//! - 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`; +//! - 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`]: std::backtrace#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 but you can write the impls yourself or use a standalone macro like +//! [thiserror]. +//! +//! [thiserror]: https://github.com/dtolnay/thiserror +//! +//! ``` +//! use thiserror::Error; +//! +//! #[derive(Error, Debug)] +//! pub enum FormatError { +//! #[error("Invalid header (expected {expected:?}, got {found:?})")] +//! InvalidHeader { +//! expected: String, +//! found: String, +//! }, +//! #[error("Missing attribute: {0}")] +//! MissingAttribute(String), +//! } +//! ``` +//! +//! - One-off error messages can be constructed using the `anyhow!` macro, which +//! supports string interpolation and produces an `anyhow::Error`. +//! +//! ``` +//! # use anyhow::{anyhow, Result}; +//! # +//! # fn demo() -> Result<()> { +//! # let missing = "..."; +//! return Err(anyhow!("Missing attribute: {}", missing)); +//! # Ok(()) +//! # } +//! ``` +//! +//! A `bail!` macro is provided as a shorthand for the same early return. +//! +//! ``` +//! # use anyhow::{bail, Result}; +//! # +//! # fn demo() -> Result<()> { +//! # let missing = "..."; +//! bail!("Missing attribute: {}", missing); +//! # Ok(()) +//! # } +//! ``` +//! +//!
+//! +//! # No-std support +//! +//! In no_std mode, almost all of the same API is available and works the same +//! way. To depend on Anyhow in no_std mode, disable our default enabled "std" +//! feature in Cargo.toml. A global allocator is required. +//! +//! ```toml +//! [dependencies] +//! anyhow = { version = "1.0", default-features = false } +//! ``` +//! +//! With versions of Rust older than 1.81, no_std mode may require an additional +//! `.map_err(Error::msg)` when working with a non-Anyhow error type inside a +//! function that returns Anyhow's error type, as the trait that `?`-based error +//! conversions are defined by is only available in std in those old versions. + +#![doc(html_root_url = "https://docs.rs/anyhow/1.0.104")] +#![cfg_attr(error_generic_member_access, feature(error_generic_member_access))] +#![no_std] +#![deny(dead_code, unsafe_op_in_unsafe_fn, unused_imports, unused_mut)] +#![allow( + clippy::doc_markdown, + clippy::elidable_lifetime_names, + clippy::enum_glob_use, + clippy::explicit_auto_deref, + clippy::extra_unused_type_parameters, + clippy::incompatible_msrv, + clippy::let_underscore_untyped, + clippy::missing_errors_doc, + clippy::missing_panics_doc, + clippy::module_name_repetitions, + clippy::must_use_candidate, + clippy::needless_doctest_main, + clippy::needless_lifetimes, + clippy::new_ret_no_self, + clippy::redundant_else, + clippy::return_self_not_must_use, + clippy::struct_field_names, + clippy::uninlined_format_args, + clippy::unused_self, + clippy::used_underscore_binding, + clippy::wildcard_imports, + clippy::wrong_self_convention +)] +#![allow(unknown_lints, mismatched_lifetime_syntaxes)] + +#[cfg(all( + anyhow_nightly_testing, + feature = "std", + not(error_generic_member_access) +))] +compile_error!("Build script probe failed to compile."); + +extern crate alloc; + +#[cfg(feature = "std")] +extern crate std; + +#[macro_use] +mod backtrace; +mod chain; +mod context; +mod ensure; +mod error; +mod fmt; +mod kind; +mod macros; +#[cfg(error_generic_member_access)] +mod nightly; +mod ptr; +mod wrapper; + +use crate::error::ErrorImpl; +use crate::ptr::Own; +use core::fmt::Display; + +#[cfg(all(not(feature = "std"), anyhow_no_core_error))] +use core::fmt::Debug; + +#[cfg(feature = "std")] +use std::error::Error as StdError; + +#[cfg(not(any(feature = "std", anyhow_no_core_error)))] +use core::error::Error as StdError; + +#[cfg(all(not(feature = "std"), anyhow_no_core_error))] +trait StdError: Debug + Display { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + None + } +} + +#[doc(no_inline)] +pub use anyhow as format_err; + +/// The `Error` type, a wrapper around a dynamic error type. +/// +/// `Error` works a lot like `Box`, but with these +/// differences: +/// +/// - `Error` requires that the error is `Send`, `Sync`, and `'static`. +/// - `Error` guarantees that a backtrace is available, even if the underlying +/// error type does not provide one. +/// - `Error` is represented as a narrow pointer — exactly one word in +/// size instead of two. +/// +///
+/// +/// # Display representations +/// +/// When you print an error object using "{}" or to_string(), only the outermost +/// underlying error or context is printed, not any of the lower level causes. +/// This is exactly as if you had called the Display impl of the error from +/// which you constructed your anyhow::Error. +/// +/// ```console +/// Failed to read instrs from ./path/to/instrs.json +/// ``` +/// +/// To print causes as well using anyhow's default formatting of causes, use the +/// alternate selector "{:#}". +/// +/// ```console +/// Failed to read instrs from ./path/to/instrs.json: No such file or directory (os error 2) +/// ``` +/// +/// The Debug format "{:?}" includes your backtrace if one was captured. Note +/// that this is the representation you get by default if you return an error +/// from `fn main` instead of printing it explicitly yourself. +/// +/// ```console +/// Error: Failed to read instrs from ./path/to/instrs.json +/// +/// Caused by: +/// No such file or directory (os error 2) +/// ``` +/// +/// and if there is a backtrace available: +/// +/// ```console +/// Error: Failed to read instrs from ./path/to/instrs.json +/// +/// Caused by: +/// No such file or directory (os error 2) +/// +/// Stack backtrace: +/// 0: ::ext_context +/// at /git/anyhow/src/backtrace.rs:26 +/// 1: core::result::Result::map_err +/// at /git/rustc/src/libcore/result.rs:596 +/// 2: anyhow::context:: for core::result::Result>::with_context +/// at /git/anyhow/src/context.rs:58 +/// 3: testing::main +/// at src/main.rs:5 +/// 4: std::rt::lang_start +/// at /git/rustc/src/libstd/rt.rs:61 +/// 5: main +/// 6: __libc_start_main +/// 7: _start +/// ``` +/// +/// To see a conventional struct-style Debug representation, use "{:#?}". +/// +/// ```console +/// Error { +/// context: "Failed to read instrs from ./path/to/instrs.json", +/// source: Os { +/// code: 2, +/// kind: NotFound, +/// message: "No such file or directory", +/// }, +/// } +/// ``` +/// +/// If none of the built-in representations are appropriate and you would prefer +/// to render the error and its cause chain yourself, it can be done something +/// like this: +/// +/// ``` +/// use anyhow::{Context, Result}; +/// +/// fn main() { +/// if let Err(err) = try_main() { +/// eprintln!("ERROR: {}", err); +/// err.chain().skip(1).for_each(|cause| eprintln!("because: {}", cause)); +/// std::process::exit(1); +/// } +/// } +/// +/// fn try_main() -> Result<()> { +/// # const IGNORE: &str = stringify! { +/// ... +/// # }; +/// # Ok(()) +/// } +/// ``` +#[repr(transparent)] +pub struct Error { + inner: Own, +} + +/// Iterator of a chain of source errors. +/// +/// This type is the iterator returned by [`Error::chain`]. +/// +/// # Example +/// +/// ``` +/// use anyhow::Error; +/// use std::io; +/// +/// pub fn underlying_io_error_kind(error: &Error) -> Option { +/// for cause in error.chain() { +/// if let Some(io_error) = cause.downcast_ref::() { +/// return Some(io_error.kind()); +/// } +/// } +/// None +/// } +/// ``` +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +#[derive(Clone)] +pub struct Chain<'a> { + state: crate::chain::ChainState<'a>, +} + +/// `Result` +/// +/// This is a reasonable return type to use throughout your application but also +/// for `fn main`; if you do, failures will be printed along with any +/// [context][Context] and a backtrace if one was captured. +/// +/// `anyhow::Result` may be used with one *or* two type parameters. +/// +/// ```rust +/// use anyhow::Result; +/// +/// # const IGNORE: &str = stringify! { +/// fn demo1() -> Result {...} +/// // ^ equivalent to std::result::Result +/// +/// fn demo2() -> Result {...} +/// // ^ equivalent to std::result::Result +/// # }; +/// ``` +/// +/// # Example +/// +/// ``` +/// # pub trait Deserialize {} +/// # +/// # mod serde_json { +/// # use super::Deserialize; +/// # use std::io; +/// # +/// # pub fn from_str(json: &str) -> io::Result { +/// # unimplemented!() +/// # } +/// # } +/// # +/// # #[derive(Debug)] +/// # struct ClusterMap; +/// # +/// # impl Deserialize for ClusterMap {} +/// # +/// use anyhow::Result; +/// +/// fn main() -> Result<()> { +/// # return Ok(()); +/// let config = std::fs::read_to_string("cluster.json")?; +/// let map: ClusterMap = serde_json::from_str(&config)?; +/// println!("cluster info: {:#?}", map); +/// Ok(()) +/// } +/// ``` +pub type Result = core::result::Result; + +/// Provides the `context` method for `Result`. +/// +/// This trait is sealed and cannot be implemented for types outside of +/// `anyhow`. +/// +///
+/// +/// # Example +/// +/// ``` +/// use anyhow::{Context, Result}; +/// use std::fs; +/// use std::path::PathBuf; +/// +/// pub struct ImportantThing { +/// path: PathBuf, +/// } +/// +/// impl ImportantThing { +/// # const IGNORE: &'static str = stringify! { +/// pub fn detach(&mut self) -> Result<()> {...} +/// # }; +/// # fn detach(&mut self) -> Result<()> { +/// # unimplemented!() +/// # } +/// } +/// +/// pub fn do_it(mut it: ImportantThing) -> Result> { +/// it.detach().context("Failed to detach the important thing")?; +/// +/// let path = &it.path; +/// let content = fs::read(path) +/// .with_context(|| format!("Failed to read instrs from {}", path.display()))?; +/// +/// Ok(content) +/// } +/// ``` +/// +/// When printed, the outermost context would be printed first and the lower +/// level underlying causes would be enumerated below. +/// +/// ```console +/// Error: Failed to read instrs from ./path/to/instrs.json +/// +/// Caused by: +/// No such file or directory (os error 2) +/// ``` +/// +/// Refer to the [Display representations] documentation for other forms in +/// which this context chain can be rendered. +/// +/// [Display representations]: Error#display-representations +/// +///
+/// +/// # Effect on downcasting +/// +/// After attaching context of type `C` onto an error of type `E`, the resulting +/// `anyhow::Error` may be downcast to `C` **or** to `E`. +/// +/// That is, in codebases that rely on downcasting, Anyhow's context supports +/// both of the following use cases: +/// +/// - **Attaching context whose type is insignificant onto errors whose type +/// is used in downcasts.** +/// +/// In other error libraries whose context is not designed this way, it can +/// be risky to introduce context to existing code because new context might +/// break existing working downcasts. In Anyhow, any downcast that worked +/// before adding context will continue to work after you add a context, so +/// you should freely add human-readable context to errors wherever it would +/// be helpful. +/// +/// ``` +/// # use anyhow::bail; +/// # use thiserror::Error; +/// # +/// # #[derive(Error, Debug)] +/// # #[error("???")] +/// # struct SuspiciousError; +/// # +/// # fn helper() -> Result<()> { +/// # bail!(SuspiciousError); +/// # } +/// # +/// use anyhow::{Context, Result}; +/// +/// fn do_it() -> Result<()> { +/// helper().context("Failed to complete the work")?; +/// # const IGNORE: &str = stringify! { +/// ... +/// # }; +/// # unreachable!() +/// } +/// +/// fn main() { +/// let err = do_it().unwrap_err(); +/// if let Some(e) = err.downcast_ref::() { +/// // If helper() returned SuspiciousError, this downcast will +/// // correctly succeed even with the context in between. +/// # return; +/// } +/// # panic!("expected downcast to succeed"); +/// } +/// ``` +/// +/// - **Attaching context whose type is used in downcasts onto errors whose +/// type is insignificant.** +/// +/// Some codebases prefer to use machine-readable context to categorize +/// lower level errors in a way that will be actionable to higher levels of +/// the application. +/// +/// ``` +/// # use anyhow::bail; +/// # use thiserror::Error; +/// # +/// # #[derive(Error, Debug)] +/// # #[error("???")] +/// # struct HelperFailed; +/// # +/// # fn helper() -> Result<()> { +/// # bail!("no such file or directory"); +/// # } +/// # +/// use anyhow::{Context, Result}; +/// +/// fn do_it() -> Result<()> { +/// helper().context(HelperFailed)?; +/// # const IGNORE: &str = stringify! { +/// ... +/// # }; +/// # unreachable!() +/// } +/// +/// fn main() { +/// let err = do_it().unwrap_err(); +/// if let Some(e) = err.downcast_ref::() { +/// // If helper failed, this downcast will succeed because +/// // HelperFailed is the context that has been attached to +/// // that error. +/// # return; +/// } +/// # panic!("expected downcast to succeed"); +/// } +/// ``` +pub trait Context: context::private::Sealed { + /// Wrap the error value with additional context. + fn context(self, context: C) -> Result + where + C: Display + Send + Sync + 'static; + + /// Wrap the error value with additional context that is evaluated lazily + /// only once an error does occur. + fn with_context(self, f: F) -> Result + where + C: Display + Send + Sync + 'static, + F: FnOnce() -> C; +} + +/// Equivalent to `Ok::<_, anyhow::Error>(value)`. +/// +/// This simplifies creation of an `anyhow::Result` in places where type +/// inference cannot deduce the `E` type of the result — without needing +/// to write `Ok::<_, anyhow::Error>(value)`. +/// +/// One might think that `anyhow::Result::Ok(value)` would work in such cases +/// but it does not. +/// +/// ```console +/// error[E0282]: type annotations needed for `std::result::Result` +/// --> src/main.rs:11:13 +/// | +/// 11 | let _ = anyhow::Result::Ok(1); +/// | - ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result` +/// | | +/// | consider giving this pattern the explicit type `std::result::Result`, where the type parameter `E` is specified +/// ``` +#[allow(non_snake_case)] +#[inline] +pub fn Ok(value: T) -> Result { + Result::Ok(value) +} + +// Not public API. Referenced by macro-generated code. +#[doc(hidden)] +pub mod __private { + use self::not::Bool; + use crate::Error; + use alloc::fmt; + use core::fmt::Arguments; + + #[doc(hidden)] + pub use crate::ensure::{BothDebug, NotBothDebug}; + #[doc(hidden)] + pub use alloc::format; + #[doc(hidden)] + pub use core::result::Result::Err; + #[doc(hidden)] + pub use core::{concat, format_args, stringify}; + + #[doc(hidden)] + pub mod kind { + #[doc(hidden)] + pub use crate::kind::{AdhocKind, TraitKind}; + + #[cfg(any(feature = "std", not(anyhow_no_core_error)))] + #[doc(hidden)] + pub use crate::kind::BoxedKind; + } + + #[doc(hidden)] + #[inline] + #[cold] + pub fn format_err(args: Arguments) -> Error { + if let Some(message) = args.as_str() { + // anyhow!("literal"), can downcast to &'static str + Error::msg(message) + } else { + // anyhow!("interpolate {var}"), can downcast to String + Error::msg(fmt::format(args)) + } + } + + #[doc(hidden)] + #[inline] + #[cold] + #[must_use] + pub fn must_use(error: Error) -> Error { + error + } + + #[doc(hidden)] + #[inline] + pub fn not(cond: impl Bool) -> bool { + cond.not() + } + + mod not { + #[doc(hidden)] + pub trait Bool { + fn not(self) -> bool; + } + + impl Bool for bool { + #[inline] + fn not(self) -> bool { + !self + } + } + + impl Bool for &bool { + #[inline] + fn not(self) -> bool { + !*self + } + } + } +} diff --git a/third_party/crates/anyhow-1.0.104/src/macros.rs b/third_party/crates/anyhow-1.0.104/src/macros.rs new file mode 100644 index 0000000..1558de5 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/macros.rs @@ -0,0 +1,245 @@ +/// Return early with an error. +/// +/// This macro is equivalent to +/// return Err([anyhow!($args\...)][anyhow!]). +/// +/// The surrounding function's or closure's return value is required to be +/// Result<_, [anyhow::Error][crate::Error]>. +/// +/// [anyhow!]: crate::anyhow +/// +/// # Example +/// +/// ``` +/// # use anyhow::{bail, Result}; +/// # +/// # fn has_permission(user: usize, resource: usize) -> bool { +/// # true +/// # } +/// # +/// # fn main() -> Result<()> { +/// # let user = 0; +/// # let resource = 0; +/// # +/// if !has_permission(user, resource) { +/// bail!("permission denied for accessing {}", resource); +/// } +/// # Ok(()) +/// # } +/// ``` +/// +/// ``` +/// # use anyhow::{bail, Result}; +/// # use thiserror::Error; +/// # +/// # const MAX_DEPTH: usize = 1; +/// # +/// #[derive(Error, Debug)] +/// enum ScienceError { +/// #[error("recursion limit exceeded")] +/// RecursionLimitExceeded, +/// # #[error("...")] +/// # More = (stringify! { +/// ... +/// # }, 1).1, +/// } +/// +/// # fn main() -> Result<()> { +/// # let depth = 0; +/// # +/// if depth > MAX_DEPTH { +/// bail!(ScienceError::RecursionLimitExceeded); +/// } +/// # Ok(()) +/// # } +/// ``` +#[macro_export] +#[cfg_attr(not(anyhow_no_clippy_format_args), clippy::format_args)] +macro_rules! bail { + ($msg:literal $(,)?) => { + return $crate::__private::Err($crate::__anyhow!($msg)) + }; + ($err:expr $(,)?) => { + return $crate::__private::Err($crate::__anyhow!($err)) + }; + ($fmt:expr, $($arg:tt)*) => { + return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)) + }; +} + +macro_rules! __ensure { + ($ensure:item) => { + /// Return early with an error if a condition is not satisfied. + /// + /// This macro is equivalent to + /// if !$cond { return Err([anyhow!($args\...)][anyhow!]); }. + /// + /// The surrounding function's or closure's return value is required to be + /// Result<_, [anyhow::Error][crate::Error]>. + /// + /// Analogously to `assert!`, `ensure!` takes a condition and exits the function + /// if the condition fails. Unlike `assert!`, `ensure!` returns an `Error` + /// rather than panicking. + /// + /// [anyhow!]: crate::anyhow + /// + /// # Example + /// + /// ``` + /// # use anyhow::{ensure, Result}; + /// # + /// # fn main() -> Result<()> { + /// # let user = 0; + /// # + /// ensure!(user == 0, "only user 0 is allowed"); + /// # Ok(()) + /// # } + /// ``` + /// + /// ``` + /// # use anyhow::{ensure, Result}; + /// # use thiserror::Error; + /// # + /// # const MAX_DEPTH: usize = 1; + /// # + /// #[derive(Error, Debug)] + /// enum ScienceError { + /// #[error("recursion limit exceeded")] + /// RecursionLimitExceeded, + /// # #[error("...")] + /// # More = (stringify! { + /// ... + /// # }, 1).1, + /// } + /// + /// # fn main() -> Result<()> { + /// # let depth = 0; + /// # + /// ensure!(depth <= MAX_DEPTH, ScienceError::RecursionLimitExceeded); + /// # Ok(()) + /// # } + /// ``` + $ensure + }; +} + +#[cfg(doc)] +__ensure![ + #[macro_export] + macro_rules! ensure { + ($cond:expr $(,)?) => { + if !$cond { + return $crate::__private::Err($crate::Error::msg( + $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`") + )); + } + }; + ($cond:expr, $msg:literal $(,)?) => { + if !$cond { + return $crate::__private::Err($crate::__anyhow!($msg)); + } + }; + ($cond:expr, $err:expr $(,)?) => { + if !$cond { + return $crate::__private::Err($crate::__anyhow!($err)); + } + }; + ($cond:expr, $fmt:expr, $($arg:tt)*) => { + if !$cond { + return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)); + } + }; + } +]; + +#[cfg(not(doc))] +__ensure![ + #[macro_export] + #[cfg_attr(not(anyhow_no_clippy_format_args), clippy::format_args)] + macro_rules! ensure { + ($($tt:tt)*) => { + $crate::__parse_ensure!( + /* state */ 0 + /* stack */ () + /* bail */ ($($tt)*) + /* fuel */ (~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~) + /* parse */ {()} + /* dup */ ($($tt)*) + /* rest */ $($tt)* + ) + }; + } +]; + +/// Construct an ad-hoc error from a string or existing non-`anyhow` error +/// value. +/// +/// This evaluates to an [`Error`][crate::Error]. It can take either just a +/// string, or a format string with arguments. It also can take any custom type +/// which implements `Debug` and `Display`. +/// +/// If called with a single argument whose type implements `std::error::Error` +/// (in addition to `Debug` and `Display`, which are always required), then that +/// Error impl's `source` is preserved as the `source` of the resulting +/// `anyhow::Error`. +/// +/// # Example +/// +/// ``` +/// # type V = (); +/// # +/// use anyhow::{anyhow, Result}; +/// +/// fn lookup(key: &str) -> Result { +/// if key.len() != 16 { +/// return Err(anyhow!("key length must be 16 characters, got {:?}", key)); +/// } +/// +/// // ... +/// # Ok(()) +/// } +/// ``` +#[macro_export] +#[cfg_attr(not(anyhow_no_clippy_format_args), clippy::format_args)] +macro_rules! anyhow { + ($msg:literal $(,)?) => { + $crate::__private::must_use({ + let error = $crate::__private::format_err($crate::__private::format_args!($msg)); + error + }) + }; + ($err:expr $(,)?) => { + $crate::__private::must_use({ + use $crate::__private::kind::*; + let error = match $err { + error => (&error).anyhow_kind().new(error), + }; + error + }) + }; + ($fmt:expr, $($arg:tt)*) => { + $crate::Error::msg($crate::__private::format!($fmt, $($arg)*)) + }; +} + +// Not public API. This is used in the implementation of some of the other +// macros, in which the must_use call is not needed because the value is known +// to be used. +#[doc(hidden)] +#[macro_export] +macro_rules! __anyhow { + ($msg:literal $(,)?) => ({ + let error = $crate::__private::format_err($crate::__private::format_args!($msg)); + error + }); + ($err:expr $(,)?) => ({ + use $crate::__private::kind::*; + let error = match $err { + error => (&error).anyhow_kind().new(error), + }; + error + }); + ($fmt:expr, $($arg:tt)*) => { + $crate::Error::msg($crate::__private::format!($fmt, $($arg)*)) + }; +} diff --git a/third_party/crates/anyhow-1.0.104/src/nightly.rs b/third_party/crates/anyhow-1.0.104/src/nightly.rs new file mode 100644 index 0000000..125fe36 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/nightly.rs @@ -0,0 +1,58 @@ +// This code exercises the surface area that we expect of the Error generic +// member access API. If the current toolchain is able to compile it, then +// anyhow is able to provide backtrace support. + +#![cfg_attr(anyhow_build_probe, feature(error_generic_member_access))] + +use core::error::{self, Error}; +use std::backtrace::Backtrace; + +pub use core::error::Request; + +#[cfg(anyhow_build_probe)] +const _: () = { + use core::fmt::{self, Debug, Display}; + + struct MyError(Backtrace); + + impl Debug for MyError { + fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { + unimplemented!() + } + } + + impl Display for MyError { + fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { + unimplemented!() + } + } + + impl Error for MyError { + fn provide<'a>(&'a self, request: &mut Request<'a>) { + provide_ref_backtrace(request, &self.0); + } + } +}; + +// Include in sccache cache key. +#[cfg(anyhow_build_probe)] +const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP"); + +pub fn request_ref_backtrace(err: &dyn Error) -> Option<&Backtrace> { + request_ref::(err) +} + +fn request_ref<'a, T>(err: &'a (impl Error + ?Sized)) -> Option<&'a T> +where + T: 'static + ?Sized, +{ + error::request_ref::(err) +} + +pub fn provide_ref_backtrace<'a>(request: &mut Request<'a>, backtrace: &'a Backtrace) { + Request::provide_ref(request, backtrace); +} + +pub fn provide<'a>(err: &'a (impl Error + ?Sized), request: &mut Request<'a>) { + Error::provide(err, request); +} diff --git a/third_party/crates/anyhow-1.0.104/src/ptr.rs b/third_party/crates/anyhow-1.0.104/src/ptr.rs new file mode 100644 index 0000000..4d6b3ab --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/ptr.rs @@ -0,0 +1,187 @@ +use alloc::boxed::Box; +use core::marker::PhantomData; +use core::ptr::NonNull; + +#[repr(transparent)] +pub struct Own +where + T: ?Sized, +{ + pub ptr: NonNull, +} + +unsafe impl Send for Own where T: ?Sized {} + +unsafe impl Sync for Own where T: ?Sized {} + +impl Copy for Own where T: ?Sized {} + +impl Clone for Own +where + T: ?Sized, +{ + fn clone(&self) -> Self { + *self + } +} + +impl Own +where + T: ?Sized, +{ + pub fn new(ptr: Box) -> Self { + Own { + ptr: unsafe { NonNull::new_unchecked(Box::into_raw(ptr)) }, + } + } + + pub fn cast(self) -> Own { + Own { + ptr: self.ptr.cast(), + } + } + + pub unsafe fn boxed(self) -> Box { + unsafe { Box::from_raw(self.ptr.as_ptr()) } + } + + pub fn by_ref(&self) -> Ref { + Ref { + ptr: self.ptr, + lifetime: PhantomData, + } + } + + pub fn by_mut(&mut self) -> Mut { + Mut { + ptr: self.ptr, + lifetime: PhantomData, + } + } +} + +#[repr(transparent)] +pub struct Ref<'a, T> +where + T: ?Sized, +{ + pub ptr: NonNull, + lifetime: PhantomData<&'a T>, +} + +impl<'a, T> Copy for Ref<'a, T> where T: ?Sized {} + +impl<'a, T> Clone for Ref<'a, T> +where + T: ?Sized, +{ + fn clone(&self) -> Self { + *self + } +} + +impl<'a, T> Ref<'a, T> +where + T: ?Sized, +{ + pub fn new(ptr: &'a T) -> Self { + Ref { + ptr: NonNull::from(ptr), + lifetime: PhantomData, + } + } + + pub fn from_raw(ptr: NonNull) -> Self { + Ref { + ptr, + lifetime: PhantomData, + } + } + + pub fn cast(self) -> Ref<'a, U::Target> { + Ref { + ptr: self.ptr.cast(), + lifetime: PhantomData, + } + } + + pub fn by_mut(self) -> Mut<'a, T> { + Mut { + ptr: self.ptr, + lifetime: PhantomData, + } + } + + pub fn as_ptr(self) -> *const T { + self.ptr.as_ptr().cast_const() + } + + pub unsafe fn deref(self) -> &'a T { + unsafe { &*self.ptr.as_ptr() } + } +} + +#[repr(transparent)] +pub struct Mut<'a, T> +where + T: ?Sized, +{ + pub ptr: NonNull, + lifetime: PhantomData<&'a mut T>, +} + +impl<'a, T> Copy for Mut<'a, T> where T: ?Sized {} + +impl<'a, T> Clone for Mut<'a, T> +where + T: ?Sized, +{ + fn clone(&self) -> Self { + *self + } +} + +impl<'a, T> Mut<'a, T> +where + T: ?Sized, +{ + pub fn cast(self) -> Mut<'a, U::Target> { + Mut { + ptr: self.ptr.cast(), + lifetime: PhantomData, + } + } + + pub fn by_ref(self) -> Ref<'a, T> { + Ref { + ptr: self.ptr, + lifetime: PhantomData, + } + } + + pub fn extend<'b>(self) -> Mut<'b, T> { + Mut { + ptr: self.ptr, + lifetime: PhantomData, + } + } + + pub unsafe fn deref_mut(self) -> &'a mut T { + unsafe { &mut *self.ptr.as_ptr() } + } +} + +impl<'a, T> Mut<'a, T> { + pub unsafe fn read(self) -> T { + unsafe { self.ptr.as_ptr().read() } + } +} + +// Force turbofish on all calls of `.cast::()`. +pub trait CastTo { + type Target; +} + +impl CastTo for T { + type Target = T; +} diff --git a/third_party/crates/anyhow-1.0.104/src/wrapper.rs b/third_party/crates/anyhow-1.0.104/src/wrapper.rs new file mode 100644 index 0000000..bad3ddd --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/src/wrapper.rs @@ -0,0 +1,84 @@ +use crate::StdError; +use core::fmt::{self, Debug, Display}; + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +use alloc::boxed::Box; + +#[cfg(error_generic_member_access)] +use crate::nightly::{self, Request}; + +#[repr(transparent)] +pub struct MessageError(pub M); + +impl Debug for MessageError +where + M: Display + Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(&self.0, f) + } +} + +impl Display for MessageError +where + M: Display + Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&self.0, f) + } +} + +impl StdError for MessageError where M: Display + Debug + 'static {} + +#[repr(transparent)] +pub struct DisplayError(pub M); + +impl Debug for DisplayError +where + M: Display, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&self.0, f) + } +} + +impl Display for DisplayError +where + M: Display, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&self.0, f) + } +} + +impl StdError for DisplayError where M: Display + 'static {} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +#[repr(transparent)] +pub struct BoxedError(pub Box); + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl Debug for BoxedError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(&self.0, f) + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl Display for BoxedError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&self.0, f) + } +} + +#[cfg(any(feature = "std", not(anyhow_no_core_error)))] +impl StdError for BoxedError { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + self.0.source() + } + + #[cfg(error_generic_member_access)] + fn provide<'a>(&'a self, request: &mut Request<'a>) { + nightly::provide(&*self.0, request); + } +} diff --git a/third_party/crates/anyhow-1.0.104/tests/common/mod.rs b/third_party/crates/anyhow-1.0.104/tests/common/mod.rs new file mode 100644 index 0000000..fc165a5 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/common/mod.rs @@ -0,0 +1,14 @@ +use anyhow::{bail, Result}; +use std::io; + +pub fn bail_literal() -> Result<()> { + bail!("oh no!"); +} + +pub fn bail_fmt() -> Result<()> { + bail!("{} {}!", "oh", "no"); +} + +pub fn bail_error() -> Result<()> { + bail!(io::Error::new(io::ErrorKind::Other, "oh no!")); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/compiletest.rs b/third_party/crates/anyhow-1.0.104/tests/compiletest.rs new file mode 100644 index 0000000..23a6a06 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/compiletest.rs @@ -0,0 +1,7 @@ +#[rustversion::attr(not(nightly), ignore = "requires nightly")] +#[cfg_attr(miri, ignore = "incompatible with miri")] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/drop/mod.rs b/third_party/crates/anyhow-1.0.104/tests/drop/mod.rs new file mode 100644 index 0000000..7da4bf5 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/drop/mod.rs @@ -0,0 +1,53 @@ +#![allow(clippy::module_name_repetitions)] + +use std::error::Error as StdError; +use std::fmt::{self, Display}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; + +#[derive(Debug)] +pub struct Flag { + atomic: Arc, +} + +impl Flag { + pub fn new() -> Self { + Flag { + atomic: Arc::new(AtomicBool::new(false)), + } + } + + pub fn get(&self) -> bool { + self.atomic.load(Ordering::Relaxed) + } +} + +#[derive(Debug)] +pub struct DetectDrop { + has_dropped: Flag, +} + +impl DetectDrop { + pub fn new(has_dropped: &Flag) -> Self { + DetectDrop { + has_dropped: Flag { + atomic: Arc::clone(&has_dropped.atomic), + }, + } + } +} + +impl StdError for DetectDrop {} + +impl Display for DetectDrop { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "oh no!") + } +} + +impl Drop for DetectDrop { + fn drop(&mut self) { + let already_dropped = self.has_dropped.atomic.swap(true, Ordering::Relaxed); + assert!(!already_dropped); + } +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs b/third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs new file mode 100644 index 0000000..080b3b9 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs @@ -0,0 +1,34 @@ +#![allow(clippy::extra_unused_type_parameters)] + +use anyhow::Error; +use std::panic::{RefUnwindSafe, UnwindSafe}; + +#[test] +fn test_send() { + fn assert_send() {} + assert_send::(); +} + +#[test] +fn test_sync() { + fn assert_sync() {} + assert_sync::(); +} + +#[test] +fn test_unwind_safe() { + fn assert_unwind_safe() {} + assert_unwind_safe::(); +} + +#[test] +fn test_ref_unwind_safe() { + fn assert_ref_unwind_safe() {} + assert_ref_unwind_safe::(); +} + +#[test] +fn test_unpin() { + fn assert_unpin() {} + assert_unpin::(); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs b/third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs new file mode 100644 index 0000000..938c1c2 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs @@ -0,0 +1,15 @@ +#![allow(clippy::let_underscore_untyped)] + +#[rustversion::not(nightly)] +#[ignore = "requires nightly"] +#[test] +fn test_backtrace() {} + +#[rustversion::nightly] +#[test] +fn test_backtrace() { + use anyhow::anyhow; + + let error = anyhow!("oh no!"); + let _ = error.backtrace(); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_boxed.rs b/third_party/crates/anyhow-1.0.104/tests/test_boxed.rs new file mode 100644 index 0000000..fb1fb13 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_boxed.rs @@ -0,0 +1,45 @@ +#![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; +use thiserror::Error; + +#[derive(Error, Debug)] +#[error("outer")] +struct MyError { + source: io::Error, +} + +#[test] +fn test_boxed_str() { + let error = Box::::from("oh no!"); + let error = anyhow!(error); + assert_eq!("oh no!", error.to_string()); + assert_eq!( + "oh no!", + error + .downcast_ref::>() + .unwrap() + .to_string() + ); +} + +#[test] +fn test_boxed_thiserror() { + let error = MyError { + source: io::Error::new(io::ErrorKind::Other, "oh no!"), + }; + let error = anyhow!(error); + assert_eq!("oh no!", error.source().unwrap().to_string()); +} + +#[test] +fn test_boxed_anyhow() { + let error = anyhow!("oh no!").context("it failed"); + let error = anyhow!(error); + assert_eq!("oh no!", error.source().unwrap().to_string()); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_chain.rs b/third_party/crates/anyhow-1.0.104/tests/test_chain.rs new file mode 100644 index 0000000..c8b901a --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_chain.rs @@ -0,0 +1,69 @@ +use anyhow::{anyhow, Chain, Error}; + +fn error() -> Error { + anyhow!({ 0 }).context(1).context(2).context(3) +} + +#[test] +fn test_iter() { + let e = error(); + let mut chain = e.chain(); + 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()); +} + +#[test] +fn test_rev() { + let e = error(); + let mut chain = e.chain().rev(); + assert_eq!("0", chain.next().unwrap().to_string()); + assert_eq!("1", chain.next().unwrap().to_string()); + assert_eq!("2", chain.next().unwrap().to_string()); + assert_eq!("3", chain.next().unwrap().to_string()); + assert!(chain.next().is_none()); + assert!(chain.next_back().is_none()); +} + +#[test] +fn test_len() { + 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] +#[allow(clippy::redundant_clone)] +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/third_party/crates/anyhow-1.0.104/tests/test_context.rs b/third_party/crates/anyhow-1.0.104/tests/test_context.rs new file mode 100644 index 0000000..3496a07 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_context.rs @@ -0,0 +1,195 @@ +#![allow( + // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 + clippy::nonstandard_macro_braces, +)] + +mod drop; + +use crate::drop::{DetectDrop, Flag}; +use anyhow::{Context, Error, Result}; +use std::fmt::{self, Display}; +use thiserror::Error; + +// https://github.com/dtolnay/anyhow/issues/18 +#[test] +fn test_inference() -> Result<()> { + let x = "1"; + let y: u32 = x.parse().context("...")?; + assert_eq!(y, 1); + Ok(()) +} + +macro_rules! context_type { + ($name:ident) => { + #[derive(Debug)] + struct $name { + message: &'static str, + #[allow(dead_code)] + drop: DetectDrop, + } + + impl Display for $name { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(self.message) + } + } + }; +} + +context_type!(HighLevel); +context_type!(MidLevel); + +#[derive(Error, Debug)] +#[error("{message}")] +struct LowLevel { + message: &'static str, + drop: DetectDrop, +} + +struct Dropped { + low: Flag, + mid: Flag, + high: Flag, +} + +impl Dropped { + fn none(&self) -> bool { + !self.low.get() && !self.mid.get() && !self.high.get() + } + + fn all(&self) -> bool { + self.low.get() && self.mid.get() && self.high.get() + } +} + +fn make_chain() -> (Error, Dropped) { + let dropped = Dropped { + low: Flag::new(), + mid: Flag::new(), + high: Flag::new(), + }; + + let low = LowLevel { + message: "no such file or directory", + drop: DetectDrop::new(&dropped.low), + }; + + // impl Context for Result + let mid = Err::<(), LowLevel>(low) + .context(MidLevel { + message: "failed to load config", + drop: DetectDrop::new(&dropped.mid), + }) + .unwrap_err(); + + // impl Context for Result + let high = Err::<(), Error>(mid) + .context(HighLevel { + message: "failed to start server", + drop: DetectDrop::new(&dropped.high), + }) + .unwrap_err(); + + (high, dropped) +} + +#[test] +fn test_downcast_ref() { + let (err, dropped) = make_chain(); + + assert!(!err.is::()); + assert!(err.downcast_ref::().is_none()); + + assert!(err.is::()); + let high = err.downcast_ref::().unwrap(); + assert_eq!(high.to_string(), "failed to start server"); + + assert!(err.is::()); + let mid = err.downcast_ref::().unwrap(); + assert_eq!(mid.to_string(), "failed to load config"); + + assert!(err.is::()); + let low = err.downcast_ref::().unwrap(); + assert_eq!(low.to_string(), "no such file or directory"); + + assert!(dropped.none()); + drop(err); + assert!(dropped.all()); +} + +#[test] +fn test_downcast_high() { + let (err, dropped) = make_chain(); + + let err = err.downcast::().unwrap(); + assert!(!dropped.high.get()); + assert!(dropped.low.get() && dropped.mid.get()); + + drop(err); + assert!(dropped.all()); +} + +#[test] +fn test_downcast_mid() { + let (err, dropped) = make_chain(); + + let err = err.downcast::().unwrap(); + assert!(!dropped.mid.get()); + assert!(dropped.low.get() && dropped.high.get()); + + drop(err); + assert!(dropped.all()); +} + +#[test] +fn test_downcast_low() { + let (err, dropped) = make_chain(); + + let err = err.downcast::().unwrap(); + assert!(!dropped.low.get()); + assert!(dropped.mid.get() && dropped.high.get()); + + drop(err); + assert!(dropped.all()); +} + +#[test] +fn test_unsuccessful_downcast() { + let (err, dropped) = make_chain(); + + let err = err.downcast::().unwrap_err(); + assert!(dropped.none()); + + drop(err); + assert!(dropped.all()); +} + +#[test] +fn test_downcast_mut() { + let (mut err, dropped) = make_chain(); + + err.downcast_mut::().unwrap().message = "high context"; + err.downcast_mut::().unwrap().message = "mid context"; + err.downcast_mut::().unwrap().message = "low error"; + + assert_eq!( + err.downcast_ref::().unwrap().message, + "high context", + ); + assert_eq!( + err.downcast_ref::().unwrap().message, + "mid context", + ); + assert_eq!(err.downcast_ref::().unwrap().message, "low error"); + + assert!(dropped.none()); + 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/third_party/crates/anyhow-1.0.104/tests/test_convert.rs b/third_party/crates/anyhow-1.0.104/tests/test_convert.rs new file mode 100644 index 0000000..6da171d --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_convert.rs @@ -0,0 +1,46 @@ +#![allow(clippy::unnecessary_wraps)] + +mod drop; + +use self::drop::{DetectDrop, Flag}; +use anyhow::{Error, Result}; +use std::error::Error as StdError; + +#[test] +fn test_convert() { + let has_dropped = Flag::new(); + let error = Error::new(DetectDrop::new(&has_dropped)); + let box_dyn = Box::::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::::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::::from(error); + assert_eq!("oh no!", box_dyn.to_string()); + drop(box_dyn); + assert!(has_dropped.get()); +} + +#[test] +fn test_question_mark() -> Result<(), Box> { + fn f() -> Result<()> { + Ok(()) + } + f()?; + Ok(()) +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_downcast.rs b/third_party/crates/anyhow-1.0.104/tests/test_downcast.rs new file mode 100644 index 0000000..b4470d5 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_downcast.rs @@ -0,0 +1,123 @@ +#![allow(clippy::assertions_on_result_states, clippy::wildcard_imports)] + +mod common; +mod drop; + +use self::common::*; +use self::drop::{DetectDrop, Flag}; +use anyhow::Error; +use std::error::Error as StdError; +use std::fmt::{self, Display}; +use std::io; + +#[test] +fn test_downcast() { + assert_eq!( + "oh no!", + bail_literal().unwrap_err().downcast::<&str>().unwrap(), + ); + assert_eq!( + "oh no!", + bail_fmt().unwrap_err().downcast::().unwrap(), + ); + assert_eq!( + "oh no!", + bail_error() + .unwrap_err() + .downcast::() + .unwrap() + .to_string(), + ); +} + +#[test] +fn test_downcast_ref() { + assert_eq!( + "oh no!", + *bail_literal().unwrap_err().downcast_ref::<&str>().unwrap(), + ); + assert_eq!( + "oh no!", + bail_fmt().unwrap_err().downcast_ref::().unwrap(), + ); + assert_eq!( + "oh no!", + bail_error() + .unwrap_err() + .downcast_ref::() + .unwrap() + .to_string(), + ); +} + +#[test] +fn test_downcast_mut() { + assert_eq!( + "oh no!", + *bail_literal().unwrap_err().downcast_mut::<&str>().unwrap(), + ); + assert_eq!( + "oh no!", + bail_fmt().unwrap_err().downcast_mut::().unwrap(), + ); + assert_eq!( + "oh no!", + bail_error() + .unwrap_err() + .downcast_mut::() + .unwrap() + .to_string(), + ); + + let mut bailed = bail_fmt().unwrap_err(); + *bailed.downcast_mut::().unwrap() = "clobber".to_string(); + assert_eq!(bailed.downcast_ref::().unwrap(), "clobber"); + assert_eq!(bailed.downcast_mut::().unwrap(), "clobber"); + assert_eq!(bailed.downcast::().unwrap(), "clobber"); +} + +#[test] +fn test_drop() { + let has_dropped = Flag::new(); + let error = Error::new(DetectDrop::new(&has_dropped)); + drop(error.downcast::().unwrap()); + assert!(has_dropped.get()); +} + +#[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)] + struct LargeAlignedError(&'static str); + + impl Display for LargeAlignedError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(self.0) + } + } + + impl StdError for LargeAlignedError {} + + let error = Error::new(LargeAlignedError("oh no!")); + assert_eq!( + "oh no!", + error.downcast_ref::().unwrap().0 + ); +} + +#[test] +fn test_unsuccessful_downcast() { + let mut error = bail_error().unwrap_err(); + assert!(error.downcast_ref::<&str>().is_none()); + assert!(error.downcast_mut::<&str>().is_none()); + assert!(error.downcast::<&str>().is_err()); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_ensure.rs b/third_party/crates/anyhow-1.0.104/tests/test_ensure.rs new file mode 100644 index 0000000..dc95160 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_ensure.rs @@ -0,0 +1,756 @@ +#![allow( + clippy::bool_to_int_with_if, + clippy::char_lit_as_u8, + clippy::deref_addrof, + clippy::diverging_sub_expression, + clippy::erasing_op, + clippy::extra_unused_type_parameters, + clippy::if_same_then_else, + clippy::ifs_same_cond, + clippy::ignored_unit_patterns, + clippy::items_after_statements, + clippy::let_and_return, + clippy::let_underscore_untyped, + clippy::literal_string_with_formatting_args, + clippy::match_bool, + clippy::needless_else, + clippy::never_loop, + clippy::overly_complex_bool_expr, + clippy::ptr_cast_constness, + clippy::redundant_closure_call, + clippy::redundant_pattern_matching, + clippy::too_many_lines, + clippy::uninlined_format_args, + clippy::unit_arg, + clippy::unnecessary_cast, + clippy::while_immutable_condition, + clippy::zero_ptr, + irrefutable_let_patterns +)] + +use self::Enum::Generic; +use anyhow::{anyhow, ensure, Chain, Error, Result}; +use std::fmt::{self, Debug}; +use std::iter; +use std::marker::{PhantomData, PhantomData as P}; +use std::mem; +use std::ops::Add; +use std::ptr; + +struct S; + +impl Add for S { + type Output = bool; + fn add(self, rhs: T) -> Self::Output { + let _ = rhs; + false + } +} + +trait Trait: Sized { + const V: usize = 0; + fn t(self, i: i32) -> i32 { + i + } +} + +impl Trait for T {} + +enum Enum { + #[allow(dead_code)] + Thing(PhantomData), + Generic, +} + +impl PartialEq for Enum { + fn eq(&self, rhs: &Self) -> bool { + mem::discriminant(self) == mem::discriminant(rhs) + } +} + +impl Debug for Enum { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("Generic") + } +} + +#[track_caller] +fn assert_err(result: impl FnOnce() -> Result, expected: &'static str) { + let actual = result().unwrap_err().to_string(); + + // In general different rustc versions will format the interpolated lhs and + // rhs $:expr fragment with insignificant differences in whitespace or + // punctuation, so we check the message in full against nightly and do just + // a cursory test on older toolchains. + if rustversion::cfg!(nightly) && !cfg!(miri) { + assert_eq!(actual, expected); + } else { + assert_eq!(actual.contains(" vs "), expected.contains(" vs ")); + } +} + +#[test] +fn test_recursion() { + // Must not blow the default #[recursion_limit], which is 128. + #[rustfmt::skip] + let test = || Ok(ensure!( + false | false | false | false | false | false | false | false | false | + false | false | false | false | false | false | false | false | false | + false | false | false | false | false | false | false | false | false | + false | false | false | false | false | false | false | false | false | + false | false | false | false | false | false | false | false | false | + false | false | false | false | false | false | false | false | false | + false | false | false | false | false | false | false | false | false + )); + + test().unwrap_err(); +} + +#[test] +fn test_low_precedence_control_flow() { + #[allow(unreachable_code)] + let test = || { + let val = loop { + // Break has lower precedence than the comparison operators so the + // expression here is `S + (break (1 == 1))`. It would be bad if the + // ensure macro partitioned this input into `(S + break 1) == (1)` + // because that means a different thing than what was written. + ensure!(S + break 1 == 1); + }; + Ok(val) + }; + + assert!(test().unwrap()); +} + +#[test] +fn test_low_precedence_binary_operator() { + // Must not partition as `false == (true && false)`. + let test = || Ok(ensure!(false == true && false)); + assert_err(test, "Condition failed: `false == true && false`"); + + // But outside the root level, it is fine. + let test = || Ok(ensure!(while false == true && false {} < ())); + assert_err( + test, + "Condition failed: `while false == true && false {} < ()` (() vs ())", + ); + + let a = 15; + let b = 3; + let test = || Ok(ensure!(a <= b || a - b <= 10)); + assert_err(test, "Condition failed: `a <= b || a - b <= 10`"); +} + +#[test] +fn test_high_precedence_binary_operator() { + let a = 15; + let b = 3; + let test = || Ok(ensure!(a - b <= 10)); + assert_err(test, "Condition failed: `a - b <= 10` (12 vs 10)"); +} + +#[test] +fn test_closure() { + // Must not partition as `(S + move) || (1 == 1)` by treating move as an + // identifier, nor as `(S + move || 1) == (1)` by misinterpreting the + // closure precedence. + let test = || Ok(ensure!(S + move || 1 == 1)); + assert_err(test, "Condition failed: `S + move || 1 == 1`"); + + let test = || Ok(ensure!(S + || 1 == 1)); + assert_err(test, "Condition failed: `S + || 1 == 1`"); + + // Must not partition as `S + ((move | ()) | 1) == 1` by treating those + // pipes as bitwise-or. + let test = || Ok(ensure!(S + move |()| 1 == 1)); + assert_err(test, "Condition failed: `S + move |()| 1 == 1`"); + + let test = || Ok(ensure!(S + |()| 1 == 1)); + assert_err(test, "Condition failed: `S + |()| 1 == 1`"); +} + +#[test] +fn test_unary() { + let mut x = &1; + let test = || Ok(ensure!(*x == 2)); + assert_err(test, "Condition failed: `*x == 2` (1 vs 2)"); + + let test = || Ok(ensure!(!x == 1)); + assert_err(test, "Condition failed: `!x == 1` (-2 vs 1)"); + + let test = || Ok(ensure!(-x == 1)); + assert_err(test, "Condition failed: `-x == 1` (-1 vs 1)"); + + let test = || Ok(ensure!(&x == &&2)); + assert_err(test, "Condition failed: `&x == &&2` (1 vs 2)"); + + let test = || Ok(ensure!(&mut x == *&&mut &2)); + assert_err(test, "Condition failed: `&mut x == *&&mut &2` (1 vs 2)"); +} + +#[rustversion::since(1.82)] +#[test] +fn test_raw_addr() { + let mut x = 1; + let test = || Ok(ensure!(S + &raw const x != S + &raw mut x)); + assert_err( + test, + "Condition failed: `S + &raw const x != S + &raw mut x` (false vs false)", + ); +} + +#[test] +fn test_if() { + #[rustfmt::skip] + let test = || Ok(ensure!(if false {}.t(1) == 2)); + assert_err(test, "Condition failed: `if false {}.t(1) == 2` (1 vs 2)"); + + #[rustfmt::skip] + let test = || Ok(ensure!(if false {} else {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `if false {} else {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(if false {} else if false {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `if false {} else if false {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(if let 1 = 2 {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `if let 1 = 2 {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(if let 1 | 2 = 2 {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `if let 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(if let | 1 | 2 = 2 {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `if let | 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)", + ); +} + +#[test] +fn test_loop() { + #[rustfmt::skip] + let test = || Ok(ensure!(1 + loop { break 1 } == 1)); + assert_err( + test, + "Condition failed: `1 + loop { break 1 } == 1` (2 vs 1)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(1 + 'a: loop { break 'a 1 } == 1)); + assert_err( + test, + "Condition failed: `1 + 'a: loop { break 'a 1 } == 1` (2 vs 1)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(while false {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `while false {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(while let None = Some(1) {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `while let None = Some(1) {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(for _x in iter::once(0) {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `for _x in iter::once(0) {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(for | _x in iter::once(0) {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `for | _x in iter::once(0) {}.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(for true | false in iter::empty() {}.t(1) == 2)); + assert_err( + test, + "Condition failed: `for true | false in iter::empty() {}.t(1) == 2` (1 vs 2)", + ); +} + +#[test] +fn test_match() { + #[rustfmt::skip] + let test = || Ok(ensure!(match 1 == 1 { true => 1, false => 0 } == 2)); + assert_err( + test, + "Condition failed: `match 1 == 1 { true => 1, false => 0 } == 2` (1 vs 2)", + ); +} + +#[test] +fn test_atom() { + let test = || Ok(ensure!([false, false].len() > 3)); + assert_err( + test, + "Condition failed: `[false, false].len() > 3` (2 vs 3)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!({ let x = 1; x } >= 3)); + assert_err(test, "Condition failed: `{ let x = 1; x } >= 3` (1 vs 3)"); + + let test = || Ok(ensure!(S + async { 1 } == true)); + assert_err( + test, + "Condition failed: `S + async { 1 } == true` (false vs true)", + ); + + let test = || Ok(ensure!(S + async move { 1 } == true)); + assert_err( + test, + "Condition failed: `S + async move { 1 } == true` (false vs true)", + ); + + let x = &1; + let test = || Ok(ensure!(S + unsafe { ptr::read(x) } == true)); + assert_err( + test, + "Condition failed: `S + unsafe { ptr::read(x) } == true` (false vs true)", + ); +} + +#[test] +fn test_path() { + let test = || Ok(ensure!(crate::S.t(1) == 2)); + assert_err(test, "Condition failed: `crate::S.t(1) == 2` (1 vs 2)"); + + let test = || Ok(ensure!(::anyhow::Error::root_cause.t(1) == 2)); + assert_err( + test, + "Condition failed: `::anyhow::Error::root_cause.t(1) == 2` (1 vs 2)", + ); + + let test = || Ok(ensure!(Error::msg::<&str>.t(1) == 2)); + assert_err( + test, + "Condition failed: `Error::msg::<&str>.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(Error::msg::<&str,>.t(1) == 2)); + assert_err( + test, + "Condition failed: `Error::msg::<&str,>.t(1) == 2` (1 vs 2)", + ); + + let test = || Ok(ensure!(Error::msg::<::Owned>.t(1) == 2)); + assert_err( + test, + "Condition failed: `Error::msg::<::Owned>.t(1) == 2` (1 vs 2)", + ); + + let test = || Ok(ensure!(Chain::<'static>::new.t(1) == 2)); + assert_err( + test, + "Condition failed: `Chain::<'static>::new.t(1) == 2` (1 vs 2)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(Chain::<'static,>::new.t(1) == 2)); + assert_err( + test, + "Condition failed: `Chain::<'static,>::new.t(1) == 2` (1 vs 2)", + ); + + fn f() {} + let test = || Ok(ensure!(f::<1>() != ())); + assert_err(test, "Condition failed: `f::<1>() != ()` (() vs ())"); + let test = || Ok(ensure!(f::<-1>() != ())); + assert_err(test, "Condition failed: `f::<-1>() != ()` (() vs ())"); + + fn g() {} + let test = || Ok(ensure!(g::() != ())); + assert_err(test, "Condition failed: `g::() != ()` (() vs ())"); + let test = || Ok(ensure!(g::() != ())); + assert_err(test, "Condition failed: `g::() != ()` (() vs ())"); + + #[derive(PartialOrd, PartialEq, Debug)] + enum E<'a, T> { + #[allow(dead_code)] + T(&'a T), + U, + } + + #[rustfmt::skip] + let test = || Ok(ensure!(E::U::<>>E::U::)); + assert_err(test, "Condition failed: `E::U::<> > E::U::` (U vs U)"); + + #[rustfmt::skip] + let test = || Ok(ensure!(E::U::>E::U)); + assert_err(test, "Condition failed: `E::U:: > E::U` (U vs U)"); + + #[rustfmt::skip] + let test = || Ok(ensure!(E::U::>E::U)); + assert_err(test, "Condition failed: `E::U:: > E::U` (U vs U)"); + + let test = || Ok(ensure!(Generic:: != Generic)); + assert_err( + test, + "Condition failed: `Generic:: != Generic` (Generic vs Generic)", + ); + + let test = || Ok(ensure!(Generic:: != Generic)); + assert_err( + test, + "Condition failed: `Generic:: != Generic` (Generic vs Generic)", + ); + + #[rustfmt::skip] + let test = || { + Ok(ensure!( + Generic:: != Generic + )) + }; + assert_err( + test, + "Condition failed: `Generic:: != Generic` (Generic vs Generic)", + ); +} + +#[test] +fn test_macro() { + let test = || Ok(ensure!(anyhow!("...").to_string().len() <= 1)); + assert_err( + test, + "Condition failed: `anyhow!(\"...\").to_string().len() <= 1` (3 vs 1)", + ); + + let test = || Ok(ensure!(vec![1].len() < 1)); + assert_err(test, "Condition failed: `vec![1].len() < 1` (1 vs 1)"); + + let test = || Ok(ensure!(stringify! {} != "")); + assert_err( + test, + "Condition failed: `stringify! {} != \"\"` (\"\" vs \"\")", + ); +} + +#[test] +fn test_trailer() { + let test = || Ok(ensure!((|| 1)() == 2)); + assert_err(test, "Condition failed: `(|| 1)() == 2` (1 vs 2)"); + + let test = || Ok(ensure!(b"hmm"[1] == b'c')); + assert_err(test, "Condition failed: `b\"hmm\"[1] == b'c'` (109 vs 99)"); + + let test = || Ok(ensure!(PhantomData:: {} != PhantomData)); + assert_err( + test, + "Condition failed: `PhantomData:: {} != PhantomData` (PhantomData vs PhantomData)", + ); + + let result = Ok::<_, Error>(1); + let test = || Ok(ensure!(result? == 2)); + assert_err(test, "Condition failed: `result? == 2` (1 vs 2)"); + + let test = || Ok(ensure!((2, 3).1 == 2)); + assert_err(test, "Condition failed: `(2, 3).1 == 2` (3 vs 2)"); + + #[rustfmt::skip] + let test = || Ok(ensure!((2, (3, 4)). 1.1 == 2)); + assert_err(test, "Condition failed: `(2, (3, 4)).1.1 == 2` (4 vs 2)"); + + let err = anyhow!(""); + let test = || Ok(ensure!(err.is::<&str>() == false)); + assert_err( + test, + "Condition failed: `err.is::<&str>() == false` (true vs false)", + ); + + let test = || Ok(ensure!(err.is::<::Owned>() == true)); + assert_err( + test, + "Condition failed: `err.is::<::Owned>() == true` (false vs true)", + ); +} + +#[test] +fn test_whitespace() { + #[derive(Debug)] + pub struct Point { + #[allow(dead_code)] + pub x: i32, + #[allow(dead_code)] + pub y: i32, + } + + let point = Point { x: 0, y: 0 }; + let test = || Ok(ensure!("" == format!("{:#?}", point))); + assert_err( + test, + "Condition failed: `\"\" == format!(\"{:#?}\", point)`", + ); +} + +#[test] +fn test_too_long() { + let test = || Ok(ensure!("" == "x".repeat(10))); + assert_err( + test, + "Condition failed: `\"\" == \"x\".repeat(10)` (\"\" vs \"xxxxxxxxxx\")", + ); + + let test = || Ok(ensure!("" == "x".repeat(80))); + assert_err(test, "Condition failed: `\"\" == \"x\".repeat(80)`"); +} + +#[test] +fn test_as() { + let test = || Ok(ensure!('\0' as u8 > 1)); + assert_err(test, "Condition failed: `'\\0' as u8 > 1` (0 vs 1)"); + + let test = || Ok(ensure!('\0' as ::std::primitive::u8 > 1)); + assert_err( + test, + "Condition failed: `'\\0' as ::std::primitive::u8 > 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(&[0] as &[i32] == [1])); + assert_err( + test, + "Condition failed: `&[0] as &[i32] == [1]` ([0] vs [1])", + ); + + let test = || Ok(ensure!(0 as *const () as *mut _ == 1 as *mut ())); + assert_err( + test, + "Condition failed: `0 as *const () as *mut _ == 1 as *mut ()` (0x0 vs 0x1)", + ); + + let s = ""; + let test = || Ok(ensure!(s as &str != s)); + assert_err(test, "Condition failed: `s as &str != s` (\"\" vs \"\")"); + + let test = || Ok(ensure!(&s as &&str != &s)); + assert_err(test, "Condition failed: `&s as &&str != &s` (\"\" vs \"\")"); + + let test = || Ok(ensure!(s as &'static str != s)); + assert_err( + test, + "Condition failed: `s as &'static str != s` (\"\" vs \"\")", + ); + + let test = || Ok(ensure!(&s as &&'static str != &s)); + assert_err( + test, + "Condition failed: `&s as &&'static str != &s` (\"\" vs \"\")", + ); + + let m: &mut str = Default::default(); + let test = || Ok(ensure!(m as &mut str != s)); + assert_err( + test, + "Condition failed: `m as &mut str != s` (\"\" vs \"\")", + ); + + let test = || Ok(ensure!(&m as &&mut str != &s)); + assert_err( + test, + "Condition failed: `&m as &&mut str != &s` (\"\" vs \"\")", + ); + + let test = || Ok(ensure!(&m as &&'static mut str != &s)); + assert_err( + test, + "Condition failed: `&m as &&'static mut str != &s` (\"\" vs \"\")", + ); + + let f = || {}; + let test = || Ok(ensure!(f as fn() as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `f as fn() as usize * 0 != 0` (0 vs 0)", + ); + + let test = || Ok(ensure!(f as fn() -> () as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `f as fn() -> () as usize * 0 != 0` (0 vs 0)", + ); + + let test = || Ok(ensure!(f as for<'a> fn() as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `f as for<'a> fn() as usize * 0 != 0` (0 vs 0)", + ); + + let test = || Ok(ensure!(f as unsafe fn() as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `f as unsafe fn() as usize * 0 != 0` (0 vs 0)", + ); + + #[rustfmt::skip] + let test = || Ok(ensure!(f as extern "Rust" fn() as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `f as extern \"Rust\" fn() as usize * 0 != 0` (0 vs 0)", + ); + + extern "C" fn extern_fn() {} + #[rustfmt::skip] + #[allow(missing_abi)] + let test = || Ok(ensure!(extern_fn as extern fn() as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `extern_fn as extern fn() as usize * 0 != 0` (0 vs 0)", + ); + + let f = || -> ! { panic!() }; + let test = || Ok(ensure!(f as fn() -> ! as usize * 0 != 0)); + assert_err( + test, + "Condition failed: `f as fn() -> ! as usize * 0 != 0` (0 vs 0)", + ); + + trait EqDebug: PartialEq + Debug { + type Assoc; + } + + impl EqDebug for S + where + S: PartialEq + Debug, + { + type Assoc = bool; + } + + let test = || Ok(ensure!(&0 as &dyn EqDebug != &0)); + assert_err( + test, + "Condition failed: `&0 as &dyn EqDebug != &0` (0 vs 0)", + ); + + let test = || { + Ok(ensure!( + PhantomData as PhantomData<::Owned> != PhantomData + )) + }; + assert_err( + test, + "Condition failed: `PhantomData as PhantomData<::Owned> != PhantomData` (PhantomData vs PhantomData)", + ); + + macro_rules! int { + (...) => { + u8 + }; + } + + let test = || Ok(ensure!(0 as int!(...) != 0)); + assert_err(test, "Condition failed: `0 as int!(...) != 0` (0 vs 0)"); + + let test = || Ok(ensure!(0 as int![...] != 0)); + assert_err(test, "Condition failed: `0 as int![...] != 0` (0 vs 0)"); + + let test = || Ok(ensure!(0 as int! {...} != 0)); + assert_err(test, "Condition failed: `0 as int! {...} != 0` (0 vs 0)"); +} + +#[test] +fn test_pat() { + let test = || Ok(ensure!(if let ref mut _x @ 0 = 0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let ref mut _x @ 0 = 0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let -1..=1 = 0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let -1..=1 = 0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let &0 = &0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let &0 = &0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let &&0 = &&0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let &&0 = &&0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let &mut 0 = &mut 0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let &mut 0 = &mut 0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let &&mut 0 = &&mut 0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let &&mut 0 = &&mut 0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let (0, 1) = (0, 1) { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let (0, 1) = (0, 1) { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let [0] = b"\0" { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let [0] = b\"\\0\" { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let p = PhantomData::; + let test = || Ok(ensure!(if let P:: {} = p { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let P:: {} = p { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(if let ::std::marker::PhantomData = p {} != ())); + assert_err( + test, + "Condition failed: `if let ::std::marker::PhantomData = p {} != ()` (() vs ())", + ); + + let test = || Ok(ensure!(if let ::V = 0 { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let ::V = 0 { 0 } else { 1 } == 1` (0 vs 1)", + ); + + let test = || Ok(ensure!(for _ in iter::once(()) {} != ())); + assert_err( + test, + "Condition failed: `for _ in iter::once(()) {} != ()` (() vs ())", + ); + + let test = || Ok(ensure!(if let stringify!(x) = "x" { 0 } else { 1 } == 1)); + assert_err( + test, + "Condition failed: `if let stringify!(x) = \"x\" { 0 } else { 1 } == 1` (0 vs 1)", + ); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_ffi.rs b/third_party/crates/anyhow-1.0.104/tests/test_ffi.rs new file mode 100644 index 0000000..59578af --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_ffi.rs @@ -0,0 +1,19 @@ +#![deny(improper_ctypes, improper_ctypes_definitions)] +#![allow(clippy::uninlined_format_args)] + +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) { + *err = Some(anyhow!("ffi error")); +} + +#[no_mangle] +pub extern "C" fn anyhow3() -> Option { + Some(anyhow!("ffi error")) +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_fmt.rs b/third_party/crates/anyhow-1.0.104/tests/test_fmt.rs new file mode 100644 index 0000000..8206f22 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_fmt.rs @@ -0,0 +1,93 @@ +use anyhow::{bail, Context, Result}; +use std::io; + +fn f() -> Result<()> { + bail!(io::Error::new(io::ErrorKind::PermissionDenied, "oh no!")); +} + +fn g() -> Result<()> { + f().context("f failed") +} + +fn h() -> Result<()> { + g().context("g failed") +} + +const EXPECTED_ALTDISPLAY_F: &str = "oh no!"; + +const EXPECTED_ALTDISPLAY_G: &str = "f failed: oh no!"; + +const EXPECTED_ALTDISPLAY_H: &str = "g failed: f failed: oh no!"; + +const EXPECTED_DEBUG_F: &str = "oh no!"; + +const EXPECTED_DEBUG_G: &str = "\ +f failed + +Caused by: + oh no!\ +"; + +const EXPECTED_DEBUG_H: &str = "\ +g failed + +Caused by: + 0: f failed + 1: oh no!\ +"; + +const EXPECTED_ALTDEBUG_F: &str = "\ +Custom { + kind: PermissionDenied, + error: \"oh no!\", +}\ +"; + +const EXPECTED_ALTDEBUG_G: &str = "\ +Error { + context: \"f failed\", + source: Custom { + kind: PermissionDenied, + error: \"oh no!\", + }, +}\ +"; + +const EXPECTED_ALTDEBUG_H: &str = "\ +Error { + context: \"g failed\", + source: Error { + context: \"f failed\", + source: Custom { + kind: PermissionDenied, + error: \"oh no!\", + }, + }, +}\ +"; + +#[test] +fn test_display() { + assert_eq!("g failed", h().unwrap_err().to_string()); +} + +#[test] +fn test_altdisplay() { + assert_eq!(EXPECTED_ALTDISPLAY_F, format!("{:#}", f().unwrap_err())); + assert_eq!(EXPECTED_ALTDISPLAY_G, format!("{:#}", g().unwrap_err())); + assert_eq!(EXPECTED_ALTDISPLAY_H, format!("{:#}", h().unwrap_err())); +} + +#[test] +fn test_debug() { + assert_eq!(EXPECTED_DEBUG_F, format!("{:?}", f().unwrap_err())); + assert_eq!(EXPECTED_DEBUG_G, format!("{:?}", g().unwrap_err())); + assert_eq!(EXPECTED_DEBUG_H, format!("{:?}", h().unwrap_err())); +} + +#[test] +fn test_altdebug() { + assert_eq!(EXPECTED_ALTDEBUG_F, format!("{:#?}", f().unwrap_err())); + assert_eq!(EXPECTED_ALTDEBUG_G, format!("{:#?}", g().unwrap_err())); + assert_eq!(EXPECTED_ALTDEBUG_H, format!("{:#?}", h().unwrap_err())); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_macros.rs b/third_party/crates/anyhow-1.0.104/tests/test_macros.rs new file mode 100644 index 0000000..0689506 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_macros.rs @@ -0,0 +1,97 @@ +#![allow( + clippy::assertions_on_result_states, + clippy::eq_op, + clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257 + clippy::items_after_statements, + clippy::match_single_binding, + clippy::needless_pass_by_value, + clippy::shadow_unrelated, + clippy::uninlined_format_args, + clippy::wildcard_imports +)] + +mod common; + +use self::common::*; +use anyhow::{anyhow, ensure, Result}; +use std::cell::Cell; +use std::future; + +#[test] +fn test_messages() { + assert_eq!("oh no!", bail_literal().unwrap_err().to_string()); + assert_eq!("oh no!", bail_fmt().unwrap_err().to_string()); + assert_eq!("oh no!", bail_error().unwrap_err().to_string()); +} + +#[test] +fn test_ensure() { + let f = || { + ensure!(1 + 1 == 2, "This is correct"); + Ok(()) + }; + assert!(f().is_ok()); + + let v = 1; + let f = || { + ensure!(v + v == 2, "This is correct, v: {}", v); + Ok(()) + }; + assert!(f().is_ok()); + + let f = || { + ensure!(v + v == 1, "This is not correct, v: {}", v); + Ok(()) + }; + assert!(f().is_err()); + + let f = || { + ensure!(v + v == 1); + Ok(()) + }; + assert_eq!( + f().unwrap_err().to_string(), + "Condition failed: `v + v == 1` (2 vs 1)", + ); +} + +#[test] +fn test_ensure_nonbool() -> Result<()> { + struct Struct { + condition: bool, + } + + let s = Struct { condition: true }; + match &s { + Struct { condition } => ensure!(condition), // &bool + } + + Ok(()) +} + +#[test] +fn test_temporaries() { + fn require_send_sync(_: impl Send + Sync) {} + + require_send_sync(async { + // If anyhow hasn't dropped any temporary format_args it creates by the + // time it's done evaluating, those will stick around until the + // semicolon, which is on the other side of the await point, making the + // enclosing future non-Send. + future::ready(anyhow!("...")).await; + }); + + fn message(cell: Cell<&str>) -> &str { + cell.get() + } + + require_send_sync(async { + future::ready(anyhow!(message(Cell::new("...")))).await; + }); +} + +#[test] +fn test_brace_escape() { + let err = anyhow!("unterminated ${{..}} expression"); + assert_eq!("unterminated ${..} expression", err.to_string()); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_repr.rs b/third_party/crates/anyhow-1.0.104/tests/test_repr.rs new file mode 100644 index 0000000..2976cd8 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_repr.rs @@ -0,0 +1,30 @@ +#![allow(clippy::extra_unused_type_parameters)] + +mod drop; + +use self::drop::{DetectDrop, Flag}; +use anyhow::Error; +use std::mem; + +#[test] +fn test_error_size() { + assert_eq!(mem::size_of::(), mem::size_of::()); +} + +#[test] +fn test_null_pointer_optimization() { + assert_eq!(mem::size_of::>(), mem::size_of::()); +} + +#[test] +fn test_autotraits() { + fn assert() {} + assert::(); +} + +#[test] +fn test_drop() { + let has_dropped = Flag::new(); + drop(Error::new(DetectDrop::new(&has_dropped))); + assert!(has_dropped.get()); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_source.rs b/third_party/crates/anyhow-1.0.104/tests/test_source.rs new file mode 100644 index 0000000..018267d --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/test_source.rs @@ -0,0 +1,62 @@ +use anyhow::anyhow; +use std::error::Error as StdError; +use std::fmt::{self, Display}; +use std::io; + +#[derive(Debug)] +enum TestError { + Io(io::Error), +} + +impl Display for TestError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + match self { + TestError::Io(e) => Display::fmt(e, formatter), + } + } +} + +impl StdError for TestError { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + match self { + TestError::Io(io) => Some(io), + } + } +} + +#[test] +fn test_literal_source() { + let error = anyhow!("oh no!"); + assert!(error.source().is_none()); +} + +#[test] +fn test_variable_source() { + let msg = "oh no!"; + let error = anyhow!(msg); + assert!(error.source().is_none()); + + let msg = msg.to_owned(); + let error = anyhow!(msg); + assert!(error.source().is_none()); +} + +#[test] +fn test_fmt_source() { + let error = anyhow!("{} {}!", "oh", "no"); + assert!(error.source().is_none()); +} + +#[test] +fn test_io_source() { + let io = io::Error::new(io::ErrorKind::Other, "oh no!"); + let error = anyhow!(TestError::Io(io)); + assert_eq!("oh no!", error.source().unwrap().to_string()); +} + +#[test] +fn test_anyhow_from_anyhow() { + let error = anyhow!("oh no!").context("context"); + let error = anyhow!(error); + assert_eq!("oh no!", error.source().unwrap().to_string()); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs b/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs new file mode 100644 index 0000000..4521b51 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs @@ -0,0 +1,8 @@ +use anyhow::{ensure, Result}; + +fn main() -> Result<()> { + // `ensure!` must not partition this into `(false) == (false == true)` + // because Rust doesn't ordinarily allow this form of expression. + ensure!(false == false == true); + Ok(()) +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr new file mode 100644 index 0000000..2a4c665 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr @@ -0,0 +1,10 @@ +error: comparison operators cannot be chained + --> tests/ui/chained-comparison.rs:6:19 + | +6 | ensure!(false == false == true); + | ^^ ^^ + | +help: split the comparison into two + | +6 | ensure!(false == false && false == true); + | ++++++++ diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs b/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs new file mode 100644 index 0000000..139b743 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs @@ -0,0 +1,6 @@ +use anyhow::{ensure, Result}; + +fn main() -> Result<()> { + ensure!(); + Ok(()) +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr new file mode 100644 index 0000000..bf0229a --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr @@ -0,0 +1,12 @@ +error: unexpected end of macro invocation + --> tests/ui/empty-ensure.rs:4:5 + | +4 | ensure!(); + | ^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$cond:expr` + --> src/ensure.rs + | + | ($cond:expr $(,)?) => { + | ^^^^^^^^^^ + = note: this error originates in the macro `$crate::__parse_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs b/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs new file mode 100644 index 0000000..c7df4e1 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs @@ -0,0 +1,40 @@ +use anyhow::{ensure, Result}; +use std::ops::{Deref, Not}; + +struct Bool(bool); + +struct DerefBool(bool); + +struct NotBool(bool); + +impl Deref for DerefBool { + type Target = bool; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Not for NotBool { + type Output = bool; + fn not(self) -> Self::Output { + !self.0 + } +} + +fn main() -> Result<()> { + ensure!("..."); + + let mut s = Bool(true); + match &mut s { + Bool(cond) => ensure!(cond), + } + + let db = DerefBool(true); + ensure!(db); + ensure!(&db); + + let nb = NotBool(true); + ensure!(nb); + + Ok(()) +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr new file mode 100644 index 0000000..5a4e0ec --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr @@ -0,0 +1,113 @@ +error[E0277]: the trait bound `&str: anyhow::__private::not::Bool` is not satisfied + --> tests/ui/ensure-nonbool.rs:25:13 + | +25 | ensure!("..."); + | --------^^^^^- + | | | + | | the trait `anyhow::__private::not::Bool` is not implemented for `&str` + | required by a bound introduced by this call + | +help: the following other types implement trait `anyhow::__private::not::Bool` + --> src/lib.rs + | + | impl Bool for bool { + | ^^^^^^^^^^^^^^^^^^ `bool` +... + | impl Bool for &bool { + | ^^^^^^^^^^^^^^^^^^^ `&bool` +note: required by a bound in `anyhow::__private::not` + --> src/lib.rs + | + | pub fn not(cond: impl Bool) -> bool { + | ^^^^ required by this bound in `not` + +error[E0277]: the trait bound `&mut bool: anyhow::__private::not::Bool` is not satisfied + --> tests/ui/ensure-nonbool.rs:29:31 + | +29 | Bool(cond) => ensure!(cond), + | --------^^^^- + | | | + | | the trait `anyhow::__private::not::Bool` is not implemented for `&mut bool` + | required by a bound introduced by this call + | + = note: `anyhow::__private::not::Bool` is implemented for `&bool`, but not for `&mut bool` +note: required by a bound in `anyhow::__private::not` + --> src/lib.rs + | + | pub fn not(cond: impl Bool) -> bool { + | ^^^^ required by this bound in `not` +help: consider dereferencing here + | +29 | Bool(cond) => ensure!(*cond), + | + + +error[E0277]: the trait bound `DerefBool: anyhow::__private::not::Bool` is not satisfied + --> tests/ui/ensure-nonbool.rs:33:13 + | +33 | ensure!(db); + | --------^^- + | | | + | | unsatisfied trait bound + | required by a bound introduced by this call + | +help: the trait `anyhow::__private::not::Bool` is not implemented for `DerefBool` + --> tests/ui/ensure-nonbool.rs:6:1 + | + 6 | struct DerefBool(bool); + | ^^^^^^^^^^^^^^^^ +note: required by a bound in `anyhow::__private::not` + --> src/lib.rs + | + | pub fn not(cond: impl Bool) -> bool { + | ^^^^ required by this bound in `not` +help: consider dereferencing here + | +33 | ensure!(*db); + | + + +error[E0277]: the trait bound `&DerefBool: anyhow::__private::not::Bool` is not satisfied + --> tests/ui/ensure-nonbool.rs:34:13 + | +34 | ensure!(&db); + | --------^^^- + | | | + | | the trait `anyhow::__private::not::Bool` is not implemented for `&DerefBool` + | required by a bound introduced by this call + | +note: required by a bound in `anyhow::__private::not` + --> src/lib.rs + | + | pub fn not(cond: impl Bool) -> bool { + | ^^^^ required by this bound in `not` +help: consider dereferencing here + | +34 | ensure!(&*db); + | + + +error[E0277]: the trait bound `NotBool: anyhow::__private::not::Bool` is not satisfied + --> tests/ui/ensure-nonbool.rs:37:13 + | +37 | ensure!(nb); + | --------^^- + | | | + | | unsatisfied trait bound + | required by a bound introduced by this call + | +help: the trait `anyhow::__private::not::Bool` is not implemented for `NotBool` + --> tests/ui/ensure-nonbool.rs:8:1 + | + 8 | struct NotBool(bool); + | ^^^^^^^^^^^^^^ +help: the following other types implement trait `anyhow::__private::not::Bool` + --> src/lib.rs + | + | impl Bool for bool { + | ^^^^^^^^^^^^^^^^^^ `bool` +... + | impl Bool for &bool { + | ^^^^^^^^^^^^^^^^^^^ `&bool` +note: required by a bound in `anyhow::__private::not` + --> src/lib.rs + | + | pub fn not(cond: impl Bool) -> bool { + | ^^^^ required by this bound in `not` diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs b/third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs new file mode 100644 index 0000000..ea4e58f --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs @@ -0,0 +1,11 @@ +#![deny(unused_must_use)] + +use anyhow::anyhow; + +fn main() -> anyhow::Result<()> { + if true { + // meant to write bail! + anyhow!("it failed"); + } + Ok(()) +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr new file mode 100644 index 0000000..b2a3f31 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr @@ -0,0 +1,15 @@ +error: unused return value of `anyhow::__private::must_use` that must be used + --> tests/ui/must-use.rs:8:9 + | +8 | anyhow!("it failed"); + | ^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui/must-use.rs:1:9 + | +1 | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +8 | let _ = anyhow!("it failed"); + | +++++++ diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs b/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs new file mode 100644 index 0000000..d2e89af --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs @@ -0,0 +1,8 @@ +use anyhow::anyhow; + +#[derive(Debug)] +struct Error; + +fn main() { + let _ = anyhow!(Error); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr new file mode 100644 index 0000000..9b584df --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr @@ -0,0 +1,32 @@ +error[E0599]: the method `anyhow_kind` exists for reference `&Error`, but its trait bounds were not satisfied + --> tests/ui/no-impl.rs:7:13 + | +4 | struct Error; + | ------------ doesn't satisfy `Error: Into`, `Error: anyhow::kind::TraitKind` or `Error: std::fmt::Display` +... +7 | let _ = anyhow!(Error); + | ^^^^^^^^^^^^^^ method cannot be called on `&Error` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `Error: Into` + which is required by `Error: anyhow::kind::TraitKind` + `Error: std::fmt::Display` + which is required by `&Error: anyhow::kind::AdhocKind` + `&Error: Into` + which is required by `&Error: anyhow::kind::TraitKind` +note: the traits `Into` and `std::fmt::Display` must be implemented + --> $RUST/core/src/fmt/mod.rs + | + | pub trait Display: PointeeSized { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + ::: $RUST/core/src/convert/mod.rs + | + | pub const trait Into: Sized { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = 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::BoxedKind` + candidate #3: `anyhow::kind::TraitKind` + = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs b/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs new file mode 100644 index 0000000..803809b --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs @@ -0,0 +1,5 @@ +use anyhow::anyhow; + +fn main() { + let _ = anyhow!(&String::new()); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr new file mode 100644 index 0000000..c92ec92 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr @@ -0,0 +1,15 @@ +error[E0716]: temporary value dropped while borrowed + --> tests/ui/temporary-value.rs:4:22 + | +4 | let _ = anyhow!(&String::new()); + | ---------^^^^^^^^^^^^^- + | | | + | | creates a temporary value which is freed while still in use + | temporary value is freed at the end of this statement + | argument requires that borrow lasts for `'static` + | +note: requirement that the value outlives `'static` introduced here + --> src/kind.rs + | + | M: Display + Debug + Send + Sync + 'static, + | ^^^^^^^ diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs b/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs new file mode 100644 index 0000000..b870ca7 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs @@ -0,0 +1,5 @@ +use anyhow::{bail, Result}; + +fn main() -> Result<()> { + bail!("{} not found"); +} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr new file mode 100644 index 0000000..55a2964 --- /dev/null +++ b/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr @@ -0,0 +1,5 @@ +error: 1 positional argument in format string, but no arguments were given + --> tests/ui/wrong-interpolation.rs:4:12 + | +4 | bail!("{} not found"); + | ^^ diff --git a/third_party/crates/crates.bzl b/third_party/crates/crates.bzl new file mode 100644 index 0000000..0fd3a5e --- /dev/null +++ b/third_party/crates/crates.bzl @@ -0,0 +1,436 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//third_party:vendor_crates +############################################################################### +""" +# `crates_repository` API + +- [aliases](#aliases) +- [crate_edition](#crate_edition) +- [crate_deps](#crate_deps) +- [all_crate_deps](#all_crate_deps) +- [crate_repositories](#crate_repositories) + +""" + +load("@bazel_skylib//lib:selects.bzl", "selects") + +############################################################################### +# MACROS API +############################################################################### + +# An identifier that represent common dependencies (unconditional). +_COMMON_CONDITION = "" + +def _flatten_dependency_maps(all_dependency_maps): + """Flatten a list of dependency maps into one dictionary. + + Dependency maps have the following structure: + + ```python + DEPENDENCIES_MAP = { + # The first key in the map is a Bazel package + # name of the workspace this file is defined in. + "workspace_member_package": { + + # Not all dependencies are supported for all platforms. + # the condition key is the condition required to be true + # on the host platform. + "condition": { + + # An alias to a crate target. # The label of the crate target the + # Aliases are only crate names. # package name refers to. + "package_name": "@full//:label", + } + } + } + ``` + + Args: + all_dependency_maps (list): A list of dicts as described above + + Returns: + dict: A dictionary as described above + """ + dependencies = {} + + for workspace_deps_map in all_dependency_maps: + for pkg_name, conditional_deps_map in workspace_deps_map.items(): + if pkg_name not in dependencies: + non_frozen_map = dict() + for key, values in conditional_deps_map.items(): + non_frozen_map.update({key: dict(values.items())}) + dependencies.setdefault(pkg_name, non_frozen_map) + continue + + for condition, deps_map in conditional_deps_map.items(): + # If the condition has not been recorded, do so and continue + if condition not in dependencies[pkg_name]: + dependencies[pkg_name].setdefault(condition, dict(deps_map.items())) + continue + + # Alert on any miss-matched dependencies + inconsistent_entries = [] + for crate_name, crate_label in deps_map.items(): + existing = dependencies[pkg_name][condition].get(crate_name) + if existing and existing != crate_label: + inconsistent_entries.append((crate_name, existing, crate_label)) + dependencies[pkg_name][condition].update({crate_name: crate_label}) + + return dependencies + +def crate_deps(deps, package_name = None): + """Finds the fully qualified label of the requested crates for the package where this macro is called. + + Args: + deps (list): The desired list of crate targets. + package_name (str, optional): The package name of the set of dependencies to look up. + Defaults to `native.package_name()`. + + Returns: + list: A list of labels to generated rust targets (str) + """ + + if not deps: + return [] + + if package_name == None: + package_name = native.package_name() + + # Join both sets of dependencies + dependencies = _flatten_dependency_maps([ + _NORMAL_DEPENDENCIES, + _NORMAL_DEV_DEPENDENCIES, + _PROC_MACRO_DEPENDENCIES, + _PROC_MACRO_DEV_DEPENDENCIES, + _BUILD_DEPENDENCIES, + _BUILD_PROC_MACRO_DEPENDENCIES, + ]).pop(package_name, {}) + + # Combine all conditional packages so we can easily index over a flat list + # TODO: Perhaps this should actually return select statements and maintain + # the conditionals of the dependencies + flat_deps = {} + for deps_set in dependencies.values(): + for crate_name, crate_label in deps_set.items(): + flat_deps.update({crate_name: crate_label}) + + missing_crates = [] + crate_targets = [] + for crate_target in deps: + if crate_target not in flat_deps: + missing_crates.append(crate_target) + else: + crate_targets.append(flat_deps[crate_target]) + + if missing_crates: + fail("Could not find crates `{}` among dependencies of `{}`. Available dependencies were `{}`".format( + missing_crates, + package_name, + dependencies, + )) + + return crate_targets + +def crate_edition(package_name = None): + """Finds the Rust edition for the package where this macro is called. + + Args: + package_name (str, optional): The package name whose edition should be + looked up. Defaults to `native.package_name()` when unset. + + Returns: + str: The Rust edition declared by the package's Cargo.toml file. + """ + if package_name == None: + package_name = native.package_name() + + if package_name not in _CRATE_EDITIONS: + fail("Tried to get crate_edition for package " + package_name + " but that package had no Cargo.toml file") + + return _CRATE_EDITIONS[package_name] + +def all_crate_deps( + normal = False, + normal_dev = False, + proc_macro = False, + proc_macro_dev = False, + build = False, + build_proc_macro = False, + package_name = None): + """Finds the fully qualified label of all requested direct crate dependencies \ + for the package where this macro is called. + + If no parameters are set, all normal dependencies are returned. Setting any one flag will + otherwise impact the contents of the returned list. + + Args: + normal (bool, optional): If True, normal dependencies are included in the + output list. + normal_dev (bool, optional): If True, normal dev dependencies will be + included in the output list. + proc_macro (bool, optional): If True, proc_macro dependencies are included + in the output list. + proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are + included in the output list. + build (bool, optional): If True, build dependencies are included + in the output list. + build_proc_macro (bool, optional): If True, build proc_macro dependencies are + included in the output list. + package_name (str, optional): The package name of the set of dependencies to look up. + Defaults to `native.package_name()` when unset. + + Returns: + list: A list of labels to generated rust targets (str) + """ + + if package_name == None: + package_name = native.package_name() + + # Determine the relevant maps to use + all_dependency_maps = [] + if normal: + all_dependency_maps.append(_NORMAL_DEPENDENCIES) + if normal_dev: + all_dependency_maps.append(_NORMAL_DEV_DEPENDENCIES) + if proc_macro: + all_dependency_maps.append(_PROC_MACRO_DEPENDENCIES) + if proc_macro_dev: + all_dependency_maps.append(_PROC_MACRO_DEV_DEPENDENCIES) + if build: + all_dependency_maps.append(_BUILD_DEPENDENCIES) + if build_proc_macro: + all_dependency_maps.append(_BUILD_PROC_MACRO_DEPENDENCIES) + + # Default to always using normal dependencies + if not all_dependency_maps: + all_dependency_maps.append(_NORMAL_DEPENDENCIES) + + dependencies = _flatten_dependency_maps(all_dependency_maps).pop(package_name, None) + + if not dependencies: + if dependencies == None: + fail("Tried to get all_crate_deps for package " + package_name + " but that package had no Cargo.toml file") + else: + return [] + + crate_deps = list(dependencies.pop(_COMMON_CONDITION, {}).values()) + for condition, deps in dependencies.items(): + crate_deps += selects.with_or({ + tuple(_CONDITIONS[condition]): deps.values(), + "//conditions:default": [], + }) + + return crate_deps + +def aliases( + normal = False, + normal_dev = False, + proc_macro = False, + proc_macro_dev = False, + build = False, + build_proc_macro = False, + package_name = None): + """Produces a map of Crate alias names to their original label + + If no dependency kinds are specified, `normal` and `proc_macro` are used by default. + Setting any one flag will otherwise determine the contents of the returned dict. + + Args: + normal (bool, optional): If True, normal dependencies are included in the + output list. + normal_dev (bool, optional): If True, normal dev dependencies will be + included in the output list.. + proc_macro (bool, optional): If True, proc_macro dependencies are included + in the output list. + proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are + included in the output list. + build (bool, optional): If True, build dependencies are included + in the output list. + build_proc_macro (bool, optional): If True, build proc_macro dependencies are + included in the output list. + package_name (str, optional): The package name of the set of dependencies to look up. + Defaults to `native.package_name()` when unset. + + Returns: + dict: The aliases of all associated packages + """ + if package_name == None: + package_name = native.package_name() + + # Determine the relevant maps to use + all_aliases_maps = [] + if normal: + all_aliases_maps.append(_NORMAL_ALIASES) + if normal_dev: + all_aliases_maps.append(_NORMAL_DEV_ALIASES) + if proc_macro: + all_aliases_maps.append(_PROC_MACRO_ALIASES) + if proc_macro_dev: + all_aliases_maps.append(_PROC_MACRO_DEV_ALIASES) + if build: + all_aliases_maps.append(_BUILD_ALIASES) + if build_proc_macro: + all_aliases_maps.append(_BUILD_PROC_MACRO_ALIASES) + + # Default to always using normal aliases + if not all_aliases_maps: + all_aliases_maps.append(_NORMAL_ALIASES) + all_aliases_maps.append(_PROC_MACRO_ALIASES) + + aliases = _flatten_dependency_maps(all_aliases_maps).pop(package_name, None) + + if not aliases: + return dict() + + common_items = aliases.pop(_COMMON_CONDITION, {}).items() + + # If there are only common items in the dictionary, immediately return them + if not len(aliases.keys()) == 1: + return dict(common_items) + + # Build a single select statement where each conditional has accounted for the + # common set of aliases. + crate_aliases = {"//conditions:default": dict(common_items)} + for condition, deps in aliases.items(): + condition_triples = _CONDITIONS[condition] + for triple in condition_triples: + if triple in crate_aliases: + crate_aliases[triple].update(deps) + else: + crate_aliases.update({triple: dict(deps.items() + common_items)}) + + return select(crate_aliases) + +############################################################################### +# WORKSPACE MEMBER DEPS, ALIASES, AND EDITIONS +############################################################################### + +_CRATE_EDITIONS = { + "src/machoke": "2024", +} + +_NORMAL_DEPENDENCIES = { + "src/machoke": { + _COMMON_CONDITION: { + "anyhow": Label("//third_party/crates/anyhow-1.0.104:anyhow"), + }, + }, +} + +_NORMAL_ALIASES = { + "src/machoke": { + _COMMON_CONDITION: { + }, + }, +} + +_NORMAL_DEV_DEPENDENCIES = { + "src/machoke": { + }, +} + +_NORMAL_DEV_ALIASES = { + "src/machoke": { + }, +} + +_PROC_MACRO_DEPENDENCIES = { + "src/machoke": { + }, +} + +_PROC_MACRO_ALIASES = { + "src/machoke": { + }, +} + +_PROC_MACRO_DEV_DEPENDENCIES = { + "src/machoke": { + }, +} + +_PROC_MACRO_DEV_ALIASES = { + "src/machoke": { + }, +} + +_BUILD_DEPENDENCIES = { + "src/machoke": { + }, +} + +_BUILD_ALIASES = { + "src/machoke": { + }, +} + +_BUILD_PROC_MACRO_DEPENDENCIES = { + "src/machoke": { + }, +} + +_BUILD_PROC_MACRO_ALIASES = { + "src/machoke": { + }, +} + +_CONDITIONS = { + "aarch64-apple-darwin": ["@rules_rust//rust/platform:aarch64-apple-darwin"], + "aarch64-apple-ios": ["@rules_rust//rust/platform:aarch64-apple-ios"], + "aarch64-apple-ios-macabi": ["@rules_rust//rust/platform:aarch64-apple-ios-macabi"], + "aarch64-apple-ios-sim": ["@rules_rust//rust/platform:aarch64-apple-ios-sim"], + "aarch64-linux-android": ["@rules_rust//rust/platform:aarch64-linux-android"], + "aarch64-pc-windows-msvc": ["@rules_rust//rust/platform:aarch64-pc-windows-msvc"], + "aarch64-unknown-fuchsia": ["@rules_rust//rust/platform:aarch64-unknown-fuchsia"], + "aarch64-unknown-linux-gnu": ["@rules_rust//rust/platform:aarch64-unknown-linux-gnu"], + "aarch64-unknown-nixos-gnu": ["@rules_rust//rust/platform:aarch64-unknown-nixos-gnu"], + "aarch64-unknown-none": ["@rules_rust//rust/platform:aarch64-unknown-none"], + "aarch64-unknown-nto-qnx710": ["@rules_rust//rust/platform:aarch64-unknown-nto-qnx710"], + "aarch64-unknown-uefi": ["@rules_rust//rust/platform:aarch64-unknown-uefi"], + "arm-unknown-linux-gnueabi": ["@rules_rust//rust/platform:arm-unknown-linux-gnueabi"], + "arm-unknown-linux-musleabi": ["@rules_rust//rust/platform:arm-unknown-linux-musleabi"], + "armv7-linux-androideabi": ["@rules_rust//rust/platform:armv7-linux-androideabi"], + "armv7-unknown-linux-gnueabi": ["@rules_rust//rust/platform:armv7-unknown-linux-gnueabi"], + "i686-apple-darwin": ["@rules_rust//rust/platform:i686-apple-darwin"], + "i686-linux-android": ["@rules_rust//rust/platform:i686-linux-android"], + "i686-pc-windows-msvc": ["@rules_rust//rust/platform:i686-pc-windows-msvc"], + "i686-unknown-freebsd": ["@rules_rust//rust/platform:i686-unknown-freebsd"], + "i686-unknown-linux-gnu": ["@rules_rust//rust/platform:i686-unknown-linux-gnu"], + "loongarch64-unknown-linux-gnu": ["@rules_rust//rust/platform:loongarch64-unknown-linux-gnu"], + "mips-unknown-linux-gnu": ["@rules_rust//rust/platform:mips-unknown-linux-gnu"], + "powerpc-unknown-linux-gnu": ["@rules_rust//rust/platform:powerpc-unknown-linux-gnu"], + "riscv32imac-unknown-none-elf": ["@rules_rust//rust/platform:riscv32imac-unknown-none-elf"], + "riscv32imc-unknown-none-elf": ["@rules_rust//rust/platform:riscv32imc-unknown-none-elf"], + "riscv64gc-unknown-linux-gnu": ["@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu"], + "riscv64gc-unknown-none-elf": ["@rules_rust//rust/platform:riscv64gc-unknown-none-elf"], + "s390x-unknown-linux-gnu": ["@rules_rust//rust/platform:s390x-unknown-linux-gnu"], + "sparc64-unknown-linux-gnu": ["@rules_rust//rust/platform:sparc64-unknown-linux-gnu"], + "sparc64-unknown-netbsd": ["@rules_rust//rust/platform:sparc64-unknown-netbsd"], + "sparc64-unknown-openbsd": ["@rules_rust//rust/platform:sparc64-unknown-openbsd"], + "thumbv6m-none-eabi": ["@rules_rust//rust/platform:thumbv6m-none-eabi"], + "thumbv7em-none-eabi": ["@rules_rust//rust/platform:thumbv7em-none-eabi"], + "thumbv7em-none-eabihf": ["@rules_rust//rust/platform:thumbv7em-none-eabihf"], + "thumbv7m-none-eabi": ["@rules_rust//rust/platform:thumbv7m-none-eabi"], + "thumbv8m.main-none-eabi": ["@rules_rust//rust/platform:thumbv8m.main-none-eabi"], + "thumbv8m.main-none-eabihf": ["@rules_rust//rust/platform:thumbv8m.main-none-eabihf"], + "wasm32-unknown-emscripten": ["@rules_rust//rust/platform:wasm32-unknown-emscripten"], + "wasm32-unknown-unknown": ["@rules_rust//rust/platform:wasm32-unknown-unknown"], + "wasm32-wasip1": ["@rules_rust//rust/platform:wasm32-wasip1"], + "wasm32-wasip1-threads": ["@rules_rust//rust/platform:wasm32-wasip1-threads"], + "wasm32-wasip2": ["@rules_rust//rust/platform:wasm32-wasip2"], + "x86_64-apple-darwin": ["@rules_rust//rust/platform:x86_64-apple-darwin"], + "x86_64-apple-ios": ["@rules_rust//rust/platform:x86_64-apple-ios"], + "x86_64-apple-ios-macabi": ["@rules_rust//rust/platform:x86_64-apple-ios-macabi"], + "x86_64-linux-android": ["@rules_rust//rust/platform:x86_64-linux-android"], + "x86_64-pc-windows-msvc": ["@rules_rust//rust/platform:x86_64-pc-windows-msvc"], + "x86_64-unknown-freebsd": ["@rules_rust//rust/platform:x86_64-unknown-freebsd"], + "x86_64-unknown-fuchsia": ["@rules_rust//rust/platform:x86_64-unknown-fuchsia"], + "x86_64-unknown-linux-gnu": ["@rules_rust//rust/platform:x86_64-unknown-linux-gnu"], + "x86_64-unknown-nixos-gnu": ["@rules_rust//rust/platform:x86_64-unknown-nixos-gnu"], + "x86_64-unknown-none": ["@rules_rust//rust/platform:x86_64-unknown-none"], + "x86_64-unknown-uefi": ["@rules_rust//rust/platform:x86_64-unknown-uefi"], +} diff --git a/third_party/crates/defs.bzl b/third_party/crates/defs.bzl new file mode 100644 index 0000000..0b7adb2 --- /dev/null +++ b/third_party/crates/defs.bzl @@ -0,0 +1,23 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//third_party:vendor_crates +############################################################################### +"""Deprecated: re-exports the crate_universe macros from `:crates.bzl`.""" + +load( + ":crates.bzl", + _aliases = "aliases", + _all_crate_deps = "all_crate_deps", + _crate_deps = "crate_deps", + _crate_edition = "crate_edition", + _crate_repositories = "crate_repositories", +) + +aliases = _aliases +all_crate_deps = _all_crate_deps +crate_deps = _crate_deps +crate_edition = _crate_edition +crate_repositories = _crate_repositories -- 2.47.3 From 5917ceecad117d01c00256d11c96a6a6c5ff57f8 Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 31 Aug 2026 18:42:15 -0400 Subject: [PATCH 2/5] build: remove unused anyhow dependency --- Cargo.lock | 9 - src/machoke/BUILD | 1 - src/machoke/Cargo.toml | 1 - src/machoke/lib.rs | 6 +- src/machoke/main.rs | 5 +- third_party/crates/BUILD.bazel | 13 - .../anyhow-1.0.104/.cargo-checksum.json | 1 - .../anyhow-1.0.104/.cargo_vcs_info.json | 6 - .../crates/anyhow-1.0.104/.github/FUNDING.yml | 1 - .../anyhow-1.0.104/.github/workflows/ci.yml | 146 --- third_party/crates/anyhow-1.0.104/BUILD.bazel | 187 --- third_party/crates/anyhow-1.0.104/Cargo.lock | 355 ------ third_party/crates/anyhow-1.0.104/Cargo.toml | 129 -- .../crates/anyhow-1.0.104/Cargo.toml.orig | 36 - .../crates/anyhow-1.0.104/LICENSE-APACHE | 176 --- third_party/crates/anyhow-1.0.104/LICENSE-MIT | 23 - third_party/crates/anyhow-1.0.104/README.md | 179 --- third_party/crates/anyhow-1.0.104/build.rs | 194 --- .../crates/anyhow-1.0.104/rust-toolchain.toml | 2 - .../crates/anyhow-1.0.104/src/backtrace.rs | 48 - .../crates/anyhow-1.0.104/src/chain.rs | 102 -- .../crates/anyhow-1.0.104/src/context.rs | 193 --- .../crates/anyhow-1.0.104/src/ensure.rs | 935 --------------- .../crates/anyhow-1.0.104/src/error.rs | 1060 ----------------- third_party/crates/anyhow-1.0.104/src/fmt.rs | 158 --- third_party/crates/anyhow-1.0.104/src/kind.rs | 121 -- third_party/crates/anyhow-1.0.104/src/lib.rs | 728 ----------- .../crates/anyhow-1.0.104/src/macros.rs | 245 ---- .../crates/anyhow-1.0.104/src/nightly.rs | 58 - third_party/crates/anyhow-1.0.104/src/ptr.rs | 187 --- .../crates/anyhow-1.0.104/src/wrapper.rs | 84 -- .../crates/anyhow-1.0.104/tests/common/mod.rs | 14 - .../anyhow-1.0.104/tests/compiletest.rs | 7 - .../crates/anyhow-1.0.104/tests/drop/mod.rs | 53 - .../anyhow-1.0.104/tests/test_autotrait.rs | 34 - .../anyhow-1.0.104/tests/test_backtrace.rs | 15 - .../crates/anyhow-1.0.104/tests/test_boxed.rs | 45 - .../crates/anyhow-1.0.104/tests/test_chain.rs | 69 -- .../anyhow-1.0.104/tests/test_context.rs | 195 --- .../anyhow-1.0.104/tests/test_convert.rs | 46 - .../anyhow-1.0.104/tests/test_downcast.rs | 123 -- .../anyhow-1.0.104/tests/test_ensure.rs | 756 ------------ .../crates/anyhow-1.0.104/tests/test_ffi.rs | 19 - .../crates/anyhow-1.0.104/tests/test_fmt.rs | 93 -- .../anyhow-1.0.104/tests/test_macros.rs | 97 -- .../crates/anyhow-1.0.104/tests/test_repr.rs | 30 - .../anyhow-1.0.104/tests/test_source.rs | 62 - .../tests/ui/chained-comparison.rs | 8 - .../tests/ui/chained-comparison.stderr | 10 - .../anyhow-1.0.104/tests/ui/empty-ensure.rs | 6 - .../tests/ui/empty-ensure.stderr | 12 - .../anyhow-1.0.104/tests/ui/ensure-nonbool.rs | 40 - .../tests/ui/ensure-nonbool.stderr | 113 -- .../anyhow-1.0.104/tests/ui/must-use.rs | 11 - .../anyhow-1.0.104/tests/ui/must-use.stderr | 15 - .../crates/anyhow-1.0.104/tests/ui/no-impl.rs | 8 - .../anyhow-1.0.104/tests/ui/no-impl.stderr | 32 - .../tests/ui/temporary-value.rs | 5 - .../tests/ui/temporary-value.stderr | 15 - .../tests/ui/wrong-interpolation.rs | 5 - .../tests/ui/wrong-interpolation.stderr | 5 - third_party/crates/crates.bzl | 5 - 62 files changed, 3 insertions(+), 7334 deletions(-) delete mode 100644 third_party/crates/anyhow-1.0.104/.cargo-checksum.json delete mode 100644 third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json delete mode 100644 third_party/crates/anyhow-1.0.104/.github/FUNDING.yml delete mode 100644 third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml delete mode 100644 third_party/crates/anyhow-1.0.104/BUILD.bazel delete mode 100644 third_party/crates/anyhow-1.0.104/Cargo.lock delete mode 100644 third_party/crates/anyhow-1.0.104/Cargo.toml delete mode 100644 third_party/crates/anyhow-1.0.104/Cargo.toml.orig delete mode 100644 third_party/crates/anyhow-1.0.104/LICENSE-APACHE delete mode 100644 third_party/crates/anyhow-1.0.104/LICENSE-MIT delete mode 100644 third_party/crates/anyhow-1.0.104/README.md delete mode 100644 third_party/crates/anyhow-1.0.104/build.rs delete mode 100644 third_party/crates/anyhow-1.0.104/rust-toolchain.toml delete mode 100644 third_party/crates/anyhow-1.0.104/src/backtrace.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/chain.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/context.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/ensure.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/error.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/fmt.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/kind.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/lib.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/macros.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/nightly.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/ptr.rs delete mode 100644 third_party/crates/anyhow-1.0.104/src/wrapper.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/common/mod.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/compiletest.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/drop/mod.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_boxed.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_chain.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_context.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_convert.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_downcast.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_ensure.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_ffi.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_fmt.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_macros.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_repr.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/test_source.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs delete mode 100644 third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr diff --git a/Cargo.lock b/Cargo.lock index f17f601..34a6f13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anyhow" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" - [[package]] name = "machoke" version = "0.1.0" -dependencies = [ - "anyhow", -] diff --git a/src/machoke/BUILD b/src/machoke/BUILD index aebba41..5d0806d 100644 --- a/src/machoke/BUILD +++ b/src/machoke/BUILD @@ -4,7 +4,6 @@ rust_library( name = "machoke_lib", crate_name = "machoke", srcs = ["lib.rs"], - deps = ["//third_party/crates:anyhow"], ) rust_binary( diff --git a/src/machoke/Cargo.toml b/src/machoke/Cargo.toml index 184663e..1beb8f9 100644 --- a/src/machoke/Cargo.toml +++ b/src/machoke/Cargo.toml @@ -11,4 +11,3 @@ name = "machoke" path = "main.rs" [dependencies] -anyhow = "1" diff --git a/src/machoke/lib.rs b/src/machoke/lib.rs index a91f24e..33a6292 100644 --- a/src/machoke/lib.rs +++ b/src/machoke/lib.rs @@ -1,5 +1,3 @@ -use anyhow::Result; - -pub fn greeting() -> Result<&'static str> { - Ok("Hello from machoke") +pub fn greeting() -> &'static str { + "Hello from machoke" } diff --git a/src/machoke/main.rs b/src/machoke/main.rs index 7c52bab..ddac719 100644 --- a/src/machoke/main.rs +++ b/src/machoke/main.rs @@ -1,6 +1,3 @@ fn main() { - println!( - "{}", - machoke::greeting().expect("greeting should be available") - ); + println!("{}", machoke::greeting()); } diff --git a/third_party/crates/BUILD.bazel b/third_party/crates/BUILD.bazel index 54eaec5..ae6a71a 100644 --- a/third_party/crates/BUILD.bazel +++ b/third_party/crates/BUILD.bazel @@ -29,16 +29,3 @@ filegroup( allow_empty = True, ), ) - -# Workspace Member Dependencies -alias( - name = "anyhow-1.0.104", - actual = "//third_party/crates/anyhow-1.0.104:anyhow", - tags = ["manual"], -) - -alias( - name = "anyhow", - actual = "//third_party/crates/anyhow-1.0.104:anyhow", - tags = ["manual"], -) diff --git a/third_party/crates/anyhow-1.0.104/.cargo-checksum.json b/third_party/crates/anyhow-1.0.104/.cargo-checksum.json deleted file mode 100644 index 51b4065..0000000 --- a/third_party/crates/anyhow-1.0.104/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"9f5691d9965b8418415cfe8872a667089542a23a1d746bad08476ccda5e6269c",".github/FUNDING.yml":"b017158736b3c9751a2d21edfce7fe61c8954e2fced8da8dd3013c2f3e295bd9",".github/workflows/ci.yml":"40e9434834e8ba84207ef6a401da6b154fa4220a4847230284d6aae63d8a39ac","Cargo.lock":"c7b6dd9adcad0b26ce812afdb8539e1d93994a0735a90eb0dd7ce8535e3e7ffa","Cargo.toml":"249789761ff37004dda628765f0c9e60a61fa43cbbd2d364789dca0c789eeb59","Cargo.toml.orig":"1b03bd9d21f63835f0449cf1456e6143a15efd6b7803bc5b7787643db62b6f53","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"86f5b88c45b2b9b7eefa0ad66c11918a607319cad683f01123ff38db68b4a49b","build.rs":"89d1baedcff59822ed692d3a33f131c211a213bdec33c83f68b54110d9c64223","rust-toolchain.toml":"6bbb61302978c736b2da03e4fb40e3beab908f85d533ab46fd541e637b5f3e0f","src/backtrace.rs":"621ec5d9e2f31883d0384ae00fc536d1ea359da989d2e0d1be1ba03482c8f920","src/chain.rs":"85af447405f075633fab186b7f1c94d7f33a36474f239c50a961b2d6197d5426","src/context.rs":"8b106e43df7a66fbc3e85b87a4d7f8a780d43d3ee0cd1ae86c571950ecf07d13","src/ensure.rs":"709524741c8f9365e01cb36fc2349a8724513de02cf9e253809a93af8d6a7b6e","src/error.rs":"2a78ee4e5f8d6b4476c761f77473362b9ed12f5402e4701001e7d04d628ba030","src/fmt.rs":"2cca8c7f3cab636fdb17433ca2b1fda0e8d28bb20d4647b87c991dacd8f06cdf","src/kind.rs":"ddcabf15b3b47a4ef16ed361c45cc0cc82e7be90622995ff6c04b3fec78bb04f","src/lib.rs":"ea7f436f6bf4b356ff30ec922b50b40ead0ade28b123341a8de7f310311fd44c","src/macros.rs":"696e6a8aac614525a29697aedc7561e98beccf3d43aed3ada1cc93daa99da8ba","src/nightly.rs":"1c0aeadfcdbe22f8f807b185dec1a7448c378bddb37689714944b60473b58049","src/ptr.rs":"a114639d26f4feca7e186106342334cdf2e2176f892149aa331ace72e5d81410","src/wrapper.rs":"079218e1d8c9374f52311b1c7971f7fbdeba4d7af1b0749c0d535010f1232697","tests/common/mod.rs":"f9088c2d7afafa64ff730b629272045b776bfafc2f5957508242da630635f2e1","tests/compiletest.rs":"4e381aa8ca3eabb7ac14d1e0c3700b3223e47640547a6988cfa13ad68255f60f","tests/drop/mod.rs":"08c3e553c1cc0d2dbd936fc45f4b5b1105057186affd6865e8d261e05f0f0646","tests/test_autotrait.rs":"ba9bc18416115cb48fd08675a3e7fc89584de7926dad6b2be6645dc13d5931df","tests/test_backtrace.rs":"60afdd7ee5850dc22625ff486fe41c47fd322db874a93c4871ddfed2bf603930","tests/test_boxed.rs":"6b26db0e2eb72afe9af7352ea820837aab90f8d486294616dd5dc34c1b94038c","tests/test_chain.rs":"3a8a8d7569913bd98c0e27c69d0bda35101e7fde7c056ed57cdd8ed018e4cbcb","tests/test_context.rs":"a4cb7d9a6d488d902eb5ac516d2b5e4135f46caaa2d151580ed9ba83c2a90b57","tests/test_convert.rs":"7e7a8b4772a427a911014ac4d1083f9519000e786177f898808980dd9bdfde61","tests/test_downcast.rs":"797e69a72d125758c4c4897e5dc776d549d52cc9a6a633e0a33193f588a62b88","tests/test_ensure.rs":"6ef8823153d6aba31dda8438b9e51984e6b7377d585addbaf87162b39d733cd9","tests/test_ffi.rs":"c6e6bf39e6b2cf9aacea12e3e4da4e1e1edb7fc906d231e5baf45812a08de3c4","tests/test_fmt.rs":"0e49b48f08e4faaf03e2f202e1efc5250018876c4e1b01b8379d7a38ae8df870","tests/test_macros.rs":"3eb6ec9024cf8812da48de35b733d5a69ed942907fb4e6c67ec471cd4bcef562","tests/test_repr.rs":"034dee888abd08741e11ac2e95ef4fcb2ab3943d0a76e8e976db404658e1a252","tests/test_source.rs":"b80723cf635a4f8c4df21891b34bfab9ed2b2aa407e7a2f826d24e334cd5f88e","tests/ui/chained-comparison.rs":"6504b03d95b5acc232a7f4defc9f343b2be6733bf475fa0992e8e6545b912bd4","tests/ui/chained-comparison.stderr":"7f1d0a8c251b0ede2d30b3087ec157fc660945c97a642c4a5acf5a14ec58de34","tests/ui/empty-ensure.rs":"ab5bf37c846a0d689f26ce9257a27228411ed64154f9c950f1602d88a355d94b","tests/ui/empty-ensure.stderr":"315782f5f4246290fe190e3767b22c3dcaffaabc19c5ace0373537d53e765278","tests/ui/ensure-nonbool.rs":"7e57cb93fbcd82959b36586ed6bd2ad978b051fe5facd5274651fde6b1600905","tests/ui/ensure-nonbool.stderr":"e3dfbaedd66fdfc524f8462305760c7978c4268ca7e1cd872d7ecde5d3b455bd","tests/ui/must-use.rs":"fb59860b43f673bf4a430a6036ba463e95028844d8dd4243cfe5ebc7f2be582f","tests/ui/must-use.stderr":"8b1cb7fca632396a22bb3a642f2df3ab62b3e9a87951e20fa40bdd548d002162","tests/ui/no-impl.rs":"fab6cbf2f6ea510b86f567dfb3b7c31250a9fd71ae5d110dbb9188be569ec593","tests/ui/no-impl.stderr":"c472de95483aa234728c7f57039c88fc3456892838329976a75cd167c3c172c9","tests/ui/temporary-value.rs":"4dcc96271b2403e6372cf4cfc813445e5ce4365fc6e156b6bc38274098499a70","tests/ui/temporary-value.stderr":"7f99cd914d2d423d77274e1b859b5ad151cde8224e42687e50622c26118fd47f","tests/ui/wrong-interpolation.rs":"9c44d4674c2dccd27b9dedd03341346ec02d993b41793ee89b5755202e7e367e","tests/ui/wrong-interpolation.stderr":"301e60e2eb9401782c7dc0b3580613a4cb2aafd4cc8065734a630a62e1161aa5"},"package":"330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"} \ No newline at end of file diff --git a/third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json b/third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json deleted file mode 100644 index 6d990c1..0000000 --- a/third_party/crates/anyhow-1.0.104/.cargo_vcs_info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "git": { - "sha1": "1dbe1862aae650423e3361fbd20b7d17c5109cc3" - }, - "path_in_vcs": "" -} \ No newline at end of file diff --git a/third_party/crates/anyhow-1.0.104/.github/FUNDING.yml b/third_party/crates/anyhow-1.0.104/.github/FUNDING.yml deleted file mode 100644 index 7507077..0000000 --- a/third_party/crates/anyhow-1.0.104/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -github: dtolnay diff --git a/third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml b/third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml deleted file mode 100644 index d4e05d2..0000000 --- a/third_party/crates/anyhow-1.0.104/.github/workflows/ci.yml +++ /dev/null @@ -1,146 +0,0 @@ -name: CI - -on: - push: - pull_request: - workflow_dispatch: - schedule: [cron: "40 1 * * *"] - -permissions: - contents: read - -env: - RUSTFLAGS: -Dwarnings - -jobs: - pre_ci: - uses: dtolnay/.github/.github/workflows/pre_ci.yml@master - - test: - name: Rust ${{matrix.rust}} - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - rust: [nightly, beta, stable, 1.85.0] - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{matrix.rust}} - components: rust-src - - name: Enable type layout randomization - run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV - if: matrix.rust == 'nightly' - - name: Enable nightly-only tests - run: echo RUSTFLAGS=${RUSTFLAGS}\ --cfg=anyhow_nightly_testing >> $GITHUB_ENV - if: matrix.rust == 'nightly' - - run: cargo test - - run: cargo check --no-default-features - - run: cargo check - - uses: actions/upload-artifact@v7 - if: matrix.rust == 'nightly' && always() - with: - name: Cargo.lock - path: Cargo.lock - continue-on-error: true - - build: - name: Rust ${{matrix.rust}} - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - rust: [1.68.0] - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{matrix.rust}} - components: rust-src - - run: cargo check --manifest-path tests/crate/Cargo.toml - - run: cargo check --manifest-path tests/crate/Cargo.toml --no-default-features - - minimal: - name: Minimal versions - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@nightly - - run: cargo generate-lockfile -Z minimal-versions - - run: cargo check --locked - - windows: - name: Windows - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: windows-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@stable - with: - components: rust-src - - run: cargo check - - doc: - name: Documentation - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - timeout-minutes: 45 - env: - RUSTDOCFLAGS: -Dwarnings - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@nightly - with: - components: rust-src - - uses: dtolnay/install@cargo-docs-rs - - run: cargo docs-rs - - clippy: - name: Clippy - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@nightly - with: - components: clippy, rust-src - - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic - - miri: - name: Miri - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@miri - - run: cargo miri setup - - run: cargo miri test - env: - MIRIFLAGS: -Zmiri-strict-provenance - - outdated: - name: Outdated - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' - timeout-minutes: 45 - steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@stable - - uses: dtolnay/install@cargo-outdated - - run: cargo outdated --workspace --exit-code 1 diff --git a/third_party/crates/anyhow-1.0.104/BUILD.bazel b/third_party/crates/anyhow-1.0.104/BUILD.bazel deleted file mode 100644 index 3b4d8af..0000000 --- a/third_party/crates/anyhow-1.0.104/BUILD.bazel +++ /dev/null @@ -1,187 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//third_party:vendor_crates -############################################################################### - -load( - "@rules_rust//cargo:defs.bzl", - "cargo_build_script", - "cargo_toml_env_vars", -) -load("@rules_rust//rust:defs.bzl", "rust_library") - -package(default_visibility = ["//visibility:public"]) - -cargo_toml_env_vars( - name = "cargo_toml_env_vars", - src = "Cargo.toml", -) - -rust_library( - name = "anyhow", - srcs = glob( - include = ["**/*.rs"], - allow_empty = False, - ), - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_features = [ - "default", - "std", - ], - crate_root = "src/lib.rs", - edition = "2021", - rustc_env_files = [ - ":cargo_toml_env_vars", - ], - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-bazel", - "crate-name=anyhow", - "manual", - "noclippy", - "norustfmt", - ], - target_compatible_with = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [], - "@rules_rust//rust/platform:aarch64-apple-ios": [], - "@rules_rust//rust/platform:aarch64-apple-ios-macabi": [], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], - "@rules_rust//rust/platform:aarch64-linux-android": [], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-none": [], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], - "@rules_rust//rust/platform:aarch64-unknown-uefi": [], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:arm-unknown-linux-musleabi": [], - "@rules_rust//rust/platform:armv7-linux-androideabi": [], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:i686-apple-darwin": [], - "@rules_rust//rust/platform:i686-linux-android": [], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [], - "@rules_rust//rust/platform:i686-unknown-freebsd": [], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], - "@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:mips-unknown-linux-gnu": [], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], - "@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:sparc64-unknown-netbsd": [], - "@rules_rust//rust/platform:sparc64-unknown-openbsd": [], - "@rules_rust//rust/platform:thumbv6m-none-eabi": [], - "@rules_rust//rust/platform:thumbv7em-none-eabi": [], - "@rules_rust//rust/platform:thumbv7em-none-eabihf": [], - "@rules_rust//rust/platform:thumbv7m-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [], - "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], - "@rules_rust//rust/platform:wasm32-unknown-unknown": [], - "@rules_rust//rust/platform:wasm32-wasip1": [], - "@rules_rust//rust/platform:wasm32-wasip1-threads": [], - "@rules_rust//rust/platform:wasm32-wasip2": [], - "@rules_rust//rust/platform:x86_64-apple-darwin": [], - "@rules_rust//rust/platform:x86_64-apple-ios": [], - "@rules_rust//rust/platform:x86_64-apple-ios-macabi": [], - "@rules_rust//rust/platform:x86_64-linux-android": [], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-none": [], - "@rules_rust//rust/platform:x86_64-unknown-uefi": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - version = "1.0.104", - deps = [ - ":build_script_build", - ], -) - -cargo_build_script( - name = "_bs", - srcs = glob( - include = ["**/*.rs"], - allow_empty = False, - ), - build_script_env_files = [ - ":cargo_toml_env_vars", - ], - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - "**/*.rs", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_features = [ - "default", - "std", - ], - crate_name = "build_script_build", - crate_root = "build.rs", - data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - edition = "2021", - emit_warnings = False, - pkg_name = "anyhow", - rustc_env_files = [ - ":cargo_toml_env_vars", - ], - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-bazel", - "crate-name=anyhow", - "manual", - "noclippy", - "norustfmt", - ], - version = "1.0.104", - visibility = ["//visibility:private"], -) - -alias( - name = "build_script_build", - actual = ":_bs", - tags = ["manual"], -) diff --git a/third_party/crates/anyhow-1.0.104/Cargo.lock b/third_party/crates/anyhow-1.0.104/Cargo.lock deleted file mode 100644 index e0d301e..0000000 --- a/third_party/crates/anyhow-1.0.104/Cargo.lock +++ /dev/null @@ -1,355 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.104" -dependencies = [ - "futures", - "rustversion", - "syn 3.0.0", - "thiserror", - "trybuild", -] - -[[package]] -name = "dissimilar" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeda16ab4059c5fd2a83f2b9c9e9c981327b18aa8e3b313f7e6563799d4f093e" - -[[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - -[[package]] -name = "futures" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a88cf1f829d945f548cf8fec32c61b1f202b6d93b45848602fc02af4b12ad218" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "262590f4fe6afeb0bc83be1daa64e52657fe185690a958af7f3ad0e92085c5ae" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7" - -[[package]] -name = "futures-io" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4577ecaa3c4f96589d473f679a71b596316f6641bc350038b962a5daf0085d7a" - -[[package]] -name = "futures-sink" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e34418ac499d6305c2fb5ad0ed2f6ac998c5f8ca209b4510f7f94242c647e307" - -[[package]] -name = "futures-task" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109" - -[[package]] -name = "futures-util" -version = "0.3.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa" -dependencies = [ - "futures-core", - "futures-sink", - "futures-task", - "pin-project-lite", -] - -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - -[[package]] -name = "hashbrown" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" - -[[package]] -name = "indexmap" -version = "2.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "itoa" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" - -[[package]] -name = "memchr" -version = "2.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" - -[[package]] -name = "pin-project-lite" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" - -[[package]] -name = "proc-macro2" -version = "1.0.106" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustversion" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" - -[[package]] -name = "serde" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" -dependencies = [ - "serde_core", -] - -[[package]] -name = "serde_core" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "serde_json" -version = "1.0.150" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" -dependencies = [ - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", -] - -[[package]] -name = "serde_spanned" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" -dependencies = [ - "serde_core", -] - -[[package]] -name = "syn" -version = "2.0.119" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fac314a64dc9a36e61a9eb4261a5e9bbfbc922b27e518af97bc32b926cf967" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "target-triple" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a6bfce3d99adfa72d24750a61f782f3036a81e7f86d8841ee1326deaebd171" - -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "toml" -version = "1.1.3+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c" -dependencies = [ - "indexmap", - "serde_core", - "serde_spanned", - "toml_datetime", - "toml_parser", - "toml_writer", - "winnow", -] - -[[package]] -name = "toml_datetime" -version = "1.1.1+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" -dependencies = [ - "serde_core", -] - -[[package]] -name = "toml_parser" -version = "1.1.2+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" -dependencies = [ - "winnow", -] - -[[package]] -name = "toml_writer" -version = "1.1.2+spec-1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" - -[[package]] -name = "trybuild" -version = "1.0.118" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06649c6f63d86604ba0c8950d5a1829fc9a17afd70fc6629f481d75b6a624c78" -dependencies = [ - "dissimilar", - "glob", - "serde", - "serde_derive", - "serde_json", - "target-triple", - "termcolor", - "toml", -] - -[[package]] -name = "unicode-ident" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" - -[[package]] -name = "winapi-util" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "winnow" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" - -[[package]] -name = "zmij" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/third_party/crates/anyhow-1.0.104/Cargo.toml b/third_party/crates/anyhow-1.0.104/Cargo.toml deleted file mode 100644 index d0b23cc..0000000 --- a/third_party/crates/anyhow-1.0.104/Cargo.toml +++ /dev/null @@ -1,129 +0,0 @@ -# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# 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. -# -# 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 = "2021" -rust-version = "1.68" -name = "anyhow" -version = "1.0.104" -authors = ["David Tolnay "] -build = "build.rs" -autolib = false -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "Flexible concrete Error type built on std::error::Error" -documentation = "https://docs.rs/anyhow" -readme = "README.md" -keywords = [ - "error", - "error-handling", -] -categories = [ - "rust-patterns", - "no-std", -] -license = "MIT OR Apache-2.0" -repository = "https://github.com/dtolnay/anyhow" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = [ - "--generate-link-to-definition", - "--generate-macro-expansion", - "--extern-html-root-url=core=https://doc.rust-lang.org", - "--extern-html-root-url=alloc=https://doc.rust-lang.org", - "--extern-html-root-url=std=https://doc.rust-lang.org", -] - -[features] -backtrace = [] -default = ["std"] -std = [] - -[lib] -name = "anyhow" -path = "src/lib.rs" - -[[test]] -name = "compiletest" -path = "tests/compiletest.rs" - -[[test]] -name = "test_autotrait" -path = "tests/test_autotrait.rs" - -[[test]] -name = "test_backtrace" -path = "tests/test_backtrace.rs" - -[[test]] -name = "test_boxed" -path = "tests/test_boxed.rs" - -[[test]] -name = "test_chain" -path = "tests/test_chain.rs" - -[[test]] -name = "test_context" -path = "tests/test_context.rs" - -[[test]] -name = "test_convert" -path = "tests/test_convert.rs" - -[[test]] -name = "test_downcast" -path = "tests/test_downcast.rs" - -[[test]] -name = "test_ensure" -path = "tests/test_ensure.rs" - -[[test]] -name = "test_ffi" -path = "tests/test_ffi.rs" - -[[test]] -name = "test_fmt" -path = "tests/test_fmt.rs" - -[[test]] -name = "test_macros" -path = "tests/test_macros.rs" - -[[test]] -name = "test_repr" -path = "tests/test_repr.rs" - -[[test]] -name = "test_source" -path = "tests/test_source.rs" - -[dev-dependencies.futures] -version = "0.3" -default-features = false - -[dev-dependencies.rustversion] -version = "1.0.6" - -[dev-dependencies.syn] -version = "3" -features = ["full"] - -[dev-dependencies.thiserror] -version = "2" - -[dev-dependencies.trybuild] -version = "1.0.108" -features = ["diff"] diff --git a/third_party/crates/anyhow-1.0.104/Cargo.toml.orig b/third_party/crates/anyhow-1.0.104/Cargo.toml.orig deleted file mode 100644 index 37cdeb7..0000000 --- a/third_party/crates/anyhow-1.0.104/Cargo.toml.orig +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "anyhow" -version = "1.0.104" -authors = ["David Tolnay "] -categories = ["rust-patterns", "no-std"] -description = "Flexible concrete Error type built on std::error::Error" -documentation = "https://docs.rs/anyhow" -edition = "2021" -keywords = ["error", "error-handling"] -license = "MIT OR Apache-2.0" -repository = "https://github.com/dtolnay/anyhow" -rust-version = "1.68" - -[features] -default = ["std"] -std = [] -# THIS HAS NO EFFECT. This feature remains to preserve compatibility with the -# old `backtrace` optional dependency that this crate used to have. -backtrace = [] - -[dev-dependencies] -futures = { version = "0.3", default-features = false } -rustversion = "1.0.6" -syn = { version = "3", features = ["full"] } -thiserror = "2" -trybuild = { version = "1.0.108", features = ["diff"] } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = [ - "--generate-link-to-definition", - "--generate-macro-expansion", - "--extern-html-root-url=core=https://doc.rust-lang.org", - "--extern-html-root-url=alloc=https://doc.rust-lang.org", - "--extern-html-root-url=std=https://doc.rust-lang.org", -] diff --git a/third_party/crates/anyhow-1.0.104/LICENSE-APACHE b/third_party/crates/anyhow-1.0.104/LICENSE-APACHE deleted file mode 100644 index 1b5ec8b..0000000 --- a/third_party/crates/anyhow-1.0.104/LICENSE-APACHE +++ /dev/null @@ -1,176 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS diff --git a/third_party/crates/anyhow-1.0.104/LICENSE-MIT b/third_party/crates/anyhow-1.0.104/LICENSE-MIT deleted file mode 100644 index 31aa793..0000000 --- a/third_party/crates/anyhow-1.0.104/LICENSE-MIT +++ /dev/null @@ -1,23 +0,0 @@ -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/third_party/crates/anyhow-1.0.104/README.md b/third_party/crates/anyhow-1.0.104/README.md deleted file mode 100644 index 78225bb..0000000 --- a/third_party/crates/anyhow-1.0.104/README.md +++ /dev/null @@ -1,179 +0,0 @@ -Anyhow ¯\\\_(°ペ)\_/¯ -========================== - -[github](https://github.com/dtolnay/anyhow) -[crates.io](https://crates.io/crates/anyhow) -[docs.rs](https://docs.rs/anyhow) -[build status](https://github.com/dtolnay/anyhow/actions?query=branch%3Amaster) - -This library provides [`anyhow::Error`][Error], a trait object based error type -for easy idiomatic error handling in Rust applications. - -[Error]: https://docs.rs/anyhow/1.0/anyhow/struct.Error.html - -```toml -[dependencies] -anyhow = "1.0" -``` - -
- -## Details - -- Use `Result`, or equivalently `anyhow::Result`, as the - return type of any fallible function. - - Within the function, use `?` to easily propagate any error that implements the - [`std::error::Error`] trait. - - ```rust - use anyhow::Result; - - fn get_cluster_info() -> Result { - let config = std::fs::read_to_string("cluster.json")?; - let map: ClusterMap = serde_json::from_str(&config)?; - Ok(map) - } - ``` - - [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html - -- Attach context to help the person troubleshooting the error understand where - things went wrong. A low-level error like "No such file or directory" can be - annoying to debug without more context about what higher level step the - application was in the middle of. - - ```rust - use anyhow::{Context, Result}; - - fn main() -> Result<()> { - ... - it.detach().context("Failed to detach the important thing")?; - - let content = std::fs::read(path) - .with_context(|| format!("Failed to read instrs from {}", path))?; - ... - } - ``` - - ```console - Error: Failed to read instrs from ./path/to/instrs.json - - Caused by: - No such file or directory (os error 2) - ``` - -- Downcasting is supported and can be by value, by shared reference, or by - mutable reference as needed. - - ```rust - // If the error was caused by redaction, then return a - // tombstone instead of the content. - match root_cause.downcast_ref::() { - Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), - None => Err(error), - } - ``` - -- 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`; - - 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 - but you can write the impls yourself or use a standalone macro like - [thiserror]. - - ```rust - use thiserror::Error; - - #[derive(Error, Debug)] - pub enum FormatError { - #[error("Invalid header (expected {expected:?}, got {found:?})")] - InvalidHeader { - expected: String, - found: String, - }, - #[error("Missing attribute: {0}")] - MissingAttribute(String), - } - ``` - -- One-off error messages can be constructed using the `anyhow!` macro, which - supports string interpolation and produces an `anyhow::Error`. - - ```rust - return Err(anyhow!("Missing attribute: {}", missing)); - ``` - - A `bail!` macro is provided as a shorthand for the same early return. - - ```rust - bail!("Missing attribute: {}", missing); - ``` - -
- -## No-std support - -In no_std mode, almost all of the same API is available and works the same way. -To depend on Anyhow in no_std mode, disable our default enabled "std" feature in -Cargo.toml. A global allocator is required. - -```toml -[dependencies] -anyhow = { version = "1.0", default-features = false } -``` - -With versions of Rust older than 1.81, no_std mode may require an additional -`.map_err(Error::msg)` when working with a non-Anyhow error type inside a -function that returns Anyhow's error type, as the trait that `?`-based error -conversions are defined by is only available in std in those old versions. - -
- -## Comparison to failure - -The `anyhow::Error` type works something like `failure::Error`, but unlike -failure ours is built around the standard library's `std::error::Error` trait -rather than a separate trait `failure::Fail`. The standard library has adopted -the necessary improvements for this to be possible as part of [RFC 2504]. - -[RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md - -
- -## Comparison to thiserror - -Use Anyhow if you don't care what error type your functions return, you just -want it to be easy. This is common in application code. Use [thiserror] if you -are a library that wants to design your own dedicated error type(s) so that on -failures the caller gets exactly the information that you choose. - -[thiserror]: https://github.com/dtolnay/thiserror - -
- -#### License - - -Licensed under either of Apache License, Version -2.0 or MIT license at your option. - - -
- - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in this crate by you, as defined in the Apache-2.0 license, shall -be dual licensed as above, without any additional terms or conditions. - diff --git a/third_party/crates/anyhow-1.0.104/build.rs b/third_party/crates/anyhow-1.0.104/build.rs deleted file mode 100644 index f4fbc94..0000000 --- a/third_party/crates/anyhow-1.0.104/build.rs +++ /dev/null @@ -1,194 +0,0 @@ -#![allow(clippy::uninlined_format_args)] - -use std::env; -use std::ffi::OsString; -use std::fs; -use std::io::ErrorKind; -use std::iter; -use std::path::Path; -use std::process::{self, Command, Stdio}; -use std::str; - -fn main() { - if cfg!(feature = "std") { - println!("cargo:rerun-if-changed=src/nightly.rs"); - - let error_generic_member_access; - let consider_rustc_bootstrap; - if compile_probe(false) { - // This is a nightly or dev compiler, so it supports unstable - // features regardless of RUSTC_BOOTSTRAP. No need to rerun build - // script if RUSTC_BOOTSTRAP is changed. - error_generic_member_access = true; - consider_rustc_bootstrap = false; - } else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") { - if compile_probe(true) { - // This is a stable or beta compiler for which the user has set - // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build - // script if they change it. - error_generic_member_access = true; - consider_rustc_bootstrap = true; - } else if rustc_bootstrap == "1" { - // This compiler does not support the generic member access API - // in the form that anyhow expects. No need to pay attention to - // RUSTC_BOOTSTRAP. - error_generic_member_access = false; - consider_rustc_bootstrap = false; - } else { - // This is a stable or beta compiler for which RUSTC_BOOTSTRAP - // is set to restrict the use of unstable features by this - // crate. - error_generic_member_access = false; - consider_rustc_bootstrap = true; - } - } else { - // Without RUSTC_BOOTSTRAP, this compiler does not support the - // generic member access API in the form that anyhow expects, but - // try again if the user turns on unstable features. - error_generic_member_access = false; - consider_rustc_bootstrap = true; - } - - if error_generic_member_access { - println!("cargo:rustc-cfg=error_generic_member_access"); - } - - if consider_rustc_bootstrap { - println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP"); - } - } - - let Some(rustc) = rustc_minor_version() else { - return; - }; - - if rustc >= 80 { - println!("cargo:rustc-check-cfg=cfg(anyhow_build_probe)"); - println!("cargo:rustc-check-cfg=cfg(anyhow_nightly_testing)"); - println!("cargo:rustc-check-cfg=cfg(anyhow_no_clippy_format_args)"); - println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_error)"); - println!("cargo:rustc-check-cfg=cfg(error_generic_member_access)"); - } - - if rustc < 81 { - // core::error::Error - // https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror - println!("cargo:rustc-cfg=anyhow_no_core_error"); - } - - if rustc < 85 { - // #[clippy::format_args] - // https://doc.rust-lang.org/1.85.1/clippy/attribs.html#clippyformat_args - println!("cargo:rustc-cfg=anyhow_no_clippy_format_args"); - } -} - -fn compile_probe(rustc_bootstrap: bool) -> bool { - if env::var_os("RUSTC_STAGE").is_some() { - // We are running inside rustc bootstrap. This is a highly non-standard - // environment with issues such as: - // - // https://github.com/rust-lang/cargo/issues/11138 - // https://github.com/rust-lang/rust/issues/114839 - // - // Let's just not use nightly features here. - return false; - } - - let rustc = cargo_env_var("RUSTC"); - let out_dir = cargo_env_var("OUT_DIR"); - let out_subdir = Path::new(&out_dir).join("probe"); - let probefile = Path::new("src").join("nightly.rs"); - - if let Err(err) = fs::create_dir(&out_subdir) { - if err.kind() != ErrorKind::AlreadyExists { - eprintln!("Failed to create {}: {}", out_subdir.display(), err); - process::exit(1); - } - } - - let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty()); - let rustc_workspace_wrapper = - env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty()); - let mut rustc = rustc_wrapper - .into_iter() - .chain(rustc_workspace_wrapper) - .chain(iter::once(rustc)); - let mut cmd = Command::new(rustc.next().unwrap()); - cmd.args(rustc); - - if !rustc_bootstrap { - cmd.env_remove("RUSTC_BOOTSTRAP"); - } - - cmd.stderr(Stdio::null()) - .arg("--cfg=anyhow_build_probe") - .arg("--edition=2018") - .arg("--crate-name=anyhow") - .arg("--crate-type=lib") - .arg("--cap-lints=allow") - .arg("--emit=dep-info,metadata") - .arg("--out-dir") - .arg(&out_subdir) - .arg(probefile); - - if let Some(target) = env::var_os("TARGET") { - cmd.arg("--target").arg(target); - } - - // 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); - } - } - } - - let success = match cmd.status() { - Ok(status) => status.success(), - Err(_) => false, - }; - - // Clean up to avoid leaving nondeterministic absolute paths in the dep-info - // file in OUT_DIR, which causes nonreproducible builds in build systems - // that treat the entire OUT_DIR as an artifact. - if let Err(err) = fs::remove_dir_all(&out_subdir) { - // libc::ENOTEMPTY - // Some filesystems (NFSv3) have timing issues under load where '.nfs*' - // dummy files can continue to get created for a short period after the - // probe command completes, breaking remove_dir_all. - // To be replaced with ErrorKind::DirectoryNotEmpty (Rust 1.83+). - const ENOTEMPTY: i32 = 39; - - if !(err.kind() == ErrorKind::NotFound - || (cfg!(target_os = "linux") && err.raw_os_error() == Some(ENOTEMPTY))) - { - eprintln!("Failed to clean up {}: {}", out_subdir.display(), err); - process::exit(1); - } - } - - success -} - -fn rustc_minor_version() -> Option { - let rustc = cargo_env_var("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() -} - -fn cargo_env_var(key: &str) -> OsString { - env::var_os(key).unwrap_or_else(|| { - eprintln!( - "Environment variable ${} is not set during execution of build script", - key, - ); - process::exit(1); - }) -} diff --git a/third_party/crates/anyhow-1.0.104/rust-toolchain.toml b/third_party/crates/anyhow-1.0.104/rust-toolchain.toml deleted file mode 100644 index 20fe888..0000000 --- a/third_party/crates/anyhow-1.0.104/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -components = ["rust-src"] diff --git a/third_party/crates/anyhow-1.0.104/src/backtrace.rs b/third_party/crates/anyhow-1.0.104/src/backtrace.rs deleted file mode 100644 index d9ae520..0000000 --- a/third_party/crates/anyhow-1.0.104/src/backtrace.rs +++ /dev/null @@ -1,48 +0,0 @@ -#[cfg(feature = "std")] -pub(crate) use std::backtrace::Backtrace; - -#[cfg(not(feature = "std"))] -pub(crate) enum Backtrace {} - -#[cfg(feature = "std")] -macro_rules! backtrace { - () => { - Some(std::backtrace::Backtrace::capture()) - }; -} - -#[cfg(not(feature = "std"))] -macro_rules! backtrace { - () => { - None - }; -} - -#[cfg(error_generic_member_access)] -macro_rules! backtrace_if_absent { - ($err:expr) => { - match $crate::nightly::request_ref_backtrace($err as &dyn core::error::Error) { - Some(_) => None, - None => backtrace!(), - } - }; -} - -#[cfg(all(not(error_generic_member_access), feature = "std"))] -macro_rules! backtrace_if_absent { - ($err:expr) => { - backtrace!() - }; -} - -#[cfg(all(not(anyhow_no_core_error), not(feature = "std")))] -macro_rules! backtrace_if_absent { - ($err:expr) => { - None - }; -} - -fn _assert_send_sync() { - fn assert() {} - assert::(); -} diff --git a/third_party/crates/anyhow-1.0.104/src/chain.rs b/third_party/crates/anyhow-1.0.104/src/chain.rs deleted file mode 100644 index e56bc66..0000000 --- a/third_party/crates/anyhow-1.0.104/src/chain.rs +++ /dev/null @@ -1,102 +0,0 @@ -use self::ChainState::*; -use crate::StdError; - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -use alloc::vec::{self, Vec}; - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -pub(crate) use crate::Chain; - -#[cfg(all(not(feature = "std"), anyhow_no_core_error))] -pub(crate) struct Chain<'a> { - state: ChainState<'a>, -} - -#[derive(Clone)] -pub(crate) enum ChainState<'a> { - Linked { - next: Option<&'a (dyn StdError + 'static)>, - }, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - Buffered { - rest: vec::IntoIter<&'a (dyn StdError + 'static)>, - }, -} - -impl<'a> Chain<'a> { - #[cold] - pub fn new(head: &'a (dyn StdError + 'static)) -> Self { - Chain { - state: ChainState::Linked { next: Some(head) }, - } - } -} - -impl<'a> Iterator for Chain<'a> { - type Item = &'a (dyn StdError + 'static); - - fn next(&mut self) -> Option { - match &mut self.state { - Linked { next } => { - let error = (*next)?; - *next = error.source(); - Some(error) - } - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - Buffered { rest } => rest.next(), - } - } - - fn size_hint(&self) -> (usize, Option) { - let len = self.len(); - (len, Some(len)) - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl DoubleEndedIterator for Chain<'_> { - fn next_back(&mut self) -> Option { - match &mut self.state { - Linked { mut next } => { - let mut rest = Vec::new(); - while let Some(cause) = next { - next = cause.source(); - rest.push(cause); - } - let mut rest = rest.into_iter(); - let last = rest.next_back(); - self.state = Buffered { rest }; - last - } - Buffered { rest } => rest.next_back(), - } - } -} - -impl ExactSizeIterator for Chain<'_> { - fn len(&self) -> usize { - match &self.state { - Linked { mut next } => { - let mut len = 0; - while let Some(cause) = next { - next = cause.source(); - len += 1; - } - len - } - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - Buffered { rest } => rest.len(), - } - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl Default for Chain<'_> { - fn default() -> Self { - Chain { - state: ChainState::Buffered { - rest: Vec::new().into_iter(), - }, - } - } -} diff --git a/third_party/crates/anyhow-1.0.104/src/context.rs b/third_party/crates/anyhow-1.0.104/src/context.rs deleted file mode 100644 index 52e6ab6..0000000 --- a/third_party/crates/anyhow-1.0.104/src/context.rs +++ /dev/null @@ -1,193 +0,0 @@ -use crate::error::ContextError; -use crate::{Context, Error, StdError}; -use core::convert::Infallible; -use core::fmt::{self, Debug, Display, Write}; - -#[cfg(error_generic_member_access)] -use crate::nightly::{self, Request}; - -mod ext { - use super::*; - - pub trait StdError { - fn ext_context(self, context: C) -> Error - where - C: Display + Send + Sync + 'static; - } - - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - impl StdError for E - where - E: crate::StdError + Send + Sync + 'static, - { - fn ext_context(self, context: C) -> Error - where - C: Display + Send + Sync + 'static, - { - let backtrace = backtrace_if_absent!(&self); - Error::construct_from_context(context, self, backtrace) - } - } - - impl StdError for Error { - fn ext_context(self, context: C) -> Error - where - C: Display + Send + Sync + 'static, - { - self.context(context) - } - } -} - -impl Context for Result -where - E: ext::StdError + Send + Sync + 'static, -{ - fn context(self, context: C) -> Result - where - C: Display + Send + Sync + 'static, - { - // Not using map_err to save 2 useless frames off the captured backtrace - // in ext_context. - match self { - Ok(ok) => Ok(ok), - Err(error) => Err(error.ext_context(context)), - } - } - - fn with_context(self, context: F) -> Result - where - C: Display + Send + Sync + 'static, - F: FnOnce() -> C, - { - match self { - Ok(ok) => Ok(ok), - Err(error) => Err(error.ext_context(context())), - } - } -} - -/// ``` -/// # type T = (); -/// # -/// use anyhow::{Context, Result}; -/// -/// fn maybe_get() -> Option { -/// # const IGNORE: &str = stringify! { -/// ... -/// # }; -/// # unimplemented!() -/// } -/// -/// fn demo() -> Result<()> { -/// let t = maybe_get().context("there is no T")?; -/// # const IGNORE: &str = stringify! { -/// ... -/// # }; -/// # unimplemented!() -/// } -/// ``` -impl Context for Option { - fn context(self, context: C) -> Result - where - C: Display + Send + Sync + 'static, - { - // Not using ok_or_else to save 2 useless frames off the captured - // backtrace. - match self { - Some(ok) => Ok(ok), - None => Err(Error::construct_from_display(context, backtrace!())), - } - } - - fn with_context(self, context: F) -> Result - where - C: Display + Send + Sync + 'static, - F: FnOnce() -> C, - { - match self { - Some(ok) => Ok(ok), - None => Err(Error::construct_from_display(context(), backtrace!())), - } - } -} - -impl Debug for ContextError -where - C: Display, - E: Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Error") - .field("context", &Quoted(&self.context)) - .field("source", &self.error) - .finish() - } -} - -impl Display for ContextError -where - C: Display, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.context, f) - } -} - -impl StdError for ContextError -where - C: Display, - E: StdError + 'static, -{ - fn source(&self) -> Option<&(dyn StdError + 'static)> { - Some(&self.error) - } - - #[cfg(error_generic_member_access)] - fn provide<'a>(&'a self, request: &mut Request<'a>) { - nightly::provide(&self.error, request); - } -} - -impl StdError for ContextError -where - C: Display, -{ - fn source(&self) -> Option<&(dyn StdError + 'static)> { - Some(unsafe { crate::ErrorImpl::error(self.error.inner.by_ref()) }) - } - - #[cfg(error_generic_member_access)] - fn provide<'a>(&'a self, request: &mut Request<'a>) { - Error::provide(&self.error, request); - } -} - -struct Quoted(C); - -impl Debug for Quoted -where - C: Display, -{ - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_char('"')?; - Quoted(&mut *formatter).write_fmt(format_args!("{}", self.0))?; - formatter.write_char('"')?; - Ok(()) - } -} - -impl Write for Quoted<&mut fmt::Formatter<'_>> { - fn write_str(&mut self, s: &str) -> fmt::Result { - Display::fmt(&s.escape_debug(), self.0) - } -} - -pub(crate) mod private { - use super::*; - - pub trait Sealed {} - - impl Sealed for Result where E: ext::StdError {} - impl Sealed for Option {} -} diff --git a/third_party/crates/anyhow-1.0.104/src/ensure.rs b/third_party/crates/anyhow-1.0.104/src/ensure.rs deleted file mode 100644 index 795757d..0000000 --- a/third_party/crates/anyhow-1.0.104/src/ensure.rs +++ /dev/null @@ -1,935 +0,0 @@ -use crate::Error; -use alloc::string::String; -use core::fmt::{self, Debug, Write}; -use core::mem::MaybeUninit; -use core::ptr; -use core::slice; -use core::str; - -#[doc(hidden)] -pub trait BothDebug { - fn __dispatch_ensure(self, msg: &'static str) -> Error; -} - -impl BothDebug for (A, B) -where - A: Debug, - B: Debug, -{ - fn __dispatch_ensure(self, msg: &'static str) -> Error { - render(msg, &self.0, &self.1) - } -} - -#[doc(hidden)] -pub trait NotBothDebug { - fn __dispatch_ensure(self, msg: &'static str) -> Error; -} - -impl NotBothDebug for &(A, B) { - fn __dispatch_ensure(self, msg: &'static str) -> Error { - Error::msg(msg) - } -} - -struct Buf { - bytes: [MaybeUninit; 40], - written: usize, -} - -impl Buf { - fn new() -> Self { - Buf { - bytes: [MaybeUninit::uninit(); 40], - written: 0, - } - } - - fn as_str(&self) -> &str { - unsafe { - str::from_utf8_unchecked(slice::from_raw_parts( - self.bytes.as_ptr().cast::(), - self.written, - )) - } - } -} - -impl Write for Buf { - fn write_str(&mut self, s: &str) -> fmt::Result { - if s.bytes().any(|b| b == b' ' || b == b'\n') { - return Err(fmt::Error); - } - - let remaining = self.bytes.len() - self.written; - if s.len() > remaining { - return Err(fmt::Error); - } - - unsafe { - ptr::copy_nonoverlapping( - s.as_ptr(), - self.bytes.as_mut_ptr().add(self.written).cast::(), - s.len(), - ); - } - self.written += s.len(); - Ok(()) - } -} - -fn render(msg: &'static str, lhs: &dyn Debug, rhs: &dyn Debug) -> Error { - let mut lhs_buf = Buf::new(); - if fmt::write(&mut lhs_buf, format_args!("{:?}", lhs)).is_ok() { - let mut rhs_buf = Buf::new(); - if fmt::write(&mut rhs_buf, format_args!("{:?}", rhs)).is_ok() { - let lhs_str = lhs_buf.as_str(); - let rhs_str = rhs_buf.as_str(); - // "{msg} ({lhs} vs {rhs})" - let len = msg.len() + 2 + lhs_str.len() + 4 + rhs_str.len() + 1; - let mut string = String::with_capacity(len); - string.push_str(msg); - string.push_str(" ("); - string.push_str(lhs_str); - string.push_str(" vs "); - string.push_str(rhs_str); - string.push(')'); - return Error::msg(string); - } - } - Error::msg(msg) -} - -#[doc(hidden)] -#[macro_export] -macro_rules! __parse_ensure { - (atom () $bail:tt $fuel:tt {($($rhs:tt)+) ($($lhs:tt)+) $op:tt} $dup:tt $(,)?) => { - $crate::__fancy_ensure!($($lhs)+, $op, $($rhs)+) - }; - - // low precedence control flow constructs - - (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt return $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt break $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt continue $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt yield $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (0 $stack:tt ($($bail:tt)*) $fuel:tt $parse:tt $dup:tt move $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - // unary operators - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($deref:tt $($dup:tt)*) * $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $deref) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($not:tt $($dup:tt)*) ! $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $not) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($neg:tt $($dup:tt)*) - $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $neg) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($let:tt $($dup:tt)*) let $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $let) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($lifetime:tt $colon:tt $($dup:tt)*) $label:lifetime : $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $lifetime $colon) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) &mut $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $raw:tt $mut:tt $($dup:tt)*) &raw mut $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $raw $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $raw:tt $const:tt $($dup:tt)*) &raw const $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and $raw $const) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $mut:tt $($dup:tt)*) &&mut $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $raw:tt $mut:tt $($dup:tt)*) &&raw mut $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $raw $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $raw:tt $const:tt $($dup:tt)*) &&raw const $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand $raw $const) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $($dup:tt)*) && $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $andand) $($parse)*} ($($rest)*) $($rest)*) - }; - - // control flow constructs - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($if:tt $($dup:tt)*) if $($rest:tt)*) => { - $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $if) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($match:tt $($dup:tt)*) match $($rest:tt)*) => { - $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $match) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($while:tt $($dup:tt)*) while $($rest:tt)*) => { - $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $while) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($for:tt $($dup:tt)*) for $($rest:tt)*) => { - $crate::__parse_ensure!(pat (cond $stack) $bail ($($fuel)*) {($($buf)* $for) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom (cond $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($block:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(cond $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) - }; - - (cond $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($else:tt $if:tt $($dup:tt)*) else if $($rest:tt)*) => { - $crate::__parse_ensure!(0 (cond $stack) $bail ($($fuel)*) {($($buf)* $else $if) $($parse)*} ($($rest)*) $($rest)*) - }; - - (cond $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($else:tt $brace:tt $($dup:tt)*) else {$($block:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $else $brace) $($parse)*} ($($rest)*) $($rest)*) - }; - - (cond $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - // atomic expressions - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($content:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($array:tt)*] $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($block:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($loop:tt $block:tt $($dup:tt)*) loop {$($body:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $loop $block) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($async:tt $block:tt $($dup:tt)*) async {$($body:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $async $block) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($async:tt $move:tt $block:tt $($dup:tt)*) async move {$($body:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $async $move $block) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($unsafe:tt $block:tt $($dup:tt)*) unsafe {$($body:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $unsafe $block) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($const:tt $block:tt $($dup:tt)*) const {$($body:tt)*} $($rest:tt)*) => { - // TODO: this is mostly useless due to https://github.com/rust-lang/rust/issues/86730 - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $const $block) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($literal:tt $($dup:tt)*) $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $literal) $($parse)*} ($($rest)*) $($rest)*) - }; - - // path expressions - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(epath (atom $stack) $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ident:tt $($dup:tt)*) $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(epath (atom $stack) $bail ($($fuel)*) {($($buf)* $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (epath (atom $stack))) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: < $($rest:tt)*) => { - $crate::__parse_ensure!(generic (epath $stack) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: << $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (tpath (arglist (epath $stack)))) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt :: <- - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $larrow:tt $($dup:tt)*) :: <- $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(generic (epath $stack) $bail ($($fuel)*) {($($buf)* $colons $larrow) $($parse)*} ($($dup)*) $($dup)*) - }; - - (epath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(epath $stack $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! ($($mac:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! [$($mac:tt)*] $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! {$($mac:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) - }; - - (epath (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - (epath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - // trailer expressions - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($call:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($index:tt)*] $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($init:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($question:tt $($dup:tt)*) ? $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $question) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $ident:tt $colons:tt $langle:tt $($dup:tt)*) . $i:ident :: < $($rest:tt)*) => { - $crate::__parse_ensure!(generic (atom $stack) $bail ($($fuel)*) {($($buf)* $dot $ident $colons $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $ident:tt $colons:tt $langle:tt $($dup:tt)*) . $i:ident :: << $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (tpath (arglist (atom $stack)))) $bail ($($fuel)*) {($($buf)* $dot $ident $colons $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt . $i:ident :: <- - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $ident:tt $colons:tt $larrow:tt $($dup:tt)*) . $i:ident :: <- $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(generic (atom $stack) $bail ($($fuel)*) {($($buf)* $dot $ident $colons $larrow) $($parse)*} ($($dup)*) $($dup)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $field:tt $($dup:tt)*) . $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $dot $field) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt . - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dot:tt $index:tt $($dup:tt)*) . $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $dot $index) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($as:tt $($dup:tt)*) as $($rest:tt)*) => { - $crate::__parse_ensure!(type (atom $stack) $bail ($($fuel)*) {($($buf)* $as) $($parse)*} ($($rest)*) $($rest)*) - }; - - // types - - (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($content:tt)*] $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($content:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($star:tt $const:tt $($dup:tt)*) *const $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $star $const) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($star:tt $mut:tt $($dup:tt)*) *mut $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $star $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $mut:tt $($dup:tt)*) & $l:lifetime mut $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) & mut $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $($dup:tt)*) & $l:lifetime $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $mut:tt $($dup:tt)*) && $l:lifetime mut $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $mut:tt $($dup:tt)*) && mut $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $lifetime:tt $($dup:tt)*) && $l:lifetime $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and $lifetime) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) && $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt unsafe extern - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($unsafe:tt $(extern $($abi:literal)?)? fn $($dup:tt)*) unsafe $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $unsafe) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt extern - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($extern:tt $abi:tt fn $($dup:tt)*) extern $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $extern $abi) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($extern:tt fn $($dup:tt)*) extern $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $extern) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($fn:tt $paren:tt $arrow:tt $($dup:tt)*) fn ($($args:tt)*) -> $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $fn $paren $arrow) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($fn:tt $paren:tt $($dup:tt)*) fn ($($args:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $fn $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($impl:tt $($dup:tt)*) impl $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $impl) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($dyn:tt $($dup:tt)*) dyn $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $dyn) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($wild:tt $($dup:tt)*) _ $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $wild) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($never:tt $($dup:tt)*) ! $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $never) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($for:tt $langle:tt $($dup:tt)*) for < $($rest:tt)*) => { - $crate::__parse_ensure!(generic (type $stack) $bail ($($fuel)*) {($($buf)* $for $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - // path types - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(tpath $stack $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ident:tt $($dup:tt)*) $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(tpath $stack $bail ($($fuel)*) {($($buf)* $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (type $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (tpath $stack)) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { - $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) << $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (tpath (arglist (tpath $stack)))) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt <- - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($larrow:tt $($dup:tt)*) <- $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $larrow) $($parse)*} ($($dup)*) $($dup)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: < $($rest:tt)*) => { - $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $langle:tt $($dup:tt)*) :: << $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (tpath (arglist (tpath $stack)))) $bail ($($fuel)*) {($($buf)* $colons $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt :: <- - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $larrow:tt $($dup:tt)*) :: <- $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(generic (tpath $stack) $bail ($($fuel)*) {($($buf)* $colons $larrow) $($parse)*} ($($dup)*) $($dup)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(tpath $stack $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $arrow:tt $($dup:tt)*) ($($args:tt)*) -> $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $paren $arrow) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($args:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!(object $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $paren:tt $arrow:tt $($dup:tt)*) :: ($($args:tt)*) -> $($rest:tt)*) => { - $crate::__parse_ensure!(type $stack $bail ($($fuel)*) {($($buf)* $colons $paren $arrow) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $paren:tt $($dup:tt)*) :: ($($args:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!(object $stack $bail ($($fuel)*) {($($buf)* $colons $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! ($($mac:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! [$($mac:tt)*] $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bang:tt $args:tt $($dup:tt)*) ! {$($mac:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $bang $args) $($parse)*} ($($rest)*) $($rest)*) - }; - - (tpath $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!(object $stack $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - // qualified paths - - (qpath (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $colons:tt $ident:tt $($dup:tt)*) >> :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (qpath ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $colons:tt $ident:tt $($dup:tt)*) > :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (qpath $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($as:tt $($dup:tt)*) as $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath $stack) $bail ($($fuel)*) {($($buf)* $as) $($parse)*} ($($rest)*) $($rest)*) - }; - - // trait objects - - (object (arglist $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($plus:tt $colons:tt $ident:tt $($dup:tt)*) + :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(tpath (arglist $stack) $bail ($($fuel)*) {($($buf)* $plus $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (object (arglist $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($plus:tt $ident:tt $($dup:tt)*) + $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(tpath (arglist $stack) $bail ($($fuel)*) {($($buf)* $plus $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (object (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - (object ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - // angle bracketed generic arguments - - (generic (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (generic ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) > $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (generic ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { - $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) {($($buf)*) $($parse)*} ($rangle $($rest)*) $rangle $($rest)*) - }; - - (generic $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($neg:tt $($dup:tt)*) - $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(generic $stack $bail ($($fuel)*) {($($buf)* $neg) $($parse)*} ($($dup)*) $($dup)*) - }; - - (generic $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($literal:tt $($dup:tt)*) $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $literal) $($parse)*} ($($rest)*) $($rest)*) - }; - - (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($block:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) - }; - - (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($lifetime:tt $($dup:tt)*) $l:lifetime $($rest:tt)*) => { - $crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $lifetime) $($parse)*} ($($rest)*) $($rest)*) - }; - - (generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($assoc:tt $eq:tt $($dup:tt)*) $ident:ident = $($rest:tt)*) => { - $crate::__parse_ensure!(type (arglist $stack) $bail ($($fuel)*) {($($buf)* $assoc $eq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (generic $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => { - $crate::__parse_ensure!(type (arglist $stack) $bail ($($fuel)*) $parse $dup $($rest)*) - }; - - (arglist $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($comma:tt $($dup:tt)*) , $($rest:tt)*) => { - $crate::__parse_ensure!(generic $stack $bail ($($fuel)*) {($($buf)* $comma) $($parse)*} ($($rest)*) $($rest)*) - }; - - (arglist (split ($pop:ident $stack:tt)) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)*) $rangle $($parse)*} ($($rest)*) $($rest)*) - }; - - (arglist ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) > $($rest:tt)*) => { - $crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (arglist ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { - $crate::__parse_ensure!($pop (split $stack) $bail ($($fuel)*) {($($buf)*) $($parse)*} ($rangle $($rest)*) $rangle $($rest)*) - }; - - // patterns - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($pipe:tt $($dup:tt)*) | $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $pipe) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($eq:tt $($dup:tt)*) = $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $eq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($in:tt $($dup:tt)*) in $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $in) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ref:tt $($dup:tt)*) ref $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $ref) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($mut:tt $($dup:tt)*) mut $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $mut) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($at:tt $($dup:tt)*) @ $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $at) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($neg:tt $($dup:tt)*) - $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $neg) $($parse)*} ($($dup)*) $($dup)*) - }; - - (pat $stack:tt ($($bail:tt)*) (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt - $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($literal:tt $($dup:tt)*) $lit:literal $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $literal) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($range:tt $($dup:tt)*) .. $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $range) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($range:tt $($dup:tt)*) ..= $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $range) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) & $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($andand:tt $($dup:tt)*) && $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $andand) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($paren:tt $($dup:tt)*) ($($content:tt)*) $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $paren) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bracket:tt $($dup:tt)*) [$($content:tt)*] $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $bracket) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($brace:tt $($dup:tt)*) {$($content:tt)*} $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $brace) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($wild:tt $($dup:tt)*) _ $($rest:tt)*) => { - $crate::__parse_ensure!(pat $stack $bail ($($fuel)*) {($($buf)* $wild) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($colons:tt $ident:tt $($dup:tt)*) :: $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(epath (pat $stack) $bail ($($fuel)*) {($($buf)* $colons $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ident:tt $($dup:tt)*) $i:ident $($rest:tt)*) => { - $crate::__parse_ensure!(epath (pat $stack) $bail ($($fuel)*) {($($buf)* $ident) $($parse)*} ($($rest)*) $($rest)*) - }; - - (pat $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($langle:tt $($dup:tt)*) < $($rest:tt)*) => { - $crate::__parse_ensure!(type (qpath (epath (pat $stack))) $bail ($($fuel)*) {($($buf)* $langle) $($parse)*} ($($rest)*) $($rest)*) - }; - - // comparison binary operators - - (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($eq:tt $($dup:tt)*) == $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $eq} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($eq:tt $($dup:tt)*) == $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $eq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($le:tt $($dup:tt)*) <= $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $le} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($le:tt $($dup:tt)*) <= $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $le) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($lt:tt $($dup:tt)*) < $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $lt} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($lt:tt $($dup:tt)*) < $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $lt) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ne:tt $($dup:tt)*) != $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $ne} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($ne:tt $($dup:tt)*) != $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $ne) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($ge:tt $($dup:tt)*) >= $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $ge} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($ge:tt $($dup:tt)*) >= $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $ge) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom (split ()) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt >> $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)* > ) > } ($($rest)*) $($rest)*) - }; - - (atom () $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($gt:tt $($dup:tt)*) > $($rest:tt)*) => { - $crate::__parse_ensure!(0 () $bail ($($fuel)*) {() $($parse)* ($($buf)*) $gt} ($($rest)*) $($rest)*) - }; - - (atom (split $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($rangle:tt $($dup:tt)*) >> $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)+) $($parse:tt)*} ($gt:tt $($dup:tt)*) > $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $gt) $($parse)*} ($($rest)*) $($rest)*) - }; - - // high precedence binary operators - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($add:tt $($dup:tt)*) + $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $add) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($sub:tt $($dup:tt)*) - $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $sub) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($mul:tt $($dup:tt)*) * $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $mul) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($div:tt $($dup:tt)*) / $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $div) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($rem:tt $($dup:tt)*) % $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $rem) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitxor:tt $($dup:tt)*) ^ $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $bitxor) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitand:tt $($dup:tt)*) & $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $bitand) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitor:tt $($dup:tt)*) | $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $bitor) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shl:tt $($dup:tt)*) << $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $shl) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shr:tt $($dup:tt)*) >> $($rest:tt)*) => { - $crate::__parse_ensure!(0 $stack $bail ($($fuel)*) {($($buf)* $shr) $($parse)*} ($($rest)*) $($rest)*) - }; - - // low precedence binary operators - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($and:tt $($dup:tt)*) && $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $and) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($or:tt $($dup:tt)*) || $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $or) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($assign:tt $($dup:tt)*) = $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $assign) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($addeq:tt $($dup:tt)*) += $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $addeq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($subeq:tt $($dup:tt)*) -= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $subeq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($muleq:tt $($dup:tt)*) *= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $muleq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($diveq:tt $($dup:tt)*) /= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $diveq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($remeq:tt $($dup:tt)*) %= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $remeq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitxoreq:tt $($dup:tt)*) ^= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $bitxoreq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitandeq:tt $($dup:tt)*) &= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $bitandeq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($bitoreq:tt $($dup:tt)*) |= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $bitoreq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shleq:tt $($dup:tt)*) <<= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $shleq) $($parse)*} ($($rest)*) $($rest)*) - }; - - (atom ($($stack:tt)+) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($shreq:tt $($dup:tt)*) >>= $($rest:tt)*) => { - $crate::__parse_ensure!(0 ($($stack)*) $bail ($($fuel)*) {($($buf)* $shreq) $($parse)*} ($($rest)*) $($rest)*) - }; - - // unrecognized expression - - ($state:tt $stack:tt ($($bail:tt)*) $($rest:tt)*) => { - $crate::__fallback_ensure!($($bail)*) - }; -} - -#[doc(hidden)] -#[macro_export] -macro_rules! __fancy_ensure { - ($lhs:expr, $op:tt, $rhs:expr) => { - match (&$lhs, &$rhs) { - (lhs, rhs) => { - if !(lhs $op rhs) { - #[allow(unused_imports)] - use $crate::__private::{BothDebug, NotBothDebug}; - return Err((lhs, rhs).__dispatch_ensure( - $crate::__private::concat!( - "Condition failed: `", - $crate::__private::stringify!($lhs), - " ", - $crate::__private::stringify!($op), - " ", - $crate::__private::stringify!($rhs), - "`", - ), - )); - } - } - } - }; -} - -#[doc(hidden)] -#[macro_export] -macro_rules! __fallback_ensure { - ($cond:expr $(,)?) => { - if $crate::__private::not($cond) { - return $crate::__private::Err($crate::Error::msg( - $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`") - )); - } - }; - ($cond:expr, $msg:literal $(,)?) => { - if $crate::__private::not($cond) { - return $crate::__private::Err($crate::__anyhow!($msg)); - } - }; - ($cond:expr, $err:expr $(,)?) => { - if $crate::__private::not($cond) { - return $crate::__private::Err($crate::__anyhow!($err)); - } - }; - ($cond:expr, $fmt:expr, $($arg:tt)*) => { - if $crate::__private::not($cond) { - return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)); - } - }; -} diff --git a/third_party/crates/anyhow-1.0.104/src/error.rs b/third_party/crates/anyhow-1.0.104/src/error.rs deleted file mode 100644 index d97df8c..0000000 --- a/third_party/crates/anyhow-1.0.104/src/error.rs +++ /dev/null @@ -1,1060 +0,0 @@ -use crate::backtrace::Backtrace; -use crate::chain::Chain; -#[cfg(error_generic_member_access)] -use crate::nightly::{self, Request}; -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -use crate::ptr::Mut; -use crate::ptr::{Own, Ref}; -use crate::{Error, StdError}; -use alloc::boxed::Box; -use core::any::TypeId; -use core::fmt::{self, Debug, Display}; -use core::mem::ManuallyDrop; -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -use core::ops::{Deref, DerefMut}; -use core::panic::{RefUnwindSafe, UnwindSafe}; -use core::ptr; -use core::ptr::NonNull; - -impl Error { - /// Create a new error object from any error type. - /// - /// The error type must be threadsafe and `'static`, so that the `Error` - /// will be as well. - /// - /// If the error type does not provide a backtrace, a backtrace will be - /// created here to ensure that a backtrace exists. - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[cold] - #[must_use] - pub fn new(error: E) -> Self - where - E: StdError + Send + Sync + 'static, - { - let backtrace = backtrace_if_absent!(&error); - Error::construct_from_std(error, backtrace) - } - - /// Create a new error object from a printable error message. - /// - /// If the argument implements std::error::Error, prefer `Error::new` - /// instead which preserves the underlying error's cause chain and - /// backtrace. If the argument may or may not implement std::error::Error - /// now or in the future, use `anyhow!(err)` which handles either way - /// correctly. - /// - /// `Error::msg("...")` is equivalent to `anyhow!("...")` but occasionally - /// convenient in places where a function is preferable over a macro, such - /// as iterator or stream combinators: - /// - /// ``` - /// # mod ffi { - /// # pub struct Input; - /// # pub struct Output; - /// # pub async fn do_some_work(_: Input) -> Result { - /// # unimplemented!() - /// # } - /// # } - /// # - /// # use ffi::{Input, Output}; - /// # - /// use anyhow::{Error, Result}; - /// use futures::stream::{Stream, StreamExt, TryStreamExt}; - /// - /// async fn demo(stream: S) -> Result> - /// where - /// S: Stream, - /// { - /// stream - /// .then(ffi::do_some_work) // returns Result - /// .map_err(Error::msg) - /// .try_collect() - /// .await - /// } - /// ``` - #[cold] - #[must_use] - pub fn msg(message: M) -> Self - where - M: Display + Debug + Send + Sync + 'static, - { - Error::construct_from_adhoc(message, backtrace!()) - } - - /// Construct an error object from a type-erased standard library error. - /// - /// This is mostly useful for interop with other error libraries. - /// - /// # Example - /// - /// Here is a skeleton of a library that provides its own error abstraction. - /// The pair of `From` impls provide bidirectional support for `?` - /// conversion between `Report` and `anyhow::Error`. - /// - /// ``` - /// use std::error::Error as StdError; - /// - /// pub struct Report {/* ... */} - /// - /// impl From for Report - /// where - /// E: Into, - /// Result<(), E>: anyhow::Context<(), E>, - /// { - /// fn from(error: E) -> Self { - /// let anyhow_error: anyhow::Error = error.into(); - /// let boxed_error: Box = anyhow_error.into(); - /// Report::from_boxed(boxed_error) - /// } - /// } - /// - /// impl From for anyhow::Error { - /// fn from(report: Report) -> Self { - /// let boxed_error: Box = report.into_boxed(); - /// anyhow::Error::from_boxed(boxed_error) - /// } - /// } - /// - /// impl Report { - /// fn from_boxed(boxed_error: Box) -> Self { - /// todo!() - /// } - /// fn into_boxed(self) -> Box { - /// todo!() - /// } - /// } - /// - /// // Example usage: can use `?` in both directions. - /// fn a() -> anyhow::Result<()> { - /// b()?; - /// Ok(()) - /// } - /// fn b() -> Result<(), Report> { - /// a()?; - /// Ok(()) - /// } - /// ``` - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[cold] - #[must_use] - pub fn from_boxed(boxed_error: Box) -> Self { - let backtrace = backtrace_if_absent!(&*boxed_error); - Error::construct_from_boxed(boxed_error, backtrace) - } - - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[cold] - pub(crate) fn construct_from_std(error: E, backtrace: Option) -> Self - where - E: StdError + Send + Sync + 'static, - { - let vtable = &ErrorVTable { - object_drop: object_drop::, - object_ref: object_ref::, - object_boxed: object_boxed::, - object_reallocate_boxed: object_reallocate_boxed::, - object_downcast: object_downcast::, - object_drop_rest: object_drop_front::, - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: no_backtrace, - }; - - // Safety: passing vtable that operates on the right type E. - unsafe { Error::construct(error, vtable, backtrace) } - } - - #[cold] - pub(crate) fn construct_from_adhoc(message: M, backtrace: Option) -> Self - where - M: Display + Debug + Send + Sync + 'static, - { - use crate::wrapper::MessageError; - let error: MessageError = MessageError(message); - let vtable = &ErrorVTable { - object_drop: object_drop::>, - object_ref: object_ref::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_boxed: object_boxed::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_reallocate_boxed: object_reallocate_boxed::>, - object_downcast: object_downcast::, - object_drop_rest: object_drop_front::, - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: no_backtrace, - }; - - // Safety: MessageError is repr(transparent) so it is okay for the - // vtable to allow casting the MessageError to M. - unsafe { Error::construct(error, vtable, backtrace) } - } - - #[cold] - pub(crate) fn construct_from_display(message: M, backtrace: Option) -> Self - where - M: Display + Send + Sync + 'static, - { - use crate::wrapper::DisplayError; - let error: DisplayError = DisplayError(message); - let vtable = &ErrorVTable { - object_drop: object_drop::>, - object_ref: object_ref::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_boxed: object_boxed::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_reallocate_boxed: object_reallocate_boxed::>, - object_downcast: object_downcast::, - object_drop_rest: object_drop_front::, - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: no_backtrace, - }; - - // Safety: DisplayError is repr(transparent) so it is okay for the - // vtable to allow casting the DisplayError to M. - unsafe { Error::construct(error, vtable, backtrace) } - } - - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[cold] - pub(crate) fn construct_from_context( - context: C, - error: E, - backtrace: Option, - ) -> Self - where - C: Display + Send + Sync + 'static, - E: StdError + Send + Sync + 'static, - { - let error: ContextError = ContextError { context, error }; - - let vtable = &ErrorVTable { - object_drop: object_drop::>, - object_ref: object_ref::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_boxed: object_boxed::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_reallocate_boxed: object_reallocate_boxed::>, - object_downcast: context_downcast::, - object_drop_rest: context_drop_rest::, - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: no_backtrace, - }; - - // Safety: passing vtable that operates on the right type. - unsafe { Error::construct(error, vtable, backtrace) } - } - - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[cold] - pub(crate) fn construct_from_boxed( - error: Box, - backtrace: Option, - ) -> Self { - use crate::wrapper::BoxedError; - let error = BoxedError(error); - let vtable = &ErrorVTable { - object_drop: object_drop::, - object_ref: object_ref::, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_boxed: object_boxed::, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_reallocate_boxed: object_reallocate_boxed::, - object_downcast: object_downcast::>, - object_drop_rest: object_drop_front::>, - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: no_backtrace, - }; - - // Safety: BoxedError is repr(transparent) so it is okay for the vtable - // to allow casting to Box. - unsafe { Error::construct(error, vtable, backtrace) } - } - - // Takes backtrace as argument rather than capturing it here so that the - // user sees one fewer layer of wrapping noise in the backtrace. - // - // Unsafe because the given vtable must have sensible behavior on the error - // value of type E. - #[cold] - unsafe fn construct( - error: E, - vtable: &'static ErrorVTable, - backtrace: Option, - ) -> Self - where - E: StdError + Send + Sync + 'static, - { - let inner: Box> = Box::new(ErrorImpl { - vtable, - backtrace, - _object: error, - }); - // Erase the concrete type of E from the compile-time type system. This - // is equivalent to the safe unsize coercion from Box> to - // Box> except that the - // result is a thin pointer. The necessary behavior for manipulating the - // underlying ErrorImpl is preserved in the vtable provided by the - // caller rather than a builtin fat pointer vtable. - let inner = Own::new(inner).cast::(); - Error { inner } - } - - /// Wrap the error value with additional context. - /// - /// For attaching context to a `Result` as it is propagated, the - /// [`Context`][crate::Context] extension trait may be more convenient than - /// this function. - /// - /// The primary reason to use `error.context(...)` instead of - /// `result.context(...)` via the `Context` trait would be if the context - /// needs to depend on some data held by the underlying error: - /// - /// ``` - /// # use std::fmt::{self, Debug, Display}; - /// # - /// # type T = (); - /// # - /// # impl std::error::Error for ParseError {} - /// # impl Debug for ParseError { - /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - /// # unimplemented!() - /// # } - /// # } - /// # impl Display for ParseError { - /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - /// # unimplemented!() - /// # } - /// # } - /// # - /// use anyhow::Result; - /// use std::fs::File; - /// use std::path::Path; - /// - /// struct ParseError { - /// line: usize, - /// column: usize, - /// } - /// - /// fn parse_impl(file: File) -> Result { - /// # const IGNORE: &str = stringify! { - /// ... - /// # }; - /// # unimplemented!() - /// } - /// - /// pub fn parse(path: impl AsRef) -> Result { - /// let file = File::open(&path)?; - /// parse_impl(file).map_err(|error| { - /// let context = format!( - /// "only the first {} lines of {} are valid", - /// error.line, path.as_ref().display(), - /// ); - /// anyhow::Error::new(error).context(context) - /// }) - /// } - /// ``` - #[cold] - #[must_use] - pub fn context(self, context: C) -> Self - where - C: Display + Send + Sync + 'static, - { - let error: ContextError = ContextError { - context, - error: self, - }; - - let vtable = &ErrorVTable { - object_drop: object_drop::>, - object_ref: object_ref::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_boxed: object_boxed::>, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_reallocate_boxed: object_reallocate_boxed::>, - object_downcast: context_chain_downcast::, - object_drop_rest: context_chain_drop_rest::, - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: context_backtrace::, - }; - - // As the cause is anyhow::Error, we already have a backtrace for it. - let backtrace = None; - - // Safety: passing vtable that operates on the right type. - unsafe { Error::construct(error, vtable, backtrace) } - } - - /// Get the backtrace for this Error. - /// - /// 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`. - /// - /// # Stability - /// - /// 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 return type of this - /// function on old compilers is `&(impl Debug + Display)`. - /// - /// ```toml - /// [dependencies] - /// anyhow = { version = "1.0", features = ["backtrace"] } - /// ``` - #[cfg(feature = "std")] - pub fn backtrace(&self) -> &Backtrace { - unsafe { ErrorImpl::backtrace(self.inner.by_ref()) } - } - - /// An iterator of the chain of source errors contained by this Error. - /// - /// This iterator will visit every error in the cause chain of this error - /// object, beginning with the error that this error object was created - /// from. - /// - /// # Example - /// - /// ``` - /// use anyhow::Error; - /// use std::io; - /// - /// pub fn underlying_io_error_kind(error: &Error) -> Option { - /// for cause in error.chain() { - /// if let Some(io_error) = cause.downcast_ref::() { - /// return Some(io_error.kind()); - /// } - /// } - /// None - /// } - /// ``` - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[cold] - pub fn chain(&self) -> Chain { - unsafe { ErrorImpl::chain(self.inner.by_ref()) } - } - - /// The lowest level cause of this error — this error's cause's - /// cause's cause etc. - /// - /// The root cause is the last error in the iterator produced by - /// [`chain()`][Error::chain]. - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[allow(clippy::double_ended_iterator_last)] - pub fn root_cause(&self) -> &(dyn StdError + 'static) { - self.chain().last().unwrap() - } - - /// Returns true if `E` is the type held by this error object. - /// - /// For errors with context, this method returns true if `E` matches the - /// type of the context `C` **or** the type of the error on which the - /// context has been attached. For details about the interaction between - /// context and downcasting, [see here]. - /// - /// [see here]: crate::Context#effect-on-downcasting - pub fn is(&self) -> bool - where - E: Display + Debug + Send + Sync + 'static, - { - self.downcast_ref::().is_some() - } - - /// Attempt to downcast the error object to a concrete type. - pub fn downcast(mut self) -> Result - where - E: Display + Debug + Send + Sync + 'static, - { - let target = TypeId::of::(); - let inner = self.inner.by_mut(); - unsafe { - // Use vtable to find NonNull<()> which points to a value of type E - // somewhere inside the data structure. - let addr = match (vtable(inner.ptr).object_downcast)(inner.by_ref(), target) { - Some(addr) => addr.by_mut().extend(), - None => return Err(self), - }; - - // Prepare to read E out of the data structure. We'll drop the rest - // of the data structure separately so that E is not dropped. - let outer = ManuallyDrop::new(self); - - // Read E from where the vtable found it. - let error = addr.cast::().read(); - - // Drop rest of the data structure outside of E. - (vtable(outer.inner.ptr).object_drop_rest)(outer.inner, target); - - Ok(error) - } - } - - /// Downcast this error object by reference. - /// - /// # Example - /// - /// ``` - /// # use anyhow::anyhow; - /// # use std::fmt::{self, Display}; - /// # use std::task::Poll; - /// # - /// # #[derive(Debug)] - /// # enum DataStoreError { - /// # Censored(()), - /// # } - /// # - /// # impl Display for DataStoreError { - /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - /// # unimplemented!() - /// # } - /// # } - /// # - /// # impl std::error::Error for DataStoreError {} - /// # - /// # const REDACTED_CONTENT: () = (); - /// # - /// # let error = anyhow!("..."); - /// # let root_cause = &error; - /// # - /// # let ret = - /// // If the error was caused by redaction, then return a tombstone instead - /// // of the content. - /// match root_cause.downcast_ref::() { - /// Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), - /// None => Err(error), - /// } - /// # ; - /// ``` - pub fn downcast_ref(&self) -> Option<&E> - where - E: Display + Debug + Send + Sync + 'static, - { - let target = TypeId::of::(); - unsafe { - // Use vtable to find NonNull<()> which points to a value of type E - // somewhere inside the data structure. - let addr = (vtable(self.inner.ptr).object_downcast)(self.inner.by_ref(), target)?; - Some(addr.cast::().deref()) - } - } - - /// Downcast this error object by mutable reference. - pub fn downcast_mut(&mut self) -> Option<&mut E> - where - E: Display + Debug + Send + Sync + 'static, - { - let target = TypeId::of::(); - unsafe { - // Use vtable to find NonNull<()> which points to a value of type E - // somewhere inside the data structure. - let addr = - (vtable(self.inner.ptr).object_downcast)(self.inner.by_ref(), target)?.by_mut(); - Some(addr.cast::().deref_mut()) - } - } - - /// Convert to a standard library error trait object. - /// - /// This is implemented as a cheap pointer cast that does not allocate or - /// deallocate memory. Like [`anyhow::Error::from_boxed`], it's useful for - /// interop with other error libraries. - /// - /// The same conversion is also available as - /// impl From<anyhow::Error> - /// for Box<dyn Error + Send + Sync + 'static>. - /// - /// If a backtrace was collected during construction of the `anyhow::Error`, - /// that backtrace remains accessible using the standard library `Error` - /// trait's provider API, but as a consequence, the resulting boxed error - /// can no longer be downcast to its original underlying type. - /// - /// ``` - #[cfg_attr(not(error_generic_member_access), doc = "# _ = stringify! {")] - /// #![feature(error_generic_member_access)] - /// - /// use anyhow::anyhow; - /// use std::backtrace::Backtrace; - /// use thiserror::Error; - /// - /// #[derive(Error, Debug)] - /// #[error("...")] - /// struct MyError; - /// - /// let anyhow_error = anyhow!(MyError); - /// println!("{}", anyhow_error.backtrace()); // has Backtrace - /// assert!(anyhow_error.downcast_ref::().is_some()); // can downcast - /// - /// let boxed_dyn_error = anyhow_error.into_boxed_dyn_error(); - /// assert!(std::error::request_ref::(&*boxed_dyn_error).is_some()); // has Backtrace - /// assert!(boxed_dyn_error.downcast_ref::().is_none()); // can no longer downcast - #[cfg_attr(not(error_generic_member_access), doc = "# };")] - /// ``` - /// - /// [`anyhow::Error::from_boxed`]: Self::from_boxed - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[must_use] - pub fn into_boxed_dyn_error(self) -> Box { - let outer = ManuallyDrop::new(self); - unsafe { - // Use vtable to attach ErrorImpl's native StdError vtable for - // the right original type E. - (vtable(outer.inner.ptr).object_boxed)(outer.inner) - } - } - - /// Convert to a standard library error trait object. - /// - /// Unlike `self.into_boxed_dyn_error()`, this method relocates the - /// underlying error into a new allocation in order to make it downcastable - /// to `&E` or `Box` for its original underlying error type. Any - /// backtrace collected during construction of the `anyhow::Error` is - /// discarded. - /// - /// ``` - #[cfg_attr(not(error_generic_member_access), doc = "# _ = stringify!{")] - /// #![feature(error_generic_member_access)] - /// - /// use anyhow::anyhow; - /// use std::backtrace::Backtrace; - /// use thiserror::Error; - /// - /// #[derive(Error, Debug)] - /// #[error("...")] - /// struct MyError; - /// - /// let anyhow_error = anyhow!(MyError); - /// println!("{}", anyhow_error.backtrace()); // has Backtrace - /// assert!(anyhow_error.downcast_ref::().is_some()); // can downcast - /// - /// let boxed_dyn_error = anyhow_error.reallocate_into_boxed_dyn_error_without_backtrace(); - /// assert!(std::error::request_ref::(&*boxed_dyn_error).is_none()); // Backtrace lost - /// assert!(boxed_dyn_error.downcast_ref::().is_some()); // can downcast to &MyError - /// assert!(boxed_dyn_error.downcast::().is_ok()); // can downcast to Box - #[cfg_attr(not(error_generic_member_access), doc = "# };")] - /// ``` - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[must_use] - pub fn reallocate_into_boxed_dyn_error_without_backtrace( - self, - ) -> Box { - let outer = ManuallyDrop::new(self); - unsafe { - // Use vtable to attach E's native StdError vtable for the right - // original type E. - (vtable(outer.inner.ptr).object_reallocate_boxed)(outer.inner) - } - } - - #[cfg(error_generic_member_access)] - pub(crate) fn provide<'a>(&'a self, request: &mut Request<'a>) { - unsafe { ErrorImpl::provide(self.inner.by_ref(), request) } - } - - // Called by thiserror when you have `#[source] anyhow::Error`. This provide - // implementation includes the anyhow::Error's Backtrace if any, unlike - // deref'ing to dyn Error where the provide implementation would include - // only the original error's Backtrace from before it got wrapped into an - // anyhow::Error. - #[cfg(error_generic_member_access)] - #[doc(hidden)] - pub fn thiserror_provide<'a>(&'a self, request: &mut Request<'a>) { - Self::provide(self, request); - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl From for Error -where - E: StdError + Send + Sync + 'static, -{ - #[cold] - fn from(error: E) -> Self { - let backtrace = backtrace_if_absent!(&error); - Error::construct_from_std(error, backtrace) - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl Deref for Error { - type Target = dyn StdError + Send + Sync + 'static; - - fn deref(&self) -> &Self::Target { - unsafe { ErrorImpl::error(self.inner.by_ref()) } - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl DerefMut for Error { - fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { ErrorImpl::error_mut(self.inner.by_mut()) } - } -} - -impl Display for Error { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - unsafe { ErrorImpl::display(self.inner.by_ref(), formatter) } - } -} - -impl Debug for Error { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - unsafe { ErrorImpl::debug(self.inner.by_ref(), formatter) } - } -} - -impl Drop for Error { - fn drop(&mut self) { - unsafe { - // Invoke the vtable's drop behavior. - (vtable(self.inner.ptr).object_drop)(self.inner); - } - } -} - -struct ErrorVTable { - object_drop: unsafe fn(Own), - object_ref: unsafe fn(Ref) -> Ref, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_boxed: unsafe fn(Own) -> Box, - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - object_reallocate_boxed: unsafe fn(Own) -> Box, - object_downcast: unsafe fn(Ref, TypeId) -> Option>, - object_drop_rest: unsafe fn(Own, TypeId), - #[cfg(all(not(error_generic_member_access), feature = "std"))] - object_backtrace: unsafe fn(Ref) -> Option<&Backtrace>, -} - -// Safety: requires layout of *e to match ErrorImpl. -unsafe fn object_drop(e: Own) { - // Cast back to ErrorImpl so that the allocator receives the correct - // Layout to deallocate the Box's memory. - let unerased_own = e.cast::>(); - drop(unsafe { unerased_own.boxed() }); -} - -// Safety: requires layout of *e to match ErrorImpl. -unsafe fn object_drop_front(e: Own, target: TypeId) { - // Drop the fields of ErrorImpl other than E as well as the Box allocation, - // without dropping E itself. This is used by downcast after doing a - // ptr::read to take ownership of the E. - let _ = target; - let unerased_own = e.cast::>>(); - drop(unsafe { unerased_own.boxed() }); -} - -// Safety: requires layout of *e to match ErrorImpl. -unsafe fn object_ref(e: Ref) -> Ref -where - E: StdError + Send + Sync + 'static, -{ - // Attach E's native StdError vtable onto a pointer to self._object. - let unerased_ref = e.cast::>(); - Ref::from_raw(unsafe { - NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut()) - }) -} - -// Safety: requires layout of *e to match ErrorImpl. -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -unsafe fn object_boxed(e: Own) -> Box -where - E: StdError + Send + Sync + 'static, -{ - // Attach ErrorImpl's native StdError vtable. The StdError impl is below. - let unerased_own = e.cast::>(); - unsafe { unerased_own.boxed() } -} - -// Safety: requires layout of *e to match ErrorImpl. -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -unsafe fn object_reallocate_boxed(e: Own) -> Box -where - E: StdError + Send + Sync + 'static, -{ - // Attach E's native StdError vtable. - let unerased_own = e.cast::>(); - Box::new(unsafe { unerased_own.boxed() }._object) -} - -// Safety: requires layout of *e to match ErrorImpl. -unsafe fn object_downcast(e: Ref, target: TypeId) -> Option> -where - E: 'static, -{ - if TypeId::of::() == target { - // Caller is looking for an E pointer and e is ErrorImpl, take a - // pointer to its E field. - let unerased_ref = e.cast::>(); - Some( - Ref::from_raw(unsafe { - NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut()) - }) - .cast::<()>(), - ) - } else { - None - } -} - -#[cfg(all(not(error_generic_member_access), feature = "std"))] -fn no_backtrace(e: Ref) -> Option<&Backtrace> { - let _ = e; - None -} - -// Safety: requires layout of *e to match ErrorImpl>. -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -unsafe fn context_downcast(e: Ref, target: TypeId) -> Option> -where - C: 'static, - E: 'static, -{ - if TypeId::of::() == target { - let unerased_ref = e.cast::>>(); - let inner = unsafe { ptr::addr_of!((*unerased_ref.as_ptr())._object.context) }; - Some(Ref::from_raw(unsafe { NonNull::new_unchecked(inner.cast_mut()) }).cast::<()>()) - } else if TypeId::of::() == target { - let unerased_ref = e.cast::>>(); - let inner = unsafe { ptr::addr_of!((*unerased_ref.as_ptr())._object.error) }; - Some(Ref::from_raw(unsafe { NonNull::new_unchecked(inner.cast_mut()) }).cast::<()>()) - } else { - None - } -} - -// Safety: requires layout of *e to match ErrorImpl>. -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -unsafe fn context_drop_rest(e: Own, target: TypeId) -where - C: 'static, - E: 'static, -{ - // Called after downcasting by value to either the C or the E and doing a - // ptr::read to take ownership of that value. - if TypeId::of::() == target { - let unerased_own = e.cast::, E>>>(); - drop(unsafe { unerased_own.boxed() }); - } else { - let unerased_own = e.cast::>>>(); - drop(unsafe { unerased_own.boxed() }); - } -} - -// Safety: requires layout of *e to match ErrorImpl>. -unsafe fn context_chain_downcast(e: Ref, target: TypeId) -> Option> -where - C: 'static, -{ - let unerased_ref = e.cast::>>(); - if TypeId::of::() == target { - let inner = unsafe { ptr::addr_of!((*unerased_ref.as_ptr())._object.context) }; - Some(Ref::from_raw(unsafe { NonNull::new_unchecked(inner.cast_mut()) }).cast::<()>()) - } else { - // Recurse down the context chain per the inner error's vtable. - let unerased = unsafe { unerased_ref.deref() }; - let source = &unerased._object.error; - unsafe { (vtable(source.inner.ptr).object_downcast)(source.inner.by_ref(), target) } - } -} - -// Safety: requires layout of *e to match ErrorImpl>. -unsafe fn context_chain_drop_rest(e: Own, target: TypeId) -where - C: 'static, -{ - // Called after downcasting by value to either the C or one of the causes - // and doing a ptr::read to take ownership of that value. - if TypeId::of::() == target { - let unerased_own = e.cast::, Error>>>(); - // Drop the entire rest of the data structure rooted in the next Error. - drop(unsafe { unerased_own.boxed() }); - } else { - let unerased_own = e.cast::>>>(); - let unerased = unsafe { unerased_own.boxed() }; - // Read the Own from the next error. - let inner = unerased._object.error.inner; - drop(unerased); - let vtable = unsafe { vtable(inner.ptr) }; - // Recursively drop the next error using the same target typeid. - unsafe { (vtable.object_drop_rest)(inner, target) }; - } -} - -// Safety: requires layout of *e to match ErrorImpl>. -#[cfg(all(not(error_generic_member_access), feature = "std"))] -#[allow(clippy::unnecessary_wraps)] -unsafe fn context_backtrace(e: Ref) -> Option<&Backtrace> -where - C: 'static, -{ - let unerased_ref = e.cast::>>(); - let unerased = unsafe { unerased_ref.deref() }; - let backtrace = unsafe { ErrorImpl::backtrace(unerased._object.error.inner.by_ref()) }; - Some(backtrace) -} - -// NOTE: If working with `ErrorImpl<()>`, references should be avoided in favor -// of raw pointers and `NonNull`. -// repr C to ensure that E remains in the final position. -#[repr(C)] -pub(crate) struct ErrorImpl { - vtable: &'static ErrorVTable, - backtrace: Option, - // NOTE: Don't use directly. Use only through vtable. Erased type may have - // different alignment. - _object: E, -} - -// Reads the vtable out of `p`. This is the same as `p.as_ref().vtable`, but -// avoids converting `p` into a reference. -unsafe fn vtable(p: NonNull) -> &'static ErrorVTable { - // NOTE: This assumes that `ErrorVTable` is the first field of ErrorImpl. - unsafe { *(p.as_ptr() as *const &'static ErrorVTable) } -} - -// repr C to ensure that ContextError has the same layout as -// ContextError, E> and ContextError>. -#[repr(C)] -pub(crate) struct ContextError { - pub context: C, - pub error: E, -} - -impl ErrorImpl { - fn erase(&self) -> Ref { - // Erase the concrete type of E but preserve the vtable in self.vtable - // for manipulating the resulting thin pointer. This is analogous to an - // unsize coercion. - Ref::new(self).cast::() - } -} - -impl ErrorImpl { - pub(crate) unsafe fn error(this: Ref) -> &(dyn StdError + Send + Sync + 'static) { - // Use vtable to attach E's native StdError vtable for the right - // original type E. - unsafe { (vtable(this.ptr).object_ref)(this).deref() } - } - - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - pub(crate) unsafe fn error_mut(this: Mut) -> &mut (dyn StdError + Send + Sync + 'static) { - // Use vtable to attach E's native StdError vtable for the right - // original type E. - unsafe { - (vtable(this.ptr).object_ref)(this.by_ref()) - .by_mut() - .deref_mut() - } - } - - #[cfg(feature = "std")] - pub(crate) unsafe fn backtrace(this: Ref) -> &Backtrace { - // This unwrap can only panic if the underlying error's backtrace method - // is nondeterministic, which would only happen in maliciously - // constructed code. - unsafe { this.deref() } - .backtrace - .as_ref() - .or_else(|| { - #[cfg(error_generic_member_access)] - return nightly::request_ref_backtrace(unsafe { Self::error(this) }); - #[cfg(not(error_generic_member_access))] - return unsafe { (vtable(this.ptr).object_backtrace)(this) }; - }) - .expect("backtrace capture failed") - } - - #[cfg(error_generic_member_access)] - unsafe fn provide<'a>(this: Ref<'a, Self>, request: &mut Request<'a>) { - if let Some(backtrace) = unsafe { &this.deref().backtrace } { - nightly::provide_ref_backtrace(request, backtrace); - } - nightly::provide(unsafe { Self::error(this) }, request); - } - - #[cold] - pub(crate) unsafe fn chain(this: Ref) -> Chain { - Chain::new(unsafe { Self::error(this) }) - } -} - -impl StdError for ErrorImpl -where - E: StdError, -{ - fn source(&self) -> Option<&(dyn StdError + 'static)> { - unsafe { ErrorImpl::error(self.erase()).source() } - } - - #[cfg(error_generic_member_access)] - fn provide<'a>(&'a self, request: &mut Request<'a>) { - unsafe { ErrorImpl::provide(self.erase(), request) } - } -} - -impl Debug for ErrorImpl -where - E: Debug, -{ - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - unsafe { ErrorImpl::debug(self.erase(), formatter) } - } -} - -impl Display for ErrorImpl -where - E: Display, -{ - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - unsafe { Display::fmt(ErrorImpl::error(self.erase()), formatter) } - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl From for Box { - #[cold] - fn from(error: Error) -> Self { - error.into_boxed_dyn_error() - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl From for Box { - #[cold] - fn from(error: Error) -> Self { - error.into_boxed_dyn_error() - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl From for Box { - #[cold] - fn from(error: Error) -> Self { - error.into_boxed_dyn_error() - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl AsRef for Error { - fn as_ref(&self) -> &(dyn StdError + Send + Sync + 'static) { - &**self - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl AsRef for Error { - fn as_ref(&self) -> &(dyn StdError + 'static) { - &**self - } -} - -impl UnwindSafe for Error {} -impl RefUnwindSafe for Error {} diff --git a/third_party/crates/anyhow-1.0.104/src/fmt.rs b/third_party/crates/anyhow-1.0.104/src/fmt.rs deleted file mode 100644 index 9a108cb..0000000 --- a/third_party/crates/anyhow-1.0.104/src/fmt.rs +++ /dev/null @@ -1,158 +0,0 @@ -use crate::chain::Chain; -use crate::error::ErrorImpl; -use crate::ptr::Ref; -use core::fmt::{self, Debug, Write}; - -impl ErrorImpl { - pub(crate) unsafe fn display(this: Ref, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", unsafe { Self::error(this) })?; - - if f.alternate() { - let chain = unsafe { Self::chain(this) }; - for cause in chain.skip(1) { - write!(f, ": {}", cause)?; - } - } - - Ok(()) - } - - pub(crate) unsafe fn debug(this: Ref, f: &mut fmt::Formatter) -> fmt::Result { - let error = unsafe { Self::error(this) }; - - if f.alternate() { - return Debug::fmt(error, f); - } - - write!(f, "{}", error)?; - - if let Some(cause) = error.source() { - write!(f, "\n\nCaused by:")?; - let multiple = cause.source().is_some(); - for (n, error) in Chain::new(cause).enumerate() { - writeln!(f)?; - let mut indented = Indented { - inner: f, - number: if multiple { Some(n) } else { None }, - started: false, - }; - write!(indented, "{}", error)?; - } - } - - #[cfg(feature = "std")] - { - use alloc::string::ToString; - use std::backtrace::BacktraceStatus; - - let backtrace = unsafe { Self::backtrace(this) }; - if let BacktraceStatus::Captured = backtrace.status() { - let mut backtrace = backtrace.to_string(); - write!(f, "\n\n")?; - if backtrace.starts_with("stack backtrace:") { - // Capitalize to match "Caused by:" - backtrace.replace_range(0..1, "S"); - } else { - // "stack backtrace:" prefix was removed in - // https://github.com/rust-lang/backtrace-rs/pull/286 - writeln!(f, "Stack backtrace:")?; - } - backtrace.truncate(backtrace.trim_end().len()); - write!(f, "{}", backtrace)?; - } - } - - Ok(()) - } -} - -struct Indented<'a, D> { - inner: &'a mut D, - number: Option, - started: bool, -} - -impl Write for Indented<'_, T> -where - T: Write, -{ - fn write_str(&mut self, s: &str) -> fmt::Result { - for (i, line) in s.split('\n').enumerate() { - if !self.started { - self.started = true; - match self.number { - Some(number) => write!(self.inner, "{: >5}: ", number)?, - None => self.inner.write_str(" ")?, - } - } else if i > 0 { - self.inner.write_char('\n')?; - if self.number.is_some() { - self.inner.write_str(" ")?; - } else { - self.inner.write_str(" ")?; - } - } - - self.inner.write_str(line)?; - } - - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use alloc::string::String; - - #[test] - fn one_digit() { - let input = "verify\nthis"; - let expected = " 2: verify\n this"; - let mut output = String::new(); - - Indented { - inner: &mut output, - number: Some(2), - started: false, - } - .write_str(input) - .unwrap(); - - assert_eq!(expected, output); - } - - #[test] - fn two_digits() { - let input = "verify\nthis"; - let expected = " 12: verify\n this"; - let mut output = String::new(); - - Indented { - inner: &mut output, - number: Some(12), - started: false, - } - .write_str(input) - .unwrap(); - - assert_eq!(expected, output); - } - - #[test] - fn no_digits() { - let input = "verify\nthis"; - let expected = " verify\n this"; - let mut output = String::new(); - - Indented { - inner: &mut output, - number: None, - started: false, - } - .write_str(input) - .unwrap(); - - assert_eq!(expected, output); - } -} diff --git a/third_party/crates/anyhow-1.0.104/src/kind.rs b/third_party/crates/anyhow-1.0.104/src/kind.rs deleted file mode 100644 index a9f40c3..0000000 --- a/third_party/crates/anyhow-1.0.104/src/kind.rs +++ /dev/null @@ -1,121 +0,0 @@ -// Tagged dispatch mechanism for resolving the behavior of `anyhow!($expr)`. -// -// When anyhow! is given a single expr argument to turn into anyhow::Error, we -// want the resulting Error to pick up the input's implementation of source() -// and backtrace() if it has a std::error::Error impl, otherwise require nothing -// more than Display and Debug. -// -// Expressed in terms of specialization, we want something like: -// -// trait AnyhowNew { -// fn new(self) -> Error; -// } -// -// impl AnyhowNew for T -// where -// T: Display + Debug + Send + Sync + 'static, -// { -// default fn new(self) -> Error { -// /* no std error impl */ -// } -// } -// -// impl AnyhowNew for T -// where -// T: std::error::Error + Send + Sync + 'static, -// { -// fn new(self) -> Error { -// /* use std error's source() and backtrace() */ -// } -// } -// -// Since specialization is not stable yet, instead we rely on autoref behavior -// of method resolution to perform tagged dispatch. Here we have two traits -// AdhocKind and TraitKind that both have an anyhow_kind() method. AdhocKind is -// implemented whether or not the caller's type has a std error impl, while -// TraitKind is implemented only when a std error impl does exist. The ambiguity -// is resolved by AdhocKind requiring an extra autoref so that it has lower -// precedence. -// -// The anyhow! macro will set up the call in this form: -// -// #[allow(unused_imports)] -// use $crate::__private::{AdhocKind, TraitKind}; -// let error = $msg; -// (&error).anyhow_kind().new(error) - -use crate::Error; -use core::fmt::{Debug, Display}; - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -use crate::StdError; -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -use alloc::boxed::Box; - -pub struct Adhoc; - -#[doc(hidden)] -pub trait AdhocKind: Sized { - #[inline] - fn anyhow_kind(&self) -> Adhoc { - Adhoc - } -} - -impl AdhocKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {} - -impl Adhoc { - #[cold] - pub fn new(self, message: M) -> Error - where - M: Display + Debug + Send + Sync + 'static, - { - Error::construct_from_adhoc(message, backtrace!()) - } -} - -pub struct Trait; - -#[doc(hidden)] -pub trait TraitKind: Sized { - #[inline] - fn anyhow_kind(&self) -> Trait { - Trait - } -} - -impl TraitKind for E where E: Into {} - -impl Trait { - #[cold] - pub fn new(self, error: E) -> Error - where - E: Into, - { - error.into() - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -pub struct Boxed; - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -#[doc(hidden)] -pub trait BoxedKind: Sized { - #[inline] - fn anyhow_kind(&self) -> Boxed { - Boxed - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl BoxedKind for Box {} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl Boxed { - #[cold] - pub fn new(self, error: Box) -> Error { - let backtrace = backtrace_if_absent!(&*error); - Error::construct_from_boxed(error, backtrace) - } -} diff --git a/third_party/crates/anyhow-1.0.104/src/lib.rs b/third_party/crates/anyhow-1.0.104/src/lib.rs deleted file mode 100644 index 2b5760d..0000000 --- a/third_party/crates/anyhow-1.0.104/src/lib.rs +++ /dev/null @@ -1,728 +0,0 @@ -//! [![github]](https://github.com/dtolnay/anyhow) [![crates-io]](https://crates.io/crates/anyhow) [![docs-rs]](https://docs.rs/anyhow) -//! -//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github -//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust -//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs -//! -//!
-//! -//! This library provides [`anyhow::Error`][Error], a trait object based error -//! type for easy idiomatic error handling in Rust applications. -//! -//!
-//! -//! # Details -//! -//! - Use `Result`, or equivalently `anyhow::Result`, as -//! the return type of any fallible function. -//! -//! Within the function, use `?` to easily propagate any error that implements -//! the [`std::error::Error`] trait. -//! -//! ``` -//! # pub trait Deserialize {} -//! # -//! # mod serde_json { -//! # use super::Deserialize; -//! # use std::io; -//! # -//! # pub fn from_str(json: &str) -> io::Result { -//! # unimplemented!() -//! # } -//! # } -//! # -//! # struct ClusterMap; -//! # -//! # impl Deserialize for ClusterMap {} -//! # -//! use anyhow::Result; -//! -//! fn get_cluster_info() -> Result { -//! let config = std::fs::read_to_string("cluster.json")?; -//! let map: ClusterMap = serde_json::from_str(&config)?; -//! Ok(map) -//! } -//! # -//! # fn main() {} -//! ``` -//! -//! - Attach context to help the person troubleshooting the error understand -//! where things went wrong. A low-level error like "No such file or -//! directory" can be annoying to debug without more context about what higher -//! level step the application was in the middle of. -//! -//! ``` -//! # struct It; -//! # -//! # impl It { -//! # fn detach(&self) -> Result<()> { -//! # unimplemented!() -//! # } -//! # } -//! # -//! use anyhow::{Context, Result}; -//! -//! fn main() -> Result<()> { -//! # return Ok(()); -//! # -//! # const _: &str = stringify! { -//! ... -//! # }; -//! # -//! # let it = It; -//! # let path = "./path/to/instrs.json"; -//! # -//! it.detach().context("Failed to detach the important thing")?; -//! -//! let content = std::fs::read(path) -//! .with_context(|| format!("Failed to read instrs from {}", path))?; -//! # -//! # const _: &str = stringify! { -//! ... -//! # }; -//! # -//! # Ok(()) -//! } -//! ``` -//! -//! ```console -//! Error: Failed to read instrs from ./path/to/instrs.json -//! -//! Caused by: -//! No such file or directory (os error 2) -//! ``` -//! -//! - Downcasting is supported and can be by value, by shared reference, or by -//! mutable reference as needed. -//! -//! ``` -//! # use anyhow::anyhow; -//! # use std::fmt::{self, Display}; -//! # use std::task::Poll; -//! # -//! # #[derive(Debug)] -//! # enum DataStoreError { -//! # Censored(()), -//! # } -//! # -//! # impl Display for DataStoreError { -//! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { -//! # unimplemented!() -//! # } -//! # } -//! # -//! # impl std::error::Error for DataStoreError {} -//! # -//! # const REDACTED_CONTENT: () = (); -//! # -//! # let error = anyhow!("..."); -//! # let root_cause = &error; -//! # -//! # let ret = -//! // If the error was caused by redaction, then return a -//! // tombstone instead of the content. -//! match root_cause.downcast_ref::() { -//! Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), -//! None => Err(error), -//! } -//! # ; -//! ``` -//! -//! - 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`; -//! - 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`]: std::backtrace#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 but you can write the impls yourself or use a standalone macro like -//! [thiserror]. -//! -//! [thiserror]: https://github.com/dtolnay/thiserror -//! -//! ``` -//! use thiserror::Error; -//! -//! #[derive(Error, Debug)] -//! pub enum FormatError { -//! #[error("Invalid header (expected {expected:?}, got {found:?})")] -//! InvalidHeader { -//! expected: String, -//! found: String, -//! }, -//! #[error("Missing attribute: {0}")] -//! MissingAttribute(String), -//! } -//! ``` -//! -//! - One-off error messages can be constructed using the `anyhow!` macro, which -//! supports string interpolation and produces an `anyhow::Error`. -//! -//! ``` -//! # use anyhow::{anyhow, Result}; -//! # -//! # fn demo() -> Result<()> { -//! # let missing = "..."; -//! return Err(anyhow!("Missing attribute: {}", missing)); -//! # Ok(()) -//! # } -//! ``` -//! -//! A `bail!` macro is provided as a shorthand for the same early return. -//! -//! ``` -//! # use anyhow::{bail, Result}; -//! # -//! # fn demo() -> Result<()> { -//! # let missing = "..."; -//! bail!("Missing attribute: {}", missing); -//! # Ok(()) -//! # } -//! ``` -//! -//!
-//! -//! # No-std support -//! -//! In no_std mode, almost all of the same API is available and works the same -//! way. To depend on Anyhow in no_std mode, disable our default enabled "std" -//! feature in Cargo.toml. A global allocator is required. -//! -//! ```toml -//! [dependencies] -//! anyhow = { version = "1.0", default-features = false } -//! ``` -//! -//! With versions of Rust older than 1.81, no_std mode may require an additional -//! `.map_err(Error::msg)` when working with a non-Anyhow error type inside a -//! function that returns Anyhow's error type, as the trait that `?`-based error -//! conversions are defined by is only available in std in those old versions. - -#![doc(html_root_url = "https://docs.rs/anyhow/1.0.104")] -#![cfg_attr(error_generic_member_access, feature(error_generic_member_access))] -#![no_std] -#![deny(dead_code, unsafe_op_in_unsafe_fn, unused_imports, unused_mut)] -#![allow( - clippy::doc_markdown, - clippy::elidable_lifetime_names, - clippy::enum_glob_use, - clippy::explicit_auto_deref, - clippy::extra_unused_type_parameters, - clippy::incompatible_msrv, - clippy::let_underscore_untyped, - clippy::missing_errors_doc, - clippy::missing_panics_doc, - clippy::module_name_repetitions, - clippy::must_use_candidate, - clippy::needless_doctest_main, - clippy::needless_lifetimes, - clippy::new_ret_no_self, - clippy::redundant_else, - clippy::return_self_not_must_use, - clippy::struct_field_names, - clippy::uninlined_format_args, - clippy::unused_self, - clippy::used_underscore_binding, - clippy::wildcard_imports, - clippy::wrong_self_convention -)] -#![allow(unknown_lints, mismatched_lifetime_syntaxes)] - -#[cfg(all( - anyhow_nightly_testing, - feature = "std", - not(error_generic_member_access) -))] -compile_error!("Build script probe failed to compile."); - -extern crate alloc; - -#[cfg(feature = "std")] -extern crate std; - -#[macro_use] -mod backtrace; -mod chain; -mod context; -mod ensure; -mod error; -mod fmt; -mod kind; -mod macros; -#[cfg(error_generic_member_access)] -mod nightly; -mod ptr; -mod wrapper; - -use crate::error::ErrorImpl; -use crate::ptr::Own; -use core::fmt::Display; - -#[cfg(all(not(feature = "std"), anyhow_no_core_error))] -use core::fmt::Debug; - -#[cfg(feature = "std")] -use std::error::Error as StdError; - -#[cfg(not(any(feature = "std", anyhow_no_core_error)))] -use core::error::Error as StdError; - -#[cfg(all(not(feature = "std"), anyhow_no_core_error))] -trait StdError: Debug + Display { - fn source(&self) -> Option<&(dyn StdError + 'static)> { - None - } -} - -#[doc(no_inline)] -pub use anyhow as format_err; - -/// The `Error` type, a wrapper around a dynamic error type. -/// -/// `Error` works a lot like `Box`, but with these -/// differences: -/// -/// - `Error` requires that the error is `Send`, `Sync`, and `'static`. -/// - `Error` guarantees that a backtrace is available, even if the underlying -/// error type does not provide one. -/// - `Error` is represented as a narrow pointer — exactly one word in -/// size instead of two. -/// -///
-/// -/// # Display representations -/// -/// When you print an error object using "{}" or to_string(), only the outermost -/// underlying error or context is printed, not any of the lower level causes. -/// This is exactly as if you had called the Display impl of the error from -/// which you constructed your anyhow::Error. -/// -/// ```console -/// Failed to read instrs from ./path/to/instrs.json -/// ``` -/// -/// To print causes as well using anyhow's default formatting of causes, use the -/// alternate selector "{:#}". -/// -/// ```console -/// Failed to read instrs from ./path/to/instrs.json: No such file or directory (os error 2) -/// ``` -/// -/// The Debug format "{:?}" includes your backtrace if one was captured. Note -/// that this is the representation you get by default if you return an error -/// from `fn main` instead of printing it explicitly yourself. -/// -/// ```console -/// Error: Failed to read instrs from ./path/to/instrs.json -/// -/// Caused by: -/// No such file or directory (os error 2) -/// ``` -/// -/// and if there is a backtrace available: -/// -/// ```console -/// Error: Failed to read instrs from ./path/to/instrs.json -/// -/// Caused by: -/// No such file or directory (os error 2) -/// -/// Stack backtrace: -/// 0: ::ext_context -/// at /git/anyhow/src/backtrace.rs:26 -/// 1: core::result::Result::map_err -/// at /git/rustc/src/libcore/result.rs:596 -/// 2: anyhow::context:: for core::result::Result>::with_context -/// at /git/anyhow/src/context.rs:58 -/// 3: testing::main -/// at src/main.rs:5 -/// 4: std::rt::lang_start -/// at /git/rustc/src/libstd/rt.rs:61 -/// 5: main -/// 6: __libc_start_main -/// 7: _start -/// ``` -/// -/// To see a conventional struct-style Debug representation, use "{:#?}". -/// -/// ```console -/// Error { -/// context: "Failed to read instrs from ./path/to/instrs.json", -/// source: Os { -/// code: 2, -/// kind: NotFound, -/// message: "No such file or directory", -/// }, -/// } -/// ``` -/// -/// If none of the built-in representations are appropriate and you would prefer -/// to render the error and its cause chain yourself, it can be done something -/// like this: -/// -/// ``` -/// use anyhow::{Context, Result}; -/// -/// fn main() { -/// if let Err(err) = try_main() { -/// eprintln!("ERROR: {}", err); -/// err.chain().skip(1).for_each(|cause| eprintln!("because: {}", cause)); -/// std::process::exit(1); -/// } -/// } -/// -/// fn try_main() -> Result<()> { -/// # const IGNORE: &str = stringify! { -/// ... -/// # }; -/// # Ok(()) -/// } -/// ``` -#[repr(transparent)] -pub struct Error { - inner: Own, -} - -/// Iterator of a chain of source errors. -/// -/// This type is the iterator returned by [`Error::chain`]. -/// -/// # Example -/// -/// ``` -/// use anyhow::Error; -/// use std::io; -/// -/// pub fn underlying_io_error_kind(error: &Error) -> Option { -/// for cause in error.chain() { -/// if let Some(io_error) = cause.downcast_ref::() { -/// return Some(io_error.kind()); -/// } -/// } -/// None -/// } -/// ``` -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -#[derive(Clone)] -pub struct Chain<'a> { - state: crate::chain::ChainState<'a>, -} - -/// `Result` -/// -/// This is a reasonable return type to use throughout your application but also -/// for `fn main`; if you do, failures will be printed along with any -/// [context][Context] and a backtrace if one was captured. -/// -/// `anyhow::Result` may be used with one *or* two type parameters. -/// -/// ```rust -/// use anyhow::Result; -/// -/// # const IGNORE: &str = stringify! { -/// fn demo1() -> Result {...} -/// // ^ equivalent to std::result::Result -/// -/// fn demo2() -> Result {...} -/// // ^ equivalent to std::result::Result -/// # }; -/// ``` -/// -/// # Example -/// -/// ``` -/// # pub trait Deserialize {} -/// # -/// # mod serde_json { -/// # use super::Deserialize; -/// # use std::io; -/// # -/// # pub fn from_str(json: &str) -> io::Result { -/// # unimplemented!() -/// # } -/// # } -/// # -/// # #[derive(Debug)] -/// # struct ClusterMap; -/// # -/// # impl Deserialize for ClusterMap {} -/// # -/// use anyhow::Result; -/// -/// fn main() -> Result<()> { -/// # return Ok(()); -/// let config = std::fs::read_to_string("cluster.json")?; -/// let map: ClusterMap = serde_json::from_str(&config)?; -/// println!("cluster info: {:#?}", map); -/// Ok(()) -/// } -/// ``` -pub type Result = core::result::Result; - -/// Provides the `context` method for `Result`. -/// -/// This trait is sealed and cannot be implemented for types outside of -/// `anyhow`. -/// -///
-/// -/// # Example -/// -/// ``` -/// use anyhow::{Context, Result}; -/// use std::fs; -/// use std::path::PathBuf; -/// -/// pub struct ImportantThing { -/// path: PathBuf, -/// } -/// -/// impl ImportantThing { -/// # const IGNORE: &'static str = stringify! { -/// pub fn detach(&mut self) -> Result<()> {...} -/// # }; -/// # fn detach(&mut self) -> Result<()> { -/// # unimplemented!() -/// # } -/// } -/// -/// pub fn do_it(mut it: ImportantThing) -> Result> { -/// it.detach().context("Failed to detach the important thing")?; -/// -/// let path = &it.path; -/// let content = fs::read(path) -/// .with_context(|| format!("Failed to read instrs from {}", path.display()))?; -/// -/// Ok(content) -/// } -/// ``` -/// -/// When printed, the outermost context would be printed first and the lower -/// level underlying causes would be enumerated below. -/// -/// ```console -/// Error: Failed to read instrs from ./path/to/instrs.json -/// -/// Caused by: -/// No such file or directory (os error 2) -/// ``` -/// -/// Refer to the [Display representations] documentation for other forms in -/// which this context chain can be rendered. -/// -/// [Display representations]: Error#display-representations -/// -///
-/// -/// # Effect on downcasting -/// -/// After attaching context of type `C` onto an error of type `E`, the resulting -/// `anyhow::Error` may be downcast to `C` **or** to `E`. -/// -/// That is, in codebases that rely on downcasting, Anyhow's context supports -/// both of the following use cases: -/// -/// - **Attaching context whose type is insignificant onto errors whose type -/// is used in downcasts.** -/// -/// In other error libraries whose context is not designed this way, it can -/// be risky to introduce context to existing code because new context might -/// break existing working downcasts. In Anyhow, any downcast that worked -/// before adding context will continue to work after you add a context, so -/// you should freely add human-readable context to errors wherever it would -/// be helpful. -/// -/// ``` -/// # use anyhow::bail; -/// # use thiserror::Error; -/// # -/// # #[derive(Error, Debug)] -/// # #[error("???")] -/// # struct SuspiciousError; -/// # -/// # fn helper() -> Result<()> { -/// # bail!(SuspiciousError); -/// # } -/// # -/// use anyhow::{Context, Result}; -/// -/// fn do_it() -> Result<()> { -/// helper().context("Failed to complete the work")?; -/// # const IGNORE: &str = stringify! { -/// ... -/// # }; -/// # unreachable!() -/// } -/// -/// fn main() { -/// let err = do_it().unwrap_err(); -/// if let Some(e) = err.downcast_ref::() { -/// // If helper() returned SuspiciousError, this downcast will -/// // correctly succeed even with the context in between. -/// # return; -/// } -/// # panic!("expected downcast to succeed"); -/// } -/// ``` -/// -/// - **Attaching context whose type is used in downcasts onto errors whose -/// type is insignificant.** -/// -/// Some codebases prefer to use machine-readable context to categorize -/// lower level errors in a way that will be actionable to higher levels of -/// the application. -/// -/// ``` -/// # use anyhow::bail; -/// # use thiserror::Error; -/// # -/// # #[derive(Error, Debug)] -/// # #[error("???")] -/// # struct HelperFailed; -/// # -/// # fn helper() -> Result<()> { -/// # bail!("no such file or directory"); -/// # } -/// # -/// use anyhow::{Context, Result}; -/// -/// fn do_it() -> Result<()> { -/// helper().context(HelperFailed)?; -/// # const IGNORE: &str = stringify! { -/// ... -/// # }; -/// # unreachable!() -/// } -/// -/// fn main() { -/// let err = do_it().unwrap_err(); -/// if let Some(e) = err.downcast_ref::() { -/// // If helper failed, this downcast will succeed because -/// // HelperFailed is the context that has been attached to -/// // that error. -/// # return; -/// } -/// # panic!("expected downcast to succeed"); -/// } -/// ``` -pub trait Context: context::private::Sealed { - /// Wrap the error value with additional context. - fn context(self, context: C) -> Result - where - C: Display + Send + Sync + 'static; - - /// Wrap the error value with additional context that is evaluated lazily - /// only once an error does occur. - fn with_context(self, f: F) -> Result - where - C: Display + Send + Sync + 'static, - F: FnOnce() -> C; -} - -/// Equivalent to `Ok::<_, anyhow::Error>(value)`. -/// -/// This simplifies creation of an `anyhow::Result` in places where type -/// inference cannot deduce the `E` type of the result — without needing -/// to write `Ok::<_, anyhow::Error>(value)`. -/// -/// One might think that `anyhow::Result::Ok(value)` would work in such cases -/// but it does not. -/// -/// ```console -/// error[E0282]: type annotations needed for `std::result::Result` -/// --> src/main.rs:11:13 -/// | -/// 11 | let _ = anyhow::Result::Ok(1); -/// | - ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result` -/// | | -/// | consider giving this pattern the explicit type `std::result::Result`, where the type parameter `E` is specified -/// ``` -#[allow(non_snake_case)] -#[inline] -pub fn Ok(value: T) -> Result { - Result::Ok(value) -} - -// Not public API. Referenced by macro-generated code. -#[doc(hidden)] -pub mod __private { - use self::not::Bool; - use crate::Error; - use alloc::fmt; - use core::fmt::Arguments; - - #[doc(hidden)] - pub use crate::ensure::{BothDebug, NotBothDebug}; - #[doc(hidden)] - pub use alloc::format; - #[doc(hidden)] - pub use core::result::Result::Err; - #[doc(hidden)] - pub use core::{concat, format_args, stringify}; - - #[doc(hidden)] - pub mod kind { - #[doc(hidden)] - pub use crate::kind::{AdhocKind, TraitKind}; - - #[cfg(any(feature = "std", not(anyhow_no_core_error)))] - #[doc(hidden)] - pub use crate::kind::BoxedKind; - } - - #[doc(hidden)] - #[inline] - #[cold] - pub fn format_err(args: Arguments) -> Error { - if let Some(message) = args.as_str() { - // anyhow!("literal"), can downcast to &'static str - Error::msg(message) - } else { - // anyhow!("interpolate {var}"), can downcast to String - Error::msg(fmt::format(args)) - } - } - - #[doc(hidden)] - #[inline] - #[cold] - #[must_use] - pub fn must_use(error: Error) -> Error { - error - } - - #[doc(hidden)] - #[inline] - pub fn not(cond: impl Bool) -> bool { - cond.not() - } - - mod not { - #[doc(hidden)] - pub trait Bool { - fn not(self) -> bool; - } - - impl Bool for bool { - #[inline] - fn not(self) -> bool { - !self - } - } - - impl Bool for &bool { - #[inline] - fn not(self) -> bool { - !*self - } - } - } -} diff --git a/third_party/crates/anyhow-1.0.104/src/macros.rs b/third_party/crates/anyhow-1.0.104/src/macros.rs deleted file mode 100644 index 1558de5..0000000 --- a/third_party/crates/anyhow-1.0.104/src/macros.rs +++ /dev/null @@ -1,245 +0,0 @@ -/// Return early with an error. -/// -/// This macro is equivalent to -/// return Err([anyhow!($args\...)][anyhow!]). -/// -/// The surrounding function's or closure's return value is required to be -/// Result<_, [anyhow::Error][crate::Error]>. -/// -/// [anyhow!]: crate::anyhow -/// -/// # Example -/// -/// ``` -/// # use anyhow::{bail, Result}; -/// # -/// # fn has_permission(user: usize, resource: usize) -> bool { -/// # true -/// # } -/// # -/// # fn main() -> Result<()> { -/// # let user = 0; -/// # let resource = 0; -/// # -/// if !has_permission(user, resource) { -/// bail!("permission denied for accessing {}", resource); -/// } -/// # Ok(()) -/// # } -/// ``` -/// -/// ``` -/// # use anyhow::{bail, Result}; -/// # use thiserror::Error; -/// # -/// # const MAX_DEPTH: usize = 1; -/// # -/// #[derive(Error, Debug)] -/// enum ScienceError { -/// #[error("recursion limit exceeded")] -/// RecursionLimitExceeded, -/// # #[error("...")] -/// # More = (stringify! { -/// ... -/// # }, 1).1, -/// } -/// -/// # fn main() -> Result<()> { -/// # let depth = 0; -/// # -/// if depth > MAX_DEPTH { -/// bail!(ScienceError::RecursionLimitExceeded); -/// } -/// # Ok(()) -/// # } -/// ``` -#[macro_export] -#[cfg_attr(not(anyhow_no_clippy_format_args), clippy::format_args)] -macro_rules! bail { - ($msg:literal $(,)?) => { - return $crate::__private::Err($crate::__anyhow!($msg)) - }; - ($err:expr $(,)?) => { - return $crate::__private::Err($crate::__anyhow!($err)) - }; - ($fmt:expr, $($arg:tt)*) => { - return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)) - }; -} - -macro_rules! __ensure { - ($ensure:item) => { - /// Return early with an error if a condition is not satisfied. - /// - /// This macro is equivalent to - /// if !$cond { return Err([anyhow!($args\...)][anyhow!]); }. - /// - /// The surrounding function's or closure's return value is required to be - /// Result<_, [anyhow::Error][crate::Error]>. - /// - /// Analogously to `assert!`, `ensure!` takes a condition and exits the function - /// if the condition fails. Unlike `assert!`, `ensure!` returns an `Error` - /// rather than panicking. - /// - /// [anyhow!]: crate::anyhow - /// - /// # Example - /// - /// ``` - /// # use anyhow::{ensure, Result}; - /// # - /// # fn main() -> Result<()> { - /// # let user = 0; - /// # - /// ensure!(user == 0, "only user 0 is allowed"); - /// # Ok(()) - /// # } - /// ``` - /// - /// ``` - /// # use anyhow::{ensure, Result}; - /// # use thiserror::Error; - /// # - /// # const MAX_DEPTH: usize = 1; - /// # - /// #[derive(Error, Debug)] - /// enum ScienceError { - /// #[error("recursion limit exceeded")] - /// RecursionLimitExceeded, - /// # #[error("...")] - /// # More = (stringify! { - /// ... - /// # }, 1).1, - /// } - /// - /// # fn main() -> Result<()> { - /// # let depth = 0; - /// # - /// ensure!(depth <= MAX_DEPTH, ScienceError::RecursionLimitExceeded); - /// # Ok(()) - /// # } - /// ``` - $ensure - }; -} - -#[cfg(doc)] -__ensure![ - #[macro_export] - macro_rules! ensure { - ($cond:expr $(,)?) => { - if !$cond { - return $crate::__private::Err($crate::Error::msg( - $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`") - )); - } - }; - ($cond:expr, $msg:literal $(,)?) => { - if !$cond { - return $crate::__private::Err($crate::__anyhow!($msg)); - } - }; - ($cond:expr, $err:expr $(,)?) => { - if !$cond { - return $crate::__private::Err($crate::__anyhow!($err)); - } - }; - ($cond:expr, $fmt:expr, $($arg:tt)*) => { - if !$cond { - return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)); - } - }; - } -]; - -#[cfg(not(doc))] -__ensure![ - #[macro_export] - #[cfg_attr(not(anyhow_no_clippy_format_args), clippy::format_args)] - macro_rules! ensure { - ($($tt:tt)*) => { - $crate::__parse_ensure!( - /* state */ 0 - /* stack */ () - /* bail */ ($($tt)*) - /* fuel */ (~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~) - /* parse */ {()} - /* dup */ ($($tt)*) - /* rest */ $($tt)* - ) - }; - } -]; - -/// Construct an ad-hoc error from a string or existing non-`anyhow` error -/// value. -/// -/// This evaluates to an [`Error`][crate::Error]. It can take either just a -/// string, or a format string with arguments. It also can take any custom type -/// which implements `Debug` and `Display`. -/// -/// If called with a single argument whose type implements `std::error::Error` -/// (in addition to `Debug` and `Display`, which are always required), then that -/// Error impl's `source` is preserved as the `source` of the resulting -/// `anyhow::Error`. -/// -/// # Example -/// -/// ``` -/// # type V = (); -/// # -/// use anyhow::{anyhow, Result}; -/// -/// fn lookup(key: &str) -> Result { -/// if key.len() != 16 { -/// return Err(anyhow!("key length must be 16 characters, got {:?}", key)); -/// } -/// -/// // ... -/// # Ok(()) -/// } -/// ``` -#[macro_export] -#[cfg_attr(not(anyhow_no_clippy_format_args), clippy::format_args)] -macro_rules! anyhow { - ($msg:literal $(,)?) => { - $crate::__private::must_use({ - let error = $crate::__private::format_err($crate::__private::format_args!($msg)); - error - }) - }; - ($err:expr $(,)?) => { - $crate::__private::must_use({ - use $crate::__private::kind::*; - let error = match $err { - error => (&error).anyhow_kind().new(error), - }; - error - }) - }; - ($fmt:expr, $($arg:tt)*) => { - $crate::Error::msg($crate::__private::format!($fmt, $($arg)*)) - }; -} - -// Not public API. This is used in the implementation of some of the other -// macros, in which the must_use call is not needed because the value is known -// to be used. -#[doc(hidden)] -#[macro_export] -macro_rules! __anyhow { - ($msg:literal $(,)?) => ({ - let error = $crate::__private::format_err($crate::__private::format_args!($msg)); - error - }); - ($err:expr $(,)?) => ({ - use $crate::__private::kind::*; - let error = match $err { - error => (&error).anyhow_kind().new(error), - }; - error - }); - ($fmt:expr, $($arg:tt)*) => { - $crate::Error::msg($crate::__private::format!($fmt, $($arg)*)) - }; -} diff --git a/third_party/crates/anyhow-1.0.104/src/nightly.rs b/third_party/crates/anyhow-1.0.104/src/nightly.rs deleted file mode 100644 index 125fe36..0000000 --- a/third_party/crates/anyhow-1.0.104/src/nightly.rs +++ /dev/null @@ -1,58 +0,0 @@ -// This code exercises the surface area that we expect of the Error generic -// member access API. If the current toolchain is able to compile it, then -// anyhow is able to provide backtrace support. - -#![cfg_attr(anyhow_build_probe, feature(error_generic_member_access))] - -use core::error::{self, Error}; -use std::backtrace::Backtrace; - -pub use core::error::Request; - -#[cfg(anyhow_build_probe)] -const _: () = { - use core::fmt::{self, Debug, Display}; - - struct MyError(Backtrace); - - impl Debug for MyError { - fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { - unimplemented!() - } - } - - impl Display for MyError { - fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { - unimplemented!() - } - } - - impl Error for MyError { - fn provide<'a>(&'a self, request: &mut Request<'a>) { - provide_ref_backtrace(request, &self.0); - } - } -}; - -// Include in sccache cache key. -#[cfg(anyhow_build_probe)] -const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP"); - -pub fn request_ref_backtrace(err: &dyn Error) -> Option<&Backtrace> { - request_ref::(err) -} - -fn request_ref<'a, T>(err: &'a (impl Error + ?Sized)) -> Option<&'a T> -where - T: 'static + ?Sized, -{ - error::request_ref::(err) -} - -pub fn provide_ref_backtrace<'a>(request: &mut Request<'a>, backtrace: &'a Backtrace) { - Request::provide_ref(request, backtrace); -} - -pub fn provide<'a>(err: &'a (impl Error + ?Sized), request: &mut Request<'a>) { - Error::provide(err, request); -} diff --git a/third_party/crates/anyhow-1.0.104/src/ptr.rs b/third_party/crates/anyhow-1.0.104/src/ptr.rs deleted file mode 100644 index 4d6b3ab..0000000 --- a/third_party/crates/anyhow-1.0.104/src/ptr.rs +++ /dev/null @@ -1,187 +0,0 @@ -use alloc::boxed::Box; -use core::marker::PhantomData; -use core::ptr::NonNull; - -#[repr(transparent)] -pub struct Own -where - T: ?Sized, -{ - pub ptr: NonNull, -} - -unsafe impl Send for Own where T: ?Sized {} - -unsafe impl Sync for Own where T: ?Sized {} - -impl Copy for Own where T: ?Sized {} - -impl Clone for Own -where - T: ?Sized, -{ - fn clone(&self) -> Self { - *self - } -} - -impl Own -where - T: ?Sized, -{ - pub fn new(ptr: Box) -> Self { - Own { - ptr: unsafe { NonNull::new_unchecked(Box::into_raw(ptr)) }, - } - } - - pub fn cast(self) -> Own { - Own { - ptr: self.ptr.cast(), - } - } - - pub unsafe fn boxed(self) -> Box { - unsafe { Box::from_raw(self.ptr.as_ptr()) } - } - - pub fn by_ref(&self) -> Ref { - Ref { - ptr: self.ptr, - lifetime: PhantomData, - } - } - - pub fn by_mut(&mut self) -> Mut { - Mut { - ptr: self.ptr, - lifetime: PhantomData, - } - } -} - -#[repr(transparent)] -pub struct Ref<'a, T> -where - T: ?Sized, -{ - pub ptr: NonNull, - lifetime: PhantomData<&'a T>, -} - -impl<'a, T> Copy for Ref<'a, T> where T: ?Sized {} - -impl<'a, T> Clone for Ref<'a, T> -where - T: ?Sized, -{ - fn clone(&self) -> Self { - *self - } -} - -impl<'a, T> Ref<'a, T> -where - T: ?Sized, -{ - pub fn new(ptr: &'a T) -> Self { - Ref { - ptr: NonNull::from(ptr), - lifetime: PhantomData, - } - } - - pub fn from_raw(ptr: NonNull) -> Self { - Ref { - ptr, - lifetime: PhantomData, - } - } - - pub fn cast(self) -> Ref<'a, U::Target> { - Ref { - ptr: self.ptr.cast(), - lifetime: PhantomData, - } - } - - pub fn by_mut(self) -> Mut<'a, T> { - Mut { - ptr: self.ptr, - lifetime: PhantomData, - } - } - - pub fn as_ptr(self) -> *const T { - self.ptr.as_ptr().cast_const() - } - - pub unsafe fn deref(self) -> &'a T { - unsafe { &*self.ptr.as_ptr() } - } -} - -#[repr(transparent)] -pub struct Mut<'a, T> -where - T: ?Sized, -{ - pub ptr: NonNull, - lifetime: PhantomData<&'a mut T>, -} - -impl<'a, T> Copy for Mut<'a, T> where T: ?Sized {} - -impl<'a, T> Clone for Mut<'a, T> -where - T: ?Sized, -{ - fn clone(&self) -> Self { - *self - } -} - -impl<'a, T> Mut<'a, T> -where - T: ?Sized, -{ - pub fn cast(self) -> Mut<'a, U::Target> { - Mut { - ptr: self.ptr.cast(), - lifetime: PhantomData, - } - } - - pub fn by_ref(self) -> Ref<'a, T> { - Ref { - ptr: self.ptr, - lifetime: PhantomData, - } - } - - pub fn extend<'b>(self) -> Mut<'b, T> { - Mut { - ptr: self.ptr, - lifetime: PhantomData, - } - } - - pub unsafe fn deref_mut(self) -> &'a mut T { - unsafe { &mut *self.ptr.as_ptr() } - } -} - -impl<'a, T> Mut<'a, T> { - pub unsafe fn read(self) -> T { - unsafe { self.ptr.as_ptr().read() } - } -} - -// Force turbofish on all calls of `.cast::()`. -pub trait CastTo { - type Target; -} - -impl CastTo for T { - type Target = T; -} diff --git a/third_party/crates/anyhow-1.0.104/src/wrapper.rs b/third_party/crates/anyhow-1.0.104/src/wrapper.rs deleted file mode 100644 index bad3ddd..0000000 --- a/third_party/crates/anyhow-1.0.104/src/wrapper.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::StdError; -use core::fmt::{self, Debug, Display}; - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -use alloc::boxed::Box; - -#[cfg(error_generic_member_access)] -use crate::nightly::{self, Request}; - -#[repr(transparent)] -pub struct MessageError(pub M); - -impl Debug for MessageError -where - M: Display + Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Debug::fmt(&self.0, f) - } -} - -impl Display for MessageError -where - M: Display + Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.0, f) - } -} - -impl StdError for MessageError where M: Display + Debug + 'static {} - -#[repr(transparent)] -pub struct DisplayError(pub M); - -impl Debug for DisplayError -where - M: Display, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.0, f) - } -} - -impl Display for DisplayError -where - M: Display, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.0, f) - } -} - -impl StdError for DisplayError where M: Display + 'static {} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -#[repr(transparent)] -pub struct BoxedError(pub Box); - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl Debug for BoxedError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Debug::fmt(&self.0, f) - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl Display for BoxedError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.0, f) - } -} - -#[cfg(any(feature = "std", not(anyhow_no_core_error)))] -impl StdError for BoxedError { - fn source(&self) -> Option<&(dyn StdError + 'static)> { - self.0.source() - } - - #[cfg(error_generic_member_access)] - fn provide<'a>(&'a self, request: &mut Request<'a>) { - nightly::provide(&*self.0, request); - } -} diff --git a/third_party/crates/anyhow-1.0.104/tests/common/mod.rs b/third_party/crates/anyhow-1.0.104/tests/common/mod.rs deleted file mode 100644 index fc165a5..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/common/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -use anyhow::{bail, Result}; -use std::io; - -pub fn bail_literal() -> Result<()> { - bail!("oh no!"); -} - -pub fn bail_fmt() -> Result<()> { - bail!("{} {}!", "oh", "no"); -} - -pub fn bail_error() -> Result<()> { - bail!(io::Error::new(io::ErrorKind::Other, "oh no!")); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/compiletest.rs b/third_party/crates/anyhow-1.0.104/tests/compiletest.rs deleted file mode 100644 index 23a6a06..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/compiletest.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[rustversion::attr(not(nightly), ignore = "requires nightly")] -#[cfg_attr(miri, ignore = "incompatible with miri")] -#[test] -fn ui() { - let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/*.rs"); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/drop/mod.rs b/third_party/crates/anyhow-1.0.104/tests/drop/mod.rs deleted file mode 100644 index 7da4bf5..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/drop/mod.rs +++ /dev/null @@ -1,53 +0,0 @@ -#![allow(clippy::module_name_repetitions)] - -use std::error::Error as StdError; -use std::fmt::{self, Display}; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; - -#[derive(Debug)] -pub struct Flag { - atomic: Arc, -} - -impl Flag { - pub fn new() -> Self { - Flag { - atomic: Arc::new(AtomicBool::new(false)), - } - } - - pub fn get(&self) -> bool { - self.atomic.load(Ordering::Relaxed) - } -} - -#[derive(Debug)] -pub struct DetectDrop { - has_dropped: Flag, -} - -impl DetectDrop { - pub fn new(has_dropped: &Flag) -> Self { - DetectDrop { - has_dropped: Flag { - atomic: Arc::clone(&has_dropped.atomic), - }, - } - } -} - -impl StdError for DetectDrop {} - -impl Display for DetectDrop { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "oh no!") - } -} - -impl Drop for DetectDrop { - fn drop(&mut self) { - let already_dropped = self.has_dropped.atomic.swap(true, Ordering::Relaxed); - assert!(!already_dropped); - } -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs b/third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs deleted file mode 100644 index 080b3b9..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_autotrait.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![allow(clippy::extra_unused_type_parameters)] - -use anyhow::Error; -use std::panic::{RefUnwindSafe, UnwindSafe}; - -#[test] -fn test_send() { - fn assert_send() {} - assert_send::(); -} - -#[test] -fn test_sync() { - fn assert_sync() {} - assert_sync::(); -} - -#[test] -fn test_unwind_safe() { - fn assert_unwind_safe() {} - assert_unwind_safe::(); -} - -#[test] -fn test_ref_unwind_safe() { - fn assert_ref_unwind_safe() {} - assert_ref_unwind_safe::(); -} - -#[test] -fn test_unpin() { - fn assert_unpin() {} - assert_unpin::(); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs b/third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs deleted file mode 100644 index 938c1c2..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_backtrace.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(clippy::let_underscore_untyped)] - -#[rustversion::not(nightly)] -#[ignore = "requires nightly"] -#[test] -fn test_backtrace() {} - -#[rustversion::nightly] -#[test] -fn test_backtrace() { - use anyhow::anyhow; - - let error = anyhow!("oh no!"); - let _ = error.backtrace(); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_boxed.rs b/third_party/crates/anyhow-1.0.104/tests/test_boxed.rs deleted file mode 100644 index fb1fb13..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_boxed.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![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; -use thiserror::Error; - -#[derive(Error, Debug)] -#[error("outer")] -struct MyError { - source: io::Error, -} - -#[test] -fn test_boxed_str() { - let error = Box::::from("oh no!"); - let error = anyhow!(error); - assert_eq!("oh no!", error.to_string()); - assert_eq!( - "oh no!", - error - .downcast_ref::>() - .unwrap() - .to_string() - ); -} - -#[test] -fn test_boxed_thiserror() { - let error = MyError { - source: io::Error::new(io::ErrorKind::Other, "oh no!"), - }; - let error = anyhow!(error); - assert_eq!("oh no!", error.source().unwrap().to_string()); -} - -#[test] -fn test_boxed_anyhow() { - let error = anyhow!("oh no!").context("it failed"); - let error = anyhow!(error); - assert_eq!("oh no!", error.source().unwrap().to_string()); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_chain.rs b/third_party/crates/anyhow-1.0.104/tests/test_chain.rs deleted file mode 100644 index c8b901a..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_chain.rs +++ /dev/null @@ -1,69 +0,0 @@ -use anyhow::{anyhow, Chain, Error}; - -fn error() -> Error { - anyhow!({ 0 }).context(1).context(2).context(3) -} - -#[test] -fn test_iter() { - let e = error(); - let mut chain = e.chain(); - 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()); -} - -#[test] -fn test_rev() { - let e = error(); - let mut chain = e.chain().rev(); - assert_eq!("0", chain.next().unwrap().to_string()); - assert_eq!("1", chain.next().unwrap().to_string()); - assert_eq!("2", chain.next().unwrap().to_string()); - assert_eq!("3", chain.next().unwrap().to_string()); - assert!(chain.next().is_none()); - assert!(chain.next_back().is_none()); -} - -#[test] -fn test_len() { - 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] -#[allow(clippy::redundant_clone)] -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/third_party/crates/anyhow-1.0.104/tests/test_context.rs b/third_party/crates/anyhow-1.0.104/tests/test_context.rs deleted file mode 100644 index 3496a07..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_context.rs +++ /dev/null @@ -1,195 +0,0 @@ -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] - -mod drop; - -use crate::drop::{DetectDrop, Flag}; -use anyhow::{Context, Error, Result}; -use std::fmt::{self, Display}; -use thiserror::Error; - -// https://github.com/dtolnay/anyhow/issues/18 -#[test] -fn test_inference() -> Result<()> { - let x = "1"; - let y: u32 = x.parse().context("...")?; - assert_eq!(y, 1); - Ok(()) -} - -macro_rules! context_type { - ($name:ident) => { - #[derive(Debug)] - struct $name { - message: &'static str, - #[allow(dead_code)] - drop: DetectDrop, - } - - impl Display for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.message) - } - } - }; -} - -context_type!(HighLevel); -context_type!(MidLevel); - -#[derive(Error, Debug)] -#[error("{message}")] -struct LowLevel { - message: &'static str, - drop: DetectDrop, -} - -struct Dropped { - low: Flag, - mid: Flag, - high: Flag, -} - -impl Dropped { - fn none(&self) -> bool { - !self.low.get() && !self.mid.get() && !self.high.get() - } - - fn all(&self) -> bool { - self.low.get() && self.mid.get() && self.high.get() - } -} - -fn make_chain() -> (Error, Dropped) { - let dropped = Dropped { - low: Flag::new(), - mid: Flag::new(), - high: Flag::new(), - }; - - let low = LowLevel { - message: "no such file or directory", - drop: DetectDrop::new(&dropped.low), - }; - - // impl Context for Result - let mid = Err::<(), LowLevel>(low) - .context(MidLevel { - message: "failed to load config", - drop: DetectDrop::new(&dropped.mid), - }) - .unwrap_err(); - - // impl Context for Result - let high = Err::<(), Error>(mid) - .context(HighLevel { - message: "failed to start server", - drop: DetectDrop::new(&dropped.high), - }) - .unwrap_err(); - - (high, dropped) -} - -#[test] -fn test_downcast_ref() { - let (err, dropped) = make_chain(); - - assert!(!err.is::()); - assert!(err.downcast_ref::().is_none()); - - assert!(err.is::()); - let high = err.downcast_ref::().unwrap(); - assert_eq!(high.to_string(), "failed to start server"); - - assert!(err.is::()); - let mid = err.downcast_ref::().unwrap(); - assert_eq!(mid.to_string(), "failed to load config"); - - assert!(err.is::()); - let low = err.downcast_ref::().unwrap(); - assert_eq!(low.to_string(), "no such file or directory"); - - assert!(dropped.none()); - drop(err); - assert!(dropped.all()); -} - -#[test] -fn test_downcast_high() { - let (err, dropped) = make_chain(); - - let err = err.downcast::().unwrap(); - assert!(!dropped.high.get()); - assert!(dropped.low.get() && dropped.mid.get()); - - drop(err); - assert!(dropped.all()); -} - -#[test] -fn test_downcast_mid() { - let (err, dropped) = make_chain(); - - let err = err.downcast::().unwrap(); - assert!(!dropped.mid.get()); - assert!(dropped.low.get() && dropped.high.get()); - - drop(err); - assert!(dropped.all()); -} - -#[test] -fn test_downcast_low() { - let (err, dropped) = make_chain(); - - let err = err.downcast::().unwrap(); - assert!(!dropped.low.get()); - assert!(dropped.mid.get() && dropped.high.get()); - - drop(err); - assert!(dropped.all()); -} - -#[test] -fn test_unsuccessful_downcast() { - let (err, dropped) = make_chain(); - - let err = err.downcast::().unwrap_err(); - assert!(dropped.none()); - - drop(err); - assert!(dropped.all()); -} - -#[test] -fn test_downcast_mut() { - let (mut err, dropped) = make_chain(); - - err.downcast_mut::().unwrap().message = "high context"; - err.downcast_mut::().unwrap().message = "mid context"; - err.downcast_mut::().unwrap().message = "low error"; - - assert_eq!( - err.downcast_ref::().unwrap().message, - "high context", - ); - assert_eq!( - err.downcast_ref::().unwrap().message, - "mid context", - ); - assert_eq!(err.downcast_ref::().unwrap().message, "low error"); - - assert!(dropped.none()); - 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/third_party/crates/anyhow-1.0.104/tests/test_convert.rs b/third_party/crates/anyhow-1.0.104/tests/test_convert.rs deleted file mode 100644 index 6da171d..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_convert.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![allow(clippy::unnecessary_wraps)] - -mod drop; - -use self::drop::{DetectDrop, Flag}; -use anyhow::{Error, Result}; -use std::error::Error as StdError; - -#[test] -fn test_convert() { - let has_dropped = Flag::new(); - let error = Error::new(DetectDrop::new(&has_dropped)); - let box_dyn = Box::::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::::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::::from(error); - assert_eq!("oh no!", box_dyn.to_string()); - drop(box_dyn); - assert!(has_dropped.get()); -} - -#[test] -fn test_question_mark() -> Result<(), Box> { - fn f() -> Result<()> { - Ok(()) - } - f()?; - Ok(()) -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_downcast.rs b/third_party/crates/anyhow-1.0.104/tests/test_downcast.rs deleted file mode 100644 index b4470d5..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_downcast.rs +++ /dev/null @@ -1,123 +0,0 @@ -#![allow(clippy::assertions_on_result_states, clippy::wildcard_imports)] - -mod common; -mod drop; - -use self::common::*; -use self::drop::{DetectDrop, Flag}; -use anyhow::Error; -use std::error::Error as StdError; -use std::fmt::{self, Display}; -use std::io; - -#[test] -fn test_downcast() { - assert_eq!( - "oh no!", - bail_literal().unwrap_err().downcast::<&str>().unwrap(), - ); - assert_eq!( - "oh no!", - bail_fmt().unwrap_err().downcast::().unwrap(), - ); - assert_eq!( - "oh no!", - bail_error() - .unwrap_err() - .downcast::() - .unwrap() - .to_string(), - ); -} - -#[test] -fn test_downcast_ref() { - assert_eq!( - "oh no!", - *bail_literal().unwrap_err().downcast_ref::<&str>().unwrap(), - ); - assert_eq!( - "oh no!", - bail_fmt().unwrap_err().downcast_ref::().unwrap(), - ); - assert_eq!( - "oh no!", - bail_error() - .unwrap_err() - .downcast_ref::() - .unwrap() - .to_string(), - ); -} - -#[test] -fn test_downcast_mut() { - assert_eq!( - "oh no!", - *bail_literal().unwrap_err().downcast_mut::<&str>().unwrap(), - ); - assert_eq!( - "oh no!", - bail_fmt().unwrap_err().downcast_mut::().unwrap(), - ); - assert_eq!( - "oh no!", - bail_error() - .unwrap_err() - .downcast_mut::() - .unwrap() - .to_string(), - ); - - let mut bailed = bail_fmt().unwrap_err(); - *bailed.downcast_mut::().unwrap() = "clobber".to_string(); - assert_eq!(bailed.downcast_ref::().unwrap(), "clobber"); - assert_eq!(bailed.downcast_mut::().unwrap(), "clobber"); - assert_eq!(bailed.downcast::().unwrap(), "clobber"); -} - -#[test] -fn test_drop() { - let has_dropped = Flag::new(); - let error = Error::new(DetectDrop::new(&has_dropped)); - drop(error.downcast::().unwrap()); - assert!(has_dropped.get()); -} - -#[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)] - struct LargeAlignedError(&'static str); - - impl Display for LargeAlignedError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.0) - } - } - - impl StdError for LargeAlignedError {} - - let error = Error::new(LargeAlignedError("oh no!")); - assert_eq!( - "oh no!", - error.downcast_ref::().unwrap().0 - ); -} - -#[test] -fn test_unsuccessful_downcast() { - let mut error = bail_error().unwrap_err(); - assert!(error.downcast_ref::<&str>().is_none()); - assert!(error.downcast_mut::<&str>().is_none()); - assert!(error.downcast::<&str>().is_err()); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_ensure.rs b/third_party/crates/anyhow-1.0.104/tests/test_ensure.rs deleted file mode 100644 index dc95160..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_ensure.rs +++ /dev/null @@ -1,756 +0,0 @@ -#![allow( - clippy::bool_to_int_with_if, - clippy::char_lit_as_u8, - clippy::deref_addrof, - clippy::diverging_sub_expression, - clippy::erasing_op, - clippy::extra_unused_type_parameters, - clippy::if_same_then_else, - clippy::ifs_same_cond, - clippy::ignored_unit_patterns, - clippy::items_after_statements, - clippy::let_and_return, - clippy::let_underscore_untyped, - clippy::literal_string_with_formatting_args, - clippy::match_bool, - clippy::needless_else, - clippy::never_loop, - clippy::overly_complex_bool_expr, - clippy::ptr_cast_constness, - clippy::redundant_closure_call, - clippy::redundant_pattern_matching, - clippy::too_many_lines, - clippy::uninlined_format_args, - clippy::unit_arg, - clippy::unnecessary_cast, - clippy::while_immutable_condition, - clippy::zero_ptr, - irrefutable_let_patterns -)] - -use self::Enum::Generic; -use anyhow::{anyhow, ensure, Chain, Error, Result}; -use std::fmt::{self, Debug}; -use std::iter; -use std::marker::{PhantomData, PhantomData as P}; -use std::mem; -use std::ops::Add; -use std::ptr; - -struct S; - -impl Add for S { - type Output = bool; - fn add(self, rhs: T) -> Self::Output { - let _ = rhs; - false - } -} - -trait Trait: Sized { - const V: usize = 0; - fn t(self, i: i32) -> i32 { - i - } -} - -impl Trait for T {} - -enum Enum { - #[allow(dead_code)] - Thing(PhantomData), - Generic, -} - -impl PartialEq for Enum { - fn eq(&self, rhs: &Self) -> bool { - mem::discriminant(self) == mem::discriminant(rhs) - } -} - -impl Debug for Enum { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("Generic") - } -} - -#[track_caller] -fn assert_err(result: impl FnOnce() -> Result, expected: &'static str) { - let actual = result().unwrap_err().to_string(); - - // In general different rustc versions will format the interpolated lhs and - // rhs $:expr fragment with insignificant differences in whitespace or - // punctuation, so we check the message in full against nightly and do just - // a cursory test on older toolchains. - if rustversion::cfg!(nightly) && !cfg!(miri) { - assert_eq!(actual, expected); - } else { - assert_eq!(actual.contains(" vs "), expected.contains(" vs ")); - } -} - -#[test] -fn test_recursion() { - // Must not blow the default #[recursion_limit], which is 128. - #[rustfmt::skip] - let test = || Ok(ensure!( - false | false | false | false | false | false | false | false | false | - false | false | false | false | false | false | false | false | false | - false | false | false | false | false | false | false | false | false | - false | false | false | false | false | false | false | false | false | - false | false | false | false | false | false | false | false | false | - false | false | false | false | false | false | false | false | false | - false | false | false | false | false | false | false | false | false - )); - - test().unwrap_err(); -} - -#[test] -fn test_low_precedence_control_flow() { - #[allow(unreachable_code)] - let test = || { - let val = loop { - // Break has lower precedence than the comparison operators so the - // expression here is `S + (break (1 == 1))`. It would be bad if the - // ensure macro partitioned this input into `(S + break 1) == (1)` - // because that means a different thing than what was written. - ensure!(S + break 1 == 1); - }; - Ok(val) - }; - - assert!(test().unwrap()); -} - -#[test] -fn test_low_precedence_binary_operator() { - // Must not partition as `false == (true && false)`. - let test = || Ok(ensure!(false == true && false)); - assert_err(test, "Condition failed: `false == true && false`"); - - // But outside the root level, it is fine. - let test = || Ok(ensure!(while false == true && false {} < ())); - assert_err( - test, - "Condition failed: `while false == true && false {} < ()` (() vs ())", - ); - - let a = 15; - let b = 3; - let test = || Ok(ensure!(a <= b || a - b <= 10)); - assert_err(test, "Condition failed: `a <= b || a - b <= 10`"); -} - -#[test] -fn test_high_precedence_binary_operator() { - let a = 15; - let b = 3; - let test = || Ok(ensure!(a - b <= 10)); - assert_err(test, "Condition failed: `a - b <= 10` (12 vs 10)"); -} - -#[test] -fn test_closure() { - // Must not partition as `(S + move) || (1 == 1)` by treating move as an - // identifier, nor as `(S + move || 1) == (1)` by misinterpreting the - // closure precedence. - let test = || Ok(ensure!(S + move || 1 == 1)); - assert_err(test, "Condition failed: `S + move || 1 == 1`"); - - let test = || Ok(ensure!(S + || 1 == 1)); - assert_err(test, "Condition failed: `S + || 1 == 1`"); - - // Must not partition as `S + ((move | ()) | 1) == 1` by treating those - // pipes as bitwise-or. - let test = || Ok(ensure!(S + move |()| 1 == 1)); - assert_err(test, "Condition failed: `S + move |()| 1 == 1`"); - - let test = || Ok(ensure!(S + |()| 1 == 1)); - assert_err(test, "Condition failed: `S + |()| 1 == 1`"); -} - -#[test] -fn test_unary() { - let mut x = &1; - let test = || Ok(ensure!(*x == 2)); - assert_err(test, "Condition failed: `*x == 2` (1 vs 2)"); - - let test = || Ok(ensure!(!x == 1)); - assert_err(test, "Condition failed: `!x == 1` (-2 vs 1)"); - - let test = || Ok(ensure!(-x == 1)); - assert_err(test, "Condition failed: `-x == 1` (-1 vs 1)"); - - let test = || Ok(ensure!(&x == &&2)); - assert_err(test, "Condition failed: `&x == &&2` (1 vs 2)"); - - let test = || Ok(ensure!(&mut x == *&&mut &2)); - assert_err(test, "Condition failed: `&mut x == *&&mut &2` (1 vs 2)"); -} - -#[rustversion::since(1.82)] -#[test] -fn test_raw_addr() { - let mut x = 1; - let test = || Ok(ensure!(S + &raw const x != S + &raw mut x)); - assert_err( - test, - "Condition failed: `S + &raw const x != S + &raw mut x` (false vs false)", - ); -} - -#[test] -fn test_if() { - #[rustfmt::skip] - let test = || Ok(ensure!(if false {}.t(1) == 2)); - assert_err(test, "Condition failed: `if false {}.t(1) == 2` (1 vs 2)"); - - #[rustfmt::skip] - let test = || Ok(ensure!(if false {} else {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `if false {} else {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(if false {} else if false {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `if false {} else if false {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(if let 1 = 2 {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `if let 1 = 2 {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(if let 1 | 2 = 2 {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `if let 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(if let | 1 | 2 = 2 {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `if let | 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)", - ); -} - -#[test] -fn test_loop() { - #[rustfmt::skip] - let test = || Ok(ensure!(1 + loop { break 1 } == 1)); - assert_err( - test, - "Condition failed: `1 + loop { break 1 } == 1` (2 vs 1)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(1 + 'a: loop { break 'a 1 } == 1)); - assert_err( - test, - "Condition failed: `1 + 'a: loop { break 'a 1 } == 1` (2 vs 1)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(while false {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `while false {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(while let None = Some(1) {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `while let None = Some(1) {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(for _x in iter::once(0) {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `for _x in iter::once(0) {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(for | _x in iter::once(0) {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `for | _x in iter::once(0) {}.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(for true | false in iter::empty() {}.t(1) == 2)); - assert_err( - test, - "Condition failed: `for true | false in iter::empty() {}.t(1) == 2` (1 vs 2)", - ); -} - -#[test] -fn test_match() { - #[rustfmt::skip] - let test = || Ok(ensure!(match 1 == 1 { true => 1, false => 0 } == 2)); - assert_err( - test, - "Condition failed: `match 1 == 1 { true => 1, false => 0 } == 2` (1 vs 2)", - ); -} - -#[test] -fn test_atom() { - let test = || Ok(ensure!([false, false].len() > 3)); - assert_err( - test, - "Condition failed: `[false, false].len() > 3` (2 vs 3)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!({ let x = 1; x } >= 3)); - assert_err(test, "Condition failed: `{ let x = 1; x } >= 3` (1 vs 3)"); - - let test = || Ok(ensure!(S + async { 1 } == true)); - assert_err( - test, - "Condition failed: `S + async { 1 } == true` (false vs true)", - ); - - let test = || Ok(ensure!(S + async move { 1 } == true)); - assert_err( - test, - "Condition failed: `S + async move { 1 } == true` (false vs true)", - ); - - let x = &1; - let test = || Ok(ensure!(S + unsafe { ptr::read(x) } == true)); - assert_err( - test, - "Condition failed: `S + unsafe { ptr::read(x) } == true` (false vs true)", - ); -} - -#[test] -fn test_path() { - let test = || Ok(ensure!(crate::S.t(1) == 2)); - assert_err(test, "Condition failed: `crate::S.t(1) == 2` (1 vs 2)"); - - let test = || Ok(ensure!(::anyhow::Error::root_cause.t(1) == 2)); - assert_err( - test, - "Condition failed: `::anyhow::Error::root_cause.t(1) == 2` (1 vs 2)", - ); - - let test = || Ok(ensure!(Error::msg::<&str>.t(1) == 2)); - assert_err( - test, - "Condition failed: `Error::msg::<&str>.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(Error::msg::<&str,>.t(1) == 2)); - assert_err( - test, - "Condition failed: `Error::msg::<&str,>.t(1) == 2` (1 vs 2)", - ); - - let test = || Ok(ensure!(Error::msg::<::Owned>.t(1) == 2)); - assert_err( - test, - "Condition failed: `Error::msg::<::Owned>.t(1) == 2` (1 vs 2)", - ); - - let test = || Ok(ensure!(Chain::<'static>::new.t(1) == 2)); - assert_err( - test, - "Condition failed: `Chain::<'static>::new.t(1) == 2` (1 vs 2)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(Chain::<'static,>::new.t(1) == 2)); - assert_err( - test, - "Condition failed: `Chain::<'static,>::new.t(1) == 2` (1 vs 2)", - ); - - fn f() {} - let test = || Ok(ensure!(f::<1>() != ())); - assert_err(test, "Condition failed: `f::<1>() != ()` (() vs ())"); - let test = || Ok(ensure!(f::<-1>() != ())); - assert_err(test, "Condition failed: `f::<-1>() != ()` (() vs ())"); - - fn g() {} - let test = || Ok(ensure!(g::() != ())); - assert_err(test, "Condition failed: `g::() != ()` (() vs ())"); - let test = || Ok(ensure!(g::() != ())); - assert_err(test, "Condition failed: `g::() != ()` (() vs ())"); - - #[derive(PartialOrd, PartialEq, Debug)] - enum E<'a, T> { - #[allow(dead_code)] - T(&'a T), - U, - } - - #[rustfmt::skip] - let test = || Ok(ensure!(E::U::<>>E::U::)); - assert_err(test, "Condition failed: `E::U::<> > E::U::` (U vs U)"); - - #[rustfmt::skip] - let test = || Ok(ensure!(E::U::>E::U)); - assert_err(test, "Condition failed: `E::U:: > E::U` (U vs U)"); - - #[rustfmt::skip] - let test = || Ok(ensure!(E::U::>E::U)); - assert_err(test, "Condition failed: `E::U:: > E::U` (U vs U)"); - - let test = || Ok(ensure!(Generic:: != Generic)); - assert_err( - test, - "Condition failed: `Generic:: != Generic` (Generic vs Generic)", - ); - - let test = || Ok(ensure!(Generic:: != Generic)); - assert_err( - test, - "Condition failed: `Generic:: != Generic` (Generic vs Generic)", - ); - - #[rustfmt::skip] - let test = || { - Ok(ensure!( - Generic:: != Generic - )) - }; - assert_err( - test, - "Condition failed: `Generic:: != Generic` (Generic vs Generic)", - ); -} - -#[test] -fn test_macro() { - let test = || Ok(ensure!(anyhow!("...").to_string().len() <= 1)); - assert_err( - test, - "Condition failed: `anyhow!(\"...\").to_string().len() <= 1` (3 vs 1)", - ); - - let test = || Ok(ensure!(vec![1].len() < 1)); - assert_err(test, "Condition failed: `vec![1].len() < 1` (1 vs 1)"); - - let test = || Ok(ensure!(stringify! {} != "")); - assert_err( - test, - "Condition failed: `stringify! {} != \"\"` (\"\" vs \"\")", - ); -} - -#[test] -fn test_trailer() { - let test = || Ok(ensure!((|| 1)() == 2)); - assert_err(test, "Condition failed: `(|| 1)() == 2` (1 vs 2)"); - - let test = || Ok(ensure!(b"hmm"[1] == b'c')); - assert_err(test, "Condition failed: `b\"hmm\"[1] == b'c'` (109 vs 99)"); - - let test = || Ok(ensure!(PhantomData:: {} != PhantomData)); - assert_err( - test, - "Condition failed: `PhantomData:: {} != PhantomData` (PhantomData vs PhantomData)", - ); - - let result = Ok::<_, Error>(1); - let test = || Ok(ensure!(result? == 2)); - assert_err(test, "Condition failed: `result? == 2` (1 vs 2)"); - - let test = || Ok(ensure!((2, 3).1 == 2)); - assert_err(test, "Condition failed: `(2, 3).1 == 2` (3 vs 2)"); - - #[rustfmt::skip] - let test = || Ok(ensure!((2, (3, 4)). 1.1 == 2)); - assert_err(test, "Condition failed: `(2, (3, 4)).1.1 == 2` (4 vs 2)"); - - let err = anyhow!(""); - let test = || Ok(ensure!(err.is::<&str>() == false)); - assert_err( - test, - "Condition failed: `err.is::<&str>() == false` (true vs false)", - ); - - let test = || Ok(ensure!(err.is::<::Owned>() == true)); - assert_err( - test, - "Condition failed: `err.is::<::Owned>() == true` (false vs true)", - ); -} - -#[test] -fn test_whitespace() { - #[derive(Debug)] - pub struct Point { - #[allow(dead_code)] - pub x: i32, - #[allow(dead_code)] - pub y: i32, - } - - let point = Point { x: 0, y: 0 }; - let test = || Ok(ensure!("" == format!("{:#?}", point))); - assert_err( - test, - "Condition failed: `\"\" == format!(\"{:#?}\", point)`", - ); -} - -#[test] -fn test_too_long() { - let test = || Ok(ensure!("" == "x".repeat(10))); - assert_err( - test, - "Condition failed: `\"\" == \"x\".repeat(10)` (\"\" vs \"xxxxxxxxxx\")", - ); - - let test = || Ok(ensure!("" == "x".repeat(80))); - assert_err(test, "Condition failed: `\"\" == \"x\".repeat(80)`"); -} - -#[test] -fn test_as() { - let test = || Ok(ensure!('\0' as u8 > 1)); - assert_err(test, "Condition failed: `'\\0' as u8 > 1` (0 vs 1)"); - - let test = || Ok(ensure!('\0' as ::std::primitive::u8 > 1)); - assert_err( - test, - "Condition failed: `'\\0' as ::std::primitive::u8 > 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(&[0] as &[i32] == [1])); - assert_err( - test, - "Condition failed: `&[0] as &[i32] == [1]` ([0] vs [1])", - ); - - let test = || Ok(ensure!(0 as *const () as *mut _ == 1 as *mut ())); - assert_err( - test, - "Condition failed: `0 as *const () as *mut _ == 1 as *mut ()` (0x0 vs 0x1)", - ); - - let s = ""; - let test = || Ok(ensure!(s as &str != s)); - assert_err(test, "Condition failed: `s as &str != s` (\"\" vs \"\")"); - - let test = || Ok(ensure!(&s as &&str != &s)); - assert_err(test, "Condition failed: `&s as &&str != &s` (\"\" vs \"\")"); - - let test = || Ok(ensure!(s as &'static str != s)); - assert_err( - test, - "Condition failed: `s as &'static str != s` (\"\" vs \"\")", - ); - - let test = || Ok(ensure!(&s as &&'static str != &s)); - assert_err( - test, - "Condition failed: `&s as &&'static str != &s` (\"\" vs \"\")", - ); - - let m: &mut str = Default::default(); - let test = || Ok(ensure!(m as &mut str != s)); - assert_err( - test, - "Condition failed: `m as &mut str != s` (\"\" vs \"\")", - ); - - let test = || Ok(ensure!(&m as &&mut str != &s)); - assert_err( - test, - "Condition failed: `&m as &&mut str != &s` (\"\" vs \"\")", - ); - - let test = || Ok(ensure!(&m as &&'static mut str != &s)); - assert_err( - test, - "Condition failed: `&m as &&'static mut str != &s` (\"\" vs \"\")", - ); - - let f = || {}; - let test = || Ok(ensure!(f as fn() as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `f as fn() as usize * 0 != 0` (0 vs 0)", - ); - - let test = || Ok(ensure!(f as fn() -> () as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `f as fn() -> () as usize * 0 != 0` (0 vs 0)", - ); - - let test = || Ok(ensure!(f as for<'a> fn() as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `f as for<'a> fn() as usize * 0 != 0` (0 vs 0)", - ); - - let test = || Ok(ensure!(f as unsafe fn() as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `f as unsafe fn() as usize * 0 != 0` (0 vs 0)", - ); - - #[rustfmt::skip] - let test = || Ok(ensure!(f as extern "Rust" fn() as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `f as extern \"Rust\" fn() as usize * 0 != 0` (0 vs 0)", - ); - - extern "C" fn extern_fn() {} - #[rustfmt::skip] - #[allow(missing_abi)] - let test = || Ok(ensure!(extern_fn as extern fn() as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `extern_fn as extern fn() as usize * 0 != 0` (0 vs 0)", - ); - - let f = || -> ! { panic!() }; - let test = || Ok(ensure!(f as fn() -> ! as usize * 0 != 0)); - assert_err( - test, - "Condition failed: `f as fn() -> ! as usize * 0 != 0` (0 vs 0)", - ); - - trait EqDebug: PartialEq + Debug { - type Assoc; - } - - impl EqDebug for S - where - S: PartialEq + Debug, - { - type Assoc = bool; - } - - let test = || Ok(ensure!(&0 as &dyn EqDebug != &0)); - assert_err( - test, - "Condition failed: `&0 as &dyn EqDebug != &0` (0 vs 0)", - ); - - let test = || { - Ok(ensure!( - PhantomData as PhantomData<::Owned> != PhantomData - )) - }; - assert_err( - test, - "Condition failed: `PhantomData as PhantomData<::Owned> != PhantomData` (PhantomData vs PhantomData)", - ); - - macro_rules! int { - (...) => { - u8 - }; - } - - let test = || Ok(ensure!(0 as int!(...) != 0)); - assert_err(test, "Condition failed: `0 as int!(...) != 0` (0 vs 0)"); - - let test = || Ok(ensure!(0 as int![...] != 0)); - assert_err(test, "Condition failed: `0 as int![...] != 0` (0 vs 0)"); - - let test = || Ok(ensure!(0 as int! {...} != 0)); - assert_err(test, "Condition failed: `0 as int! {...} != 0` (0 vs 0)"); -} - -#[test] -fn test_pat() { - let test = || Ok(ensure!(if let ref mut _x @ 0 = 0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let ref mut _x @ 0 = 0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let -1..=1 = 0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let -1..=1 = 0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let &0 = &0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let &0 = &0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let &&0 = &&0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let &&0 = &&0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let &mut 0 = &mut 0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let &mut 0 = &mut 0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let &&mut 0 = &&mut 0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let &&mut 0 = &&mut 0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let (0, 1) = (0, 1) { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let (0, 1) = (0, 1) { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let [0] = b"\0" { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let [0] = b\"\\0\" { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let p = PhantomData::; - let test = || Ok(ensure!(if let P:: {} = p { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let P:: {} = p { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(if let ::std::marker::PhantomData = p {} != ())); - assert_err( - test, - "Condition failed: `if let ::std::marker::PhantomData = p {} != ()` (() vs ())", - ); - - let test = || Ok(ensure!(if let ::V = 0 { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let ::V = 0 { 0 } else { 1 } == 1` (0 vs 1)", - ); - - let test = || Ok(ensure!(for _ in iter::once(()) {} != ())); - assert_err( - test, - "Condition failed: `for _ in iter::once(()) {} != ()` (() vs ())", - ); - - let test = || Ok(ensure!(if let stringify!(x) = "x" { 0 } else { 1 } == 1)); - assert_err( - test, - "Condition failed: `if let stringify!(x) = \"x\" { 0 } else { 1 } == 1` (0 vs 1)", - ); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_ffi.rs b/third_party/crates/anyhow-1.0.104/tests/test_ffi.rs deleted file mode 100644 index 59578af..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_ffi.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![deny(improper_ctypes, improper_ctypes_definitions)] -#![allow(clippy::uninlined_format_args)] - -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) { - *err = Some(anyhow!("ffi error")); -} - -#[no_mangle] -pub extern "C" fn anyhow3() -> Option { - Some(anyhow!("ffi error")) -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_fmt.rs b/third_party/crates/anyhow-1.0.104/tests/test_fmt.rs deleted file mode 100644 index 8206f22..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_fmt.rs +++ /dev/null @@ -1,93 +0,0 @@ -use anyhow::{bail, Context, Result}; -use std::io; - -fn f() -> Result<()> { - bail!(io::Error::new(io::ErrorKind::PermissionDenied, "oh no!")); -} - -fn g() -> Result<()> { - f().context("f failed") -} - -fn h() -> Result<()> { - g().context("g failed") -} - -const EXPECTED_ALTDISPLAY_F: &str = "oh no!"; - -const EXPECTED_ALTDISPLAY_G: &str = "f failed: oh no!"; - -const EXPECTED_ALTDISPLAY_H: &str = "g failed: f failed: oh no!"; - -const EXPECTED_DEBUG_F: &str = "oh no!"; - -const EXPECTED_DEBUG_G: &str = "\ -f failed - -Caused by: - oh no!\ -"; - -const EXPECTED_DEBUG_H: &str = "\ -g failed - -Caused by: - 0: f failed - 1: oh no!\ -"; - -const EXPECTED_ALTDEBUG_F: &str = "\ -Custom { - kind: PermissionDenied, - error: \"oh no!\", -}\ -"; - -const EXPECTED_ALTDEBUG_G: &str = "\ -Error { - context: \"f failed\", - source: Custom { - kind: PermissionDenied, - error: \"oh no!\", - }, -}\ -"; - -const EXPECTED_ALTDEBUG_H: &str = "\ -Error { - context: \"g failed\", - source: Error { - context: \"f failed\", - source: Custom { - kind: PermissionDenied, - error: \"oh no!\", - }, - }, -}\ -"; - -#[test] -fn test_display() { - assert_eq!("g failed", h().unwrap_err().to_string()); -} - -#[test] -fn test_altdisplay() { - assert_eq!(EXPECTED_ALTDISPLAY_F, format!("{:#}", f().unwrap_err())); - assert_eq!(EXPECTED_ALTDISPLAY_G, format!("{:#}", g().unwrap_err())); - assert_eq!(EXPECTED_ALTDISPLAY_H, format!("{:#}", h().unwrap_err())); -} - -#[test] -fn test_debug() { - assert_eq!(EXPECTED_DEBUG_F, format!("{:?}", f().unwrap_err())); - assert_eq!(EXPECTED_DEBUG_G, format!("{:?}", g().unwrap_err())); - assert_eq!(EXPECTED_DEBUG_H, format!("{:?}", h().unwrap_err())); -} - -#[test] -fn test_altdebug() { - assert_eq!(EXPECTED_ALTDEBUG_F, format!("{:#?}", f().unwrap_err())); - assert_eq!(EXPECTED_ALTDEBUG_G, format!("{:#?}", g().unwrap_err())); - assert_eq!(EXPECTED_ALTDEBUG_H, format!("{:#?}", h().unwrap_err())); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_macros.rs b/third_party/crates/anyhow-1.0.104/tests/test_macros.rs deleted file mode 100644 index 0689506..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_macros.rs +++ /dev/null @@ -1,97 +0,0 @@ -#![allow( - clippy::assertions_on_result_states, - clippy::eq_op, - clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257 - clippy::items_after_statements, - clippy::match_single_binding, - clippy::needless_pass_by_value, - clippy::shadow_unrelated, - clippy::uninlined_format_args, - clippy::wildcard_imports -)] - -mod common; - -use self::common::*; -use anyhow::{anyhow, ensure, Result}; -use std::cell::Cell; -use std::future; - -#[test] -fn test_messages() { - assert_eq!("oh no!", bail_literal().unwrap_err().to_string()); - assert_eq!("oh no!", bail_fmt().unwrap_err().to_string()); - assert_eq!("oh no!", bail_error().unwrap_err().to_string()); -} - -#[test] -fn test_ensure() { - let f = || { - ensure!(1 + 1 == 2, "This is correct"); - Ok(()) - }; - assert!(f().is_ok()); - - let v = 1; - let f = || { - ensure!(v + v == 2, "This is correct, v: {}", v); - Ok(()) - }; - assert!(f().is_ok()); - - let f = || { - ensure!(v + v == 1, "This is not correct, v: {}", v); - Ok(()) - }; - assert!(f().is_err()); - - let f = || { - ensure!(v + v == 1); - Ok(()) - }; - assert_eq!( - f().unwrap_err().to_string(), - "Condition failed: `v + v == 1` (2 vs 1)", - ); -} - -#[test] -fn test_ensure_nonbool() -> Result<()> { - struct Struct { - condition: bool, - } - - let s = Struct { condition: true }; - match &s { - Struct { condition } => ensure!(condition), // &bool - } - - Ok(()) -} - -#[test] -fn test_temporaries() { - fn require_send_sync(_: impl Send + Sync) {} - - require_send_sync(async { - // If anyhow hasn't dropped any temporary format_args it creates by the - // time it's done evaluating, those will stick around until the - // semicolon, which is on the other side of the await point, making the - // enclosing future non-Send. - future::ready(anyhow!("...")).await; - }); - - fn message(cell: Cell<&str>) -> &str { - cell.get() - } - - require_send_sync(async { - future::ready(anyhow!(message(Cell::new("...")))).await; - }); -} - -#[test] -fn test_brace_escape() { - let err = anyhow!("unterminated ${{..}} expression"); - assert_eq!("unterminated ${..} expression", err.to_string()); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_repr.rs b/third_party/crates/anyhow-1.0.104/tests/test_repr.rs deleted file mode 100644 index 2976cd8..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_repr.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![allow(clippy::extra_unused_type_parameters)] - -mod drop; - -use self::drop::{DetectDrop, Flag}; -use anyhow::Error; -use std::mem; - -#[test] -fn test_error_size() { - assert_eq!(mem::size_of::(), mem::size_of::()); -} - -#[test] -fn test_null_pointer_optimization() { - assert_eq!(mem::size_of::>(), mem::size_of::()); -} - -#[test] -fn test_autotraits() { - fn assert() {} - assert::(); -} - -#[test] -fn test_drop() { - let has_dropped = Flag::new(); - drop(Error::new(DetectDrop::new(&has_dropped))); - assert!(has_dropped.get()); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/test_source.rs b/third_party/crates/anyhow-1.0.104/tests/test_source.rs deleted file mode 100644 index 018267d..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/test_source.rs +++ /dev/null @@ -1,62 +0,0 @@ -use anyhow::anyhow; -use std::error::Error as StdError; -use std::fmt::{self, Display}; -use std::io; - -#[derive(Debug)] -enum TestError { - Io(io::Error), -} - -impl Display for TestError { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - match self { - TestError::Io(e) => Display::fmt(e, formatter), - } - } -} - -impl StdError for TestError { - fn source(&self) -> Option<&(dyn StdError + 'static)> { - match self { - TestError::Io(io) => Some(io), - } - } -} - -#[test] -fn test_literal_source() { - let error = anyhow!("oh no!"); - assert!(error.source().is_none()); -} - -#[test] -fn test_variable_source() { - let msg = "oh no!"; - let error = anyhow!(msg); - assert!(error.source().is_none()); - - let msg = msg.to_owned(); - let error = anyhow!(msg); - assert!(error.source().is_none()); -} - -#[test] -fn test_fmt_source() { - let error = anyhow!("{} {}!", "oh", "no"); - assert!(error.source().is_none()); -} - -#[test] -fn test_io_source() { - let io = io::Error::new(io::ErrorKind::Other, "oh no!"); - let error = anyhow!(TestError::Io(io)); - assert_eq!("oh no!", error.source().unwrap().to_string()); -} - -#[test] -fn test_anyhow_from_anyhow() { - let error = anyhow!("oh no!").context("context"); - let error = anyhow!(error); - assert_eq!("oh no!", error.source().unwrap().to_string()); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs b/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs deleted file mode 100644 index 4521b51..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.rs +++ /dev/null @@ -1,8 +0,0 @@ -use anyhow::{ensure, Result}; - -fn main() -> Result<()> { - // `ensure!` must not partition this into `(false) == (false == true)` - // because Rust doesn't ordinarily allow this form of expression. - ensure!(false == false == true); - Ok(()) -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr deleted file mode 100644 index 2a4c665..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/chained-comparison.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: comparison operators cannot be chained - --> tests/ui/chained-comparison.rs:6:19 - | -6 | ensure!(false == false == true); - | ^^ ^^ - | -help: split the comparison into two - | -6 | ensure!(false == false && false == true); - | ++++++++ diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs b/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs deleted file mode 100644 index 139b743..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.rs +++ /dev/null @@ -1,6 +0,0 @@ -use anyhow::{ensure, Result}; - -fn main() -> Result<()> { - ensure!(); - Ok(()) -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr deleted file mode 100644 index bf0229a..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/empty-ensure.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: unexpected end of macro invocation - --> tests/ui/empty-ensure.rs:4:5 - | -4 | ensure!(); - | ^^^^^^^^^ missing tokens in macro arguments - | -note: while trying to match meta-variable `$cond:expr` - --> src/ensure.rs - | - | ($cond:expr $(,)?) => { - | ^^^^^^^^^^ - = note: this error originates in the macro `$crate::__parse_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs b/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs deleted file mode 100644 index c7df4e1..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.rs +++ /dev/null @@ -1,40 +0,0 @@ -use anyhow::{ensure, Result}; -use std::ops::{Deref, Not}; - -struct Bool(bool); - -struct DerefBool(bool); - -struct NotBool(bool); - -impl Deref for DerefBool { - type Target = bool; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl Not for NotBool { - type Output = bool; - fn not(self) -> Self::Output { - !self.0 - } -} - -fn main() -> Result<()> { - ensure!("..."); - - let mut s = Bool(true); - match &mut s { - Bool(cond) => ensure!(cond), - } - - let db = DerefBool(true); - ensure!(db); - ensure!(&db); - - let nb = NotBool(true); - ensure!(nb); - - Ok(()) -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr deleted file mode 100644 index 5a4e0ec..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/ensure-nonbool.stderr +++ /dev/null @@ -1,113 +0,0 @@ -error[E0277]: the trait bound `&str: anyhow::__private::not::Bool` is not satisfied - --> tests/ui/ensure-nonbool.rs:25:13 - | -25 | ensure!("..."); - | --------^^^^^- - | | | - | | the trait `anyhow::__private::not::Bool` is not implemented for `&str` - | required by a bound introduced by this call - | -help: the following other types implement trait `anyhow::__private::not::Bool` - --> src/lib.rs - | - | impl Bool for bool { - | ^^^^^^^^^^^^^^^^^^ `bool` -... - | impl Bool for &bool { - | ^^^^^^^^^^^^^^^^^^^ `&bool` -note: required by a bound in `anyhow::__private::not` - --> src/lib.rs - | - | pub fn not(cond: impl Bool) -> bool { - | ^^^^ required by this bound in `not` - -error[E0277]: the trait bound `&mut bool: anyhow::__private::not::Bool` is not satisfied - --> tests/ui/ensure-nonbool.rs:29:31 - | -29 | Bool(cond) => ensure!(cond), - | --------^^^^- - | | | - | | the trait `anyhow::__private::not::Bool` is not implemented for `&mut bool` - | required by a bound introduced by this call - | - = note: `anyhow::__private::not::Bool` is implemented for `&bool`, but not for `&mut bool` -note: required by a bound in `anyhow::__private::not` - --> src/lib.rs - | - | pub fn not(cond: impl Bool) -> bool { - | ^^^^ required by this bound in `not` -help: consider dereferencing here - | -29 | Bool(cond) => ensure!(*cond), - | + - -error[E0277]: the trait bound `DerefBool: anyhow::__private::not::Bool` is not satisfied - --> tests/ui/ensure-nonbool.rs:33:13 - | -33 | ensure!(db); - | --------^^- - | | | - | | unsatisfied trait bound - | required by a bound introduced by this call - | -help: the trait `anyhow::__private::not::Bool` is not implemented for `DerefBool` - --> tests/ui/ensure-nonbool.rs:6:1 - | - 6 | struct DerefBool(bool); - | ^^^^^^^^^^^^^^^^ -note: required by a bound in `anyhow::__private::not` - --> src/lib.rs - | - | pub fn not(cond: impl Bool) -> bool { - | ^^^^ required by this bound in `not` -help: consider dereferencing here - | -33 | ensure!(*db); - | + - -error[E0277]: the trait bound `&DerefBool: anyhow::__private::not::Bool` is not satisfied - --> tests/ui/ensure-nonbool.rs:34:13 - | -34 | ensure!(&db); - | --------^^^- - | | | - | | the trait `anyhow::__private::not::Bool` is not implemented for `&DerefBool` - | required by a bound introduced by this call - | -note: required by a bound in `anyhow::__private::not` - --> src/lib.rs - | - | pub fn not(cond: impl Bool) -> bool { - | ^^^^ required by this bound in `not` -help: consider dereferencing here - | -34 | ensure!(&*db); - | + - -error[E0277]: the trait bound `NotBool: anyhow::__private::not::Bool` is not satisfied - --> tests/ui/ensure-nonbool.rs:37:13 - | -37 | ensure!(nb); - | --------^^- - | | | - | | unsatisfied trait bound - | required by a bound introduced by this call - | -help: the trait `anyhow::__private::not::Bool` is not implemented for `NotBool` - --> tests/ui/ensure-nonbool.rs:8:1 - | - 8 | struct NotBool(bool); - | ^^^^^^^^^^^^^^ -help: the following other types implement trait `anyhow::__private::not::Bool` - --> src/lib.rs - | - | impl Bool for bool { - | ^^^^^^^^^^^^^^^^^^ `bool` -... - | impl Bool for &bool { - | ^^^^^^^^^^^^^^^^^^^ `&bool` -note: required by a bound in `anyhow::__private::not` - --> src/lib.rs - | - | pub fn not(cond: impl Bool) -> bool { - | ^^^^ required by this bound in `not` diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs b/third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs deleted file mode 100644 index ea4e58f..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/must-use.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![deny(unused_must_use)] - -use anyhow::anyhow; - -fn main() -> anyhow::Result<()> { - if true { - // meant to write bail! - anyhow!("it failed"); - } - Ok(()) -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr deleted file mode 100644 index b2a3f31..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/must-use.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error: unused return value of `anyhow::__private::must_use` that must be used - --> tests/ui/must-use.rs:8:9 - | -8 | anyhow!("it failed"); - | ^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> tests/ui/must-use.rs:1:9 - | -1 | #![deny(unused_must_use)] - | ^^^^^^^^^^^^^^^ -help: use `let _ = ...` to ignore the resulting value - | -8 | let _ = anyhow!("it failed"); - | +++++++ diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs b/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs deleted file mode 100644 index d2e89af..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.rs +++ /dev/null @@ -1,8 +0,0 @@ -use anyhow::anyhow; - -#[derive(Debug)] -struct Error; - -fn main() { - let _ = anyhow!(Error); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr deleted file mode 100644 index 9b584df..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/no-impl.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error[E0599]: the method `anyhow_kind` exists for reference `&Error`, but its trait bounds were not satisfied - --> tests/ui/no-impl.rs:7:13 - | -4 | struct Error; - | ------------ doesn't satisfy `Error: Into`, `Error: anyhow::kind::TraitKind` or `Error: std::fmt::Display` -... -7 | let _ = anyhow!(Error); - | ^^^^^^^^^^^^^^ method cannot be called on `&Error` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `Error: Into` - which is required by `Error: anyhow::kind::TraitKind` - `Error: std::fmt::Display` - which is required by `&Error: anyhow::kind::AdhocKind` - `&Error: Into` - which is required by `&Error: anyhow::kind::TraitKind` -note: the traits `Into` and `std::fmt::Display` must be implemented - --> $RUST/core/src/fmt/mod.rs - | - | pub trait Display: PointeeSized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - ::: $RUST/core/src/convert/mod.rs - | - | pub const trait Into: Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = 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::BoxedKind` - candidate #3: `anyhow::kind::TraitKind` - = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs b/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs deleted file mode 100644 index 803809b..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.rs +++ /dev/null @@ -1,5 +0,0 @@ -use anyhow::anyhow; - -fn main() { - let _ = anyhow!(&String::new()); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr deleted file mode 100644 index c92ec92..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/temporary-value.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0716]: temporary value dropped while borrowed - --> tests/ui/temporary-value.rs:4:22 - | -4 | let _ = anyhow!(&String::new()); - | ---------^^^^^^^^^^^^^- - | | | - | | creates a temporary value which is freed while still in use - | temporary value is freed at the end of this statement - | argument requires that borrow lasts for `'static` - | -note: requirement that the value outlives `'static` introduced here - --> src/kind.rs - | - | M: Display + Debug + Send + Sync + 'static, - | ^^^^^^^ diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs b/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs deleted file mode 100644 index b870ca7..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.rs +++ /dev/null @@ -1,5 +0,0 @@ -use anyhow::{bail, Result}; - -fn main() -> Result<()> { - bail!("{} not found"); -} diff --git a/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr b/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr deleted file mode 100644 index 55a2964..0000000 --- a/third_party/crates/anyhow-1.0.104/tests/ui/wrong-interpolation.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: 1 positional argument in format string, but no arguments were given - --> tests/ui/wrong-interpolation.rs:4:12 - | -4 | bail!("{} not found"); - | ^^ diff --git a/third_party/crates/crates.bzl b/third_party/crates/crates.bzl index 0fd3a5e..837646b 100644 --- a/third_party/crates/crates.bzl +++ b/third_party/crates/crates.bzl @@ -315,16 +315,11 @@ _CRATE_EDITIONS = { _NORMAL_DEPENDENCIES = { "src/machoke": { - _COMMON_CONDITION: { - "anyhow": Label("//third_party/crates/anyhow-1.0.104:anyhow"), - }, }, } _NORMAL_ALIASES = { "src/machoke": { - _COMMON_CONDITION: { - }, }, } -- 2.47.3 From 0100c8e648b9a2759ad1b45d5867b22a61dcfccb Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 31 Aug 2026 18:46:42 -0400 Subject: [PATCH 3/5] docs: document Rust crate vendoring --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0d5a98c..1c8d394 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,49 @@ This is my monorepo, started in 2026. -## Monorepo Structure -``` -dev/ Monorepo root -├── .archive/ Archived projects -├── configs/ Declarative configuration -│ └── nixos/ NixOS hosts, modules, guests, registry, and secrets -├── docs/ Obsidian vault / Second brain -├── src/ Projects -│ └── tools/ Projects that are tools -└── third_party/ Open source tools, libraries or otherwise +## Monorepo structure + +```text +dev/ Monorepo root +├── bazel/ Bazel support files +├── configs/ Declarative configuration +│ └── nixos/ NixOS hosts, modules, guests, registry, and secrets +├── docs/ Repository documentation +├── src/ Projects +│ ├── dotfiles/ Home and system configuration +│ └── machoke/ Rust application +├── third_party/ External source and vendoring support +│ └── crates/ Generated Rust crate sources and Bazel targets +├── Cargo.lock Shared Rust dependency lockfile +├── Cargo.toml Rust workspace manifest +└── MODULE.bazel Bazel module definition ``` +## Rust dependencies + +The repository root contains one Cargo dependency graph. +Each Rust project declares its dependencies in its local `Cargo.toml` file. +Add each Rust project to the `members` list in the root `Cargo.toml` file. +Use explicit member paths because the Bazel generator does not expand workspace globs. + +Update the shared lockfile after changing a project manifest: + +```sh +cargo generate-lockfile +``` + +Regenerate local crate sources and Bazel targets: + +```sh +bazel run //third_party:vendor_crates +``` + +Reference each dependency with an explicit local Bazel label: + +```starlark +deps = ["//third_party/crates:crate_name"] +``` + +Commit the generated files under `third_party/crates/`. +Do not edit generated files manually. -- 2.47.3 From fae75849be3ea229a074ee1c6520b473befa079b Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 31 Aug 2026 18:47:03 -0400 Subject: [PATCH 4/5] docs: limit structure overview to directories --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1c8d394..a56cedc 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,8 @@ dev/ Monorepo root ├── src/ Projects │ ├── dotfiles/ Home and system configuration │ └── machoke/ Rust application -├── third_party/ External source and vendoring support -│ └── crates/ Generated Rust crate sources and Bazel targets -├── Cargo.lock Shared Rust dependency lockfile -├── Cargo.toml Rust workspace manifest -└── MODULE.bazel Bazel module definition +└── third_party/ External source and vendoring support + └── crates/ Generated Rust crate sources and Bazel targets ``` ## Rust dependencies -- 2.47.3 From 50f36e4a0960ba8cd5c5eb47b1fc6625f540d50a Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 31 Aug 2026 18:47:32 -0400 Subject: [PATCH 5/5] docs: simplify project structure overview --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index a56cedc..9991994 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ dev/ Monorepo root │ └── nixos/ NixOS hosts, modules, guests, registry, and secrets ├── docs/ Repository documentation ├── src/ Projects -│ ├── dotfiles/ Home and system configuration -│ └── machoke/ Rust application +│ └── dotfiles/ Home and system configuration └── third_party/ External source and vendoring support └── crates/ Generated Rust crate sources and Bazel targets ``` -- 2.47.3