diff --git a/Cargo.lock b/Cargo.lock index 097eae02..519466a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -309,7 +309,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -493,12 +493,12 @@ dependencies = [ "reqwest-middleware", "reqwest-retry", "tempfile", + "thiserror 2.0.9", "tokio", "tracing", "tracing-test", "url", "utils", - "xet_error", ] [[package]] @@ -514,10 +514,10 @@ dependencies = [ "merkledb", "merklehash", "rand 0.8.5", + "thiserror 2.0.9", "tokio", "tokio-util", "tracing", - "xet_error", ] [[package]] @@ -527,7 +527,7 @@ dependencies = [ "merklehash", "serde", "serde_repr", - "xet_error", + "thiserror 2.0.9", ] [[package]] @@ -572,10 +572,10 @@ dependencies = [ "once_cell", "rand 0.8.5", "tempdir", + "thiserror 2.0.9", "tokio", "tracing", "utils", - "xet_error", ] [[package]] @@ -650,7 +650,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -889,11 +889,11 @@ dependencies = [ "sha2", "static_assertions", "tempfile", + "thiserror 2.0.9", "tokio", - "toml 0.5.11", + "toml", "tracing", "utils", - "xet_error", ] [[package]] @@ -948,12 +948,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "dissimilar" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59f8e79d1fbf76bdfbde321e902714bf6c49df88a7dda6fc682fc2979226962d" - [[package]] name = "downcast" version = "0.11.0" @@ -1179,7 +1173,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -1876,11 +1870,11 @@ dependencies = [ "regex", "static_assertions", "tempdir", + "thiserror 2.0.9", "tokio", "tracing", "utils", "uuid", - "xet_error", ] [[package]] @@ -1911,10 +1905,10 @@ dependencies = [ "rustc-hash", "serde", "tempfile", + "thiserror 2.0.9", "tokio", "tracing", "walkdir", - "xet_error", ] [[package]] @@ -1990,7 +1984,7 @@ dependencies = [ "cfg-if 1.0.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -2085,7 +2079,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -2259,7 +2253,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -2401,9 +2395,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -2429,7 +2423,7 @@ dependencies = [ "memchr", "parking_lot 0.12.3", "protobuf", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -2560,27 +2554,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", -] - -[[package]] -name = "ref-cast" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.85", + "thiserror 1.0.65", ] [[package]] @@ -2733,7 +2707,7 @@ dependencies = [ "http 1.1.0", "reqwest 0.12.8", "serde", - "thiserror", + "thiserror 1.0.65", "tower-service", ] @@ -2947,7 +2921,7 @@ checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -2980,16 +2954,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", -] - -[[package]] -name = "serde_spanned" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" -dependencies = [ - "serde", + "syn 2.0.95", ] [[package]] @@ -3163,9 +3128,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", @@ -3238,12 +3203,6 @@ dependencies = [ "libc", ] -[[package]] -name = "target-triple" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a4d50cdb458045afc8131fd91b64904da29548bcb63c7236e0844936c13078" - [[package]] name = "tempdir" version = "0.3.7" @@ -3314,7 +3273,16 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.65", +] + +[[package]] +name = "thiserror" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +dependencies = [ + "thiserror-impl 2.0.9", ] [[package]] @@ -3325,7 +3293,18 @@ checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", ] [[package]] @@ -3398,7 +3377,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -3444,40 +3423,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" -dependencies = [ - "indexmap 2.6.0", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -3503,7 +3448,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -3563,7 +3508,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04659ddb06c87d233c566112c1c9c5b9e98256d9af50ec3bc9c8327f873a7568" dependencies = [ "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] @@ -3572,22 +3517,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "trybuild" -version = "1.0.101" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dcd332a5496c026f1e14b7f3d2b7bd98e509660c04239c58b0ba38a12daded4" -dependencies = [ - "dissimilar", - "glob", - "serde", - "serde_derive", - "serde_json", - "target-triple", - "termcolor", - "toml 0.8.19", -] - [[package]] name = "twox-hash" version = "1.6.3" @@ -3670,9 +3599,9 @@ dependencies = [ "parking_lot 0.11.2", "pin-project", "tempfile", + "thiserror 2.0.9", "tokio", "tracing", - "xet_error", ] [[package]] @@ -3761,7 +3690,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", "wasm-bindgen-shared", ] @@ -3795,7 +3724,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4070,15 +3999,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" -dependencies = [ - "memchr", -] - [[package]] name = "winreg" version = "0.50.0" @@ -4089,27 +4009,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "xet-error-impl" -version = "1.0.50" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.85", -] - -[[package]] -name = "xet_error" -version = "0.14.5" -dependencies = [ - "anyhow", - "lazy_static", - "ref-cast", - "rustversion", - "trybuild", - "xet-error-impl", -] - [[package]] name = "zerocopy" version = "0.7.35" @@ -4128,7 +4027,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.95", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d9d21292..311f1562 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ members = [ "parutils", "progress_reporting", "utils", - "xet_error", "cas_object", "cas_types", "chunk_cache", diff --git a/README.md b/README.md index 7f4e95c4..2fb3dc29 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,6 @@ Xet-core is the repo responsible for Rust-based code running on the client machi * [parutils](src/parutils): Provides parallel execution utilities relying on Tokio (ex. parallel foreach). * [progress_reporting](src/progress_reporting): offers ReportedWriter so progress for Writer operations can be displayed. * [utils](src/utils): general utilities - **unclear how much is currently in use** -* [xet_error](src/xet_error): Error utility crate, widely used for anyhow! logging in other crates. ## Local Development diff --git a/cas_client/Cargo.toml b/cas_client/Cargo.toml index 610e8aa6..4fcd8c13 100644 --- a/cas_client/Cargo.toml +++ b/cas_client/Cargo.toml @@ -18,7 +18,7 @@ utils = { path = "../utils" } merkledb = { path = "../merkledb" } mdb_shard = { path = "../mdb_shard" } merklehash = { path = "../merklehash" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" tokio = { version = "1.41", features = ["full"] } async-trait = "0.1.9" anyhow = "1" diff --git a/cas_client/src/error.rs b/cas_client/src/error.rs index f7f3709e..4a4e463c 100644 --- a/cas_client/src/error.rs +++ b/cas_client/src/error.rs @@ -1,5 +1,5 @@ use merklehash::MerkleHash; -use xet_error::Error; +use thiserror::Error; #[non_exhaustive] #[derive(Error, Debug)] diff --git a/cas_object/Cargo.toml b/cas_object/Cargo.toml index 5178514a..a70184b6 100644 --- a/cas_object/Cargo.toml +++ b/cas_object/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -xet_error = { path = "../xet_error" } +thiserror = "2.0" error_printer = { path = "../error_printer" } merkledb = { path = "../merkledb" } merklehash = { path = "../merklehash" } diff --git a/cas_object/src/error.rs b/cas_object/src/error.rs index 0d9e878d..1b44cfb0 100644 --- a/cas_object/src/error.rs +++ b/cas_object/src/error.rs @@ -1,7 +1,7 @@ use std::convert::Infallible; +use thiserror::Error; use tracing::warn; -use xet_error::Error; #[non_exhaustive] #[derive(Error, Debug)] diff --git a/cas_types/Cargo.toml b/cas_types/Cargo.toml index c573056d..4349104b 100644 --- a/cas_types/Cargo.toml +++ b/cas_types/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" [dependencies] merklehash = { path = "../merklehash" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" serde = { version = "1.0.208", features = ["derive"] } serde_repr = "0.1.19" diff --git a/cas_types/src/error.rs b/cas_types/src/error.rs index 9c6ac19c..bf53f7ea 100644 --- a/cas_types/src/error.rs +++ b/cas_types/src/error.rs @@ -1,4 +1,4 @@ -use xet_error::Error; +use thiserror::Error; #[non_exhaustive] #[derive(Error, Debug)] diff --git a/chunk_cache/Cargo.toml b/chunk_cache/Cargo.toml index ae64b653..9a95233a 100644 --- a/chunk_cache/Cargo.toml +++ b/chunk_cache/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] cas_types = { path = "../cas_types" } merklehash = { path = "../merklehash" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" error_printer = { path = "../error_printer" } file_utils = { path = "../file_utils" } utils = { path = "../utils" } diff --git a/chunk_cache/src/error.rs b/chunk_cache/src/error.rs index 802d556f..b1d07179 100644 --- a/chunk_cache/src/error.rs +++ b/chunk_cache/src/error.rs @@ -3,7 +3,7 @@ use std::str::Utf8Error; use base64::DecodeError; use merklehash::DataHashBytesParseError; -use xet_error::Error; +use thiserror::Error; #[derive(Debug, Error)] pub enum ChunkCacheError { diff --git a/chunk_cache_bench/Cargo.lock b/chunk_cache_bench/Cargo.lock index ad46c5d4..239d0804 100644 --- a/chunk_cache_bench/Cargo.lock +++ b/chunk_cache_bench/Cargo.lock @@ -314,7 +314,7 @@ dependencies = [ "merklehash", "serde", "serde_repr", - "xet_error", + "thiserror", ] [[package]] @@ -384,7 +384,7 @@ dependencies = [ "rand 0.8.5", "tracing", "utils", - "xet_error", + "thiserror", ] [[package]] @@ -3829,7 +3829,7 @@ dependencies = [ "pin-project", "tokio", "tracing", - "xet_error", + "thiserror", ] [[package]] @@ -4293,7 +4293,7 @@ dependencies = [ ] [[package]] -name = "xet_error" +name = "thiserror" version = "0.14.5" dependencies = [ "lazy_static", diff --git a/data/Cargo.toml b/data/Cargo.toml index 8dc97b94..232f96a8 100644 --- a/data/Cargo.toml +++ b/data/Cargo.toml @@ -21,7 +21,7 @@ utils = { path = "../utils" } parutils = { path = "../parutils" } file_utils = { path = "../file_utils" } error_printer = { path = "../error_printer" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" tokio = { version = "1.36", features = ["full"] } anyhow = "1" tracing = "0.1.*" diff --git a/data/src/errors.rs b/data/src/errors.rs index 074a7340..b310a5da 100644 --- a/data/src/errors.rs +++ b/data/src/errors.rs @@ -4,8 +4,9 @@ use std::sync::mpsc::RecvError; use cas_client::CasClientError; use mdb_shard::error::MDBShardError; use merkledb::error::MerkleDBError; +use thiserror::Error; +use tracing::error; use utils::errors::{AuthError, SingleflightError}; -use xet_error::Error; #[derive(Error, Debug)] pub enum DataProcessingError { @@ -79,7 +80,7 @@ pub type Result = std::result::Result; impl From> for DataProcessingError { fn from(value: SingleflightError) -> Self { let msg = format!("{value:?}"); - xet_error::error_hook(&msg); + error!("{msg}"); match value { SingleflightError::InternalError(e) => e, _ => DataProcessingError::InternalError(format!("SingleflightError: {msg}")), diff --git a/hf_xet/Cargo.lock b/hf_xet/Cargo.lock index e27756c9..e52333f5 100644 --- a/hf_xet/Cargo.lock +++ b/hf_xet/Cargo.lock @@ -229,7 +229,7 @@ dependencies = [ "tracing", "url", "utils", - "xet_error", + "thiserror", ] [[package]] @@ -248,7 +248,7 @@ dependencies = [ "tokio", "tokio-util", "tracing", - "xet_error", + "thiserror", ] [[package]] @@ -258,7 +258,7 @@ dependencies = [ "merklehash", "serde", "serde_repr", - "xet_error", + "thiserror", ] [[package]] @@ -303,7 +303,7 @@ dependencies = [ "rand 0.8.5", "tracing", "utils", - "xet_error", + "thiserror", ] [[package]] @@ -477,7 +477,7 @@ dependencies = [ "toml", "tracing", "utils", - "xet_error", + "thiserror", ] [[package]] @@ -1437,7 +1437,7 @@ dependencies = [ "tracing", "utils", "uuid", - "xet_error", + "thiserror", ] [[package]] @@ -1477,7 +1477,7 @@ dependencies = [ "tempfile", "tracing", "walkdir", - "xet_error", + "thiserror", ] [[package]] @@ -2977,7 +2977,7 @@ dependencies = [ "pin-project", "tokio", "tracing", - "xet_error", + "thiserror", ] [[package]] @@ -3401,7 +3401,7 @@ dependencies = [ ] [[package]] -name = "xet_error" +name = "thiserror" version = "0.14.5" dependencies = [ "lazy_static", diff --git a/mdb_shard/Cargo.toml b/mdb_shard/Cargo.toml index a66116bf..278b6406 100644 --- a/mdb_shard/Cargo.toml +++ b/mdb_shard/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] merklehash = { path = "../merklehash" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" utils = { path = "../utils" } tempdir = "0.3.7" tokio = { version = "1.36", features = ["full"] } diff --git a/mdb_shard/src/error.rs b/mdb_shard/src/error.rs index 55b670a3..f22ea321 100644 --- a/mdb_shard/src/error.rs +++ b/mdb_shard/src/error.rs @@ -1,7 +1,7 @@ use std::io; use merklehash::MerkleHash; -use xet_error::Error; +use thiserror::Error; #[non_exhaustive] #[derive(Error, Debug)] diff --git a/merkledb/Cargo.toml b/merkledb/Cargo.toml index 1bd24a4b..1b84b75b 100644 --- a/merkledb/Cargo.toml +++ b/merkledb/Cargo.toml @@ -10,7 +10,7 @@ doctest = false [dependencies] merklehash = { path = "../merklehash" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" parutils = { path = "../parutils" } rand = "0.8.5" rand_core = "0.6.3" diff --git a/merkledb/src/error.rs b/merkledb/src/error.rs index 6f9b5dd9..7feaa85a 100644 --- a/merkledb/src/error.rs +++ b/merkledb/src/error.rs @@ -1,6 +1,6 @@ use std::io; -use xet_error::Error; +use thiserror::Error; #[derive(Error, Debug)] pub enum MerkleDBError { diff --git a/utils/Cargo.toml b/utils/Cargo.toml index 3fd8df44..3532a108 100644 --- a/utils/Cargo.toml +++ b/utils/Cargo.toml @@ -9,7 +9,7 @@ path = "src/lib.rs" [dependencies] merklehash = { path = "../merklehash" } -xet_error = { path = "../xet_error" } +thiserror = "2.0" futures = "0.3.28" # singleflight & threadpool diff --git a/utils/src/errors.rs b/utils/src/errors.rs index 8d0c8c0b..92d60277 100644 --- a/utils/src/errors.rs +++ b/utils/src/errors.rs @@ -1,4 +1,4 @@ -use xet_error::Error; +use thiserror::Error; #[derive(Debug, Error)] #[non_exhaustive] diff --git a/utils/src/threadpool.rs b/utils/src/threadpool.rs index e7c64e70..861b770c 100644 --- a/utils/src/threadpool.rs +++ b/utils/src/threadpool.rs @@ -3,6 +3,7 @@ use std::future::Future; use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use thiserror::Error; /// This module provides a simple wrapper around Tokio's runtime to create a thread pool /// with some default settings. It is intended to be used as a singleton thread pool for /// the entire application. @@ -52,7 +53,6 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use tokio; use tokio::task::{JoinError, JoinHandle}; use tracing::{debug, error}; -use xet_error::Error; const THREADPOOL_NUM_WORKER_THREADS: usize = 4; // 4 active threads const THREADPOOL_THREAD_ID_PREFIX: &str = "hf-xet"; // thread names will be hf-xet-0, hf-xet-1, etc. diff --git a/xet_error/.github/workflows/ci.yml b/xet_error/.github/workflows/ci.yml deleted file mode 100644 index c67e7fca..00000000 --- a/xet_error/.github/workflows/ci.yml +++ /dev/null @@ -1,105 +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.56.0] - timeout-minutes: 45 - steps: - - uses: actions/checkout@v4 - - 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=xet_error_nightly_testing >> $GITHUB_ENV - if: matrix.rust == 'nightly' - - run: cargo test --all - - minimal: - name: Minimal versions - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@nightly - - run: cargo generate-lockfile -Z minimal-versions - - run: cargo check --locked - - 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@v4 - - 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@v4 - - uses: dtolnay/rust-toolchain@nightly - with: - components: clippy, rust-src - - run: cargo clippy --tests --workspace -- -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@v4 - - 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@v4 - - uses: dtolnay/install@cargo-outdated - - run: cargo outdated --workspace --exit-code 1 diff --git a/xet_error/.gitignore b/xet_error/.gitignore deleted file mode 100644 index 69369904..00000000 --- a/xet_error/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock diff --git a/xet_error/Cargo.toml b/xet_error/Cargo.toml deleted file mode 100644 index 31806e8d..00000000 --- a/xet_error/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "xet_error" -version = "0.14.5" -authors = ["David Tolnay "] -categories = ["rust-patterns"] -description = "derive(Error)" -documentation = "https://docs.rs/thiserror" -edition = "2021" -keywords = ["error", "error-handling", "derive"] -license = "MIT OR Apache-2.0" -repository = "https://github.com/dtolnay/thiserror" -rust-version = "1.56" - -[dependencies] -xet-error-impl = { version = "=1.0.50", path = "impl" } -lazy_static = "1.4.0" - -[dev-dependencies] -anyhow = "1.0.73" -ref-cast = "1.0.18" -rustversion = "1.0.13" -trybuild = { version = "1.0.81", features = ["diff"] } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = ["--generate-link-to-definition"] - -[features] -error_generic_member_access = [] diff --git a/xet_error/LICENSE-APACHE b/xet_error/LICENSE-APACHE deleted file mode 100644 index 1b5ec8b7..00000000 --- a/xet_error/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/xet_error/LICENSE-MIT b/xet_error/LICENSE-MIT deleted file mode 100644 index 31aa7938..00000000 --- a/xet_error/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/xet_error/README.md b/xet_error/README.md deleted file mode 100644 index de95d042..00000000 --- a/xet_error/README.md +++ /dev/null @@ -1,227 +0,0 @@ -Xet_error -========= - -This is a local source drop of the thiserror package, with hooks installed for error reporting and tracing. - -derive(Error) -============= - -[github](https://github.com/dtolnay/thiserror) -[crates.io](https://crates.io/crates/thiserror) -[docs.rs](https://docs.rs/thiserror) -[build status](https://github.com/dtolnay/thiserror/actions?query=branch%3Amaster) - -This library provides a convenient derive macro for the standard library's -[`std::error::Error`] trait. - -[`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html - -```toml -[dependencies] -thiserror = "1.0" -``` - -*Compiler support: requires rustc 1.56+* - -
- -## Example - -```rust -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum DataStoreError { - #[error("data store disconnected")] - Disconnect(#[from] io::Error), - #[error("the data for key `{0}` is not available")] - Redaction(String), - #[error("invalid header (expected {expected:?}, found {found:?})")] - InvalidHeader { - expected: String, - found: String, - }, - #[error("unknown data store error")] - Unknown, -} -``` - -
- -## Details - -- Thiserror deliberately does not appear in your public API. You get the same - thing as if you had written an implementation of `std::error::Error` by hand, - and switching from handwritten impls to thiserror or vice versa is not a - breaking change. - -- Errors may be enums, structs with named fields, tuple structs, or unit - structs. - -- A `Display` impl is generated for your error if you provide `#[error("...")]` - messages on the struct or each variant of your enum, as shown above in the - example. - - The messages support a shorthand for interpolating fields from the error. - - - `#[error("{var}")]` ⟶ `write!("{}", self.var)` - - `#[error("{0}")]` ⟶ `write!("{}", self.0)` - - `#[error("{var:?}")]` ⟶ `write!("{:?}", self.var)` - - `#[error("{0:?}")]` ⟶ `write!("{:?}", self.0)` - - These shorthands can be used together with any additional format args, which - may be arbitrary expressions. For example: - - ```rust - #[derive(Error, Debug)] - pub enum Error { - #[error("invalid rdo_lookahead_frames {0} (expected < {})", i32::MAX)] - InvalidLookahead(u32), - } - ``` - - If one of the additional expression arguments needs to refer to a field of the - struct or enum, then refer to named fields as `.var` and tuple fields as `.0`. - - ```rust - #[derive(Error, Debug)] - pub enum Error { - #[error("first letter must be lowercase but was {:?}", first_char(.0))] - WrongCase(String), - #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)] - OutOfBounds { idx: usize, limits: Limits }, - } - ``` - -- A `From` impl is generated for each variant containing a `#[from]` attribute. - - Note that the variant must not contain any other fields beyond the source - error and possibly a backtrace. A backtrace is captured from within the `From` - impl if there is a field for it. - - ```rust - #[derive(Error, Debug)] - pub enum MyError { - Io { - #[from] - source: io::Error, - backtrace: Backtrace, - }, - } - ``` - -- The Error trait's `source()` method is implemented to return whichever field - has a `#[source]` attribute or is named `source`, if any. This is for - identifying the underlying lower level error that caused your error. - - The `#[from]` attribute always implies that the same field is `#[source]`, so - you don't ever need to specify both attributes. - - Any error type that implements `std::error::Error` or dereferences to `dyn - std::error::Error` will work as a source. - - ```rust - #[derive(Error, Debug)] - pub struct MyError { - msg: String, - #[source] // optional if field name is `source` - source: anyhow::Error, - } - ``` - -- The Error trait's `provide()` method is implemented to provide whichever field - has a type named `Backtrace`, if any, as a `std::backtrace::Backtrace`. - - ```rust - use std::backtrace::Backtrace; - - #[derive(Error, Debug)] - pub struct MyError { - msg: String, - backtrace: Backtrace, // automatically detected - } - ``` - -- If a field is both a source (named `source`, or has `#[source]` or `#[from]` - attribute) *and* is marked `#[backtrace]`, then the Error trait's `provide()` - method is forwarded to the source's `provide` so that both layers of the error - share the same backtrace. - - ```rust - #[derive(Error, Debug)] - pub enum MyError { - Io { - #[backtrace] - source: io::Error, - }, - } - ``` - -- Errors may use `error(transparent)` to forward the source and Display methods - straight through to an underlying error without adding an additional message. - This would be appropriate for enums that need an "anything else" variant. - - ```rust - #[derive(Error, Debug)] - pub enum MyError { - ... - - #[error(transparent)] - Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error - } - ``` - - Another use case is hiding implementation details of an error representation - behind an opaque error type, so that the representation is able to evolve - without breaking the crate's public API. - - ```rust - // PublicError is public, but opaque and easy to keep compatible. - #[derive(Error, Debug)] - #[error(transparent)] - pub struct PublicError(#[from] ErrorRepr); - - impl PublicError { - // Accessors for anything we do want to expose publicly. - } - - // Private and free to change across minor version of the crate. - #[derive(Error, Debug)] - enum ErrorRepr { - ... - } - ``` - -- See also the [`anyhow`] library for a convenient single error type to use in - application code. - - [`anyhow`]: https://github.com/dtolnay/anyhow - -
- -## Comparison to anyhow - -Use thiserror if you care about designing your own dedicated error type(s) so -that the caller receives exactly the information that you choose in the event of -failure. This most often applies to library-like code. 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-like code. - -[Anyhow]: https://github.com/dtolnay/anyhow - -
- -#### 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/xet_error/_git/HEAD b/xet_error/_git/HEAD deleted file mode 100644 index cb089cd8..00000000 --- a/xet_error/_git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/xet_error/_git/config b/xet_error/_git/config deleted file mode 100644 index 7d076b13..00000000 --- a/xet_error/_git/config +++ /dev/null @@ -1,13 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true - ignorecase = true - precomposeunicode = true -[remote "origin"] - url = git@github.com:dtolnay/thiserror.git - fetch = +refs/heads/*:refs/remotes/origin/* -[branch "master"] - remote = origin - merge = refs/heads/master diff --git a/xet_error/_git/description b/xet_error/_git/description deleted file mode 100644 index 498b267a..00000000 --- a/xet_error/_git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/xet_error/_git/hooks/applypatch-msg.sample b/xet_error/_git/hooks/applypatch-msg.sample deleted file mode 100755 index a5d7b84a..00000000 --- a/xet_error/_git/hooks/applypatch-msg.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message taken by -# applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. The hook is -# allowed to edit the commit message file. -# -# To enable this hook, rename this file to "applypatch-msg". - -. git-sh-setup -commitmsg="$(git rev-parse --git-path hooks/commit-msg)" -test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} -: diff --git a/xet_error/_git/hooks/commit-msg.sample b/xet_error/_git/hooks/commit-msg.sample deleted file mode 100755 index b58d1184..00000000 --- a/xet_error/_git/hooks/commit-msg.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message. -# Called by "git commit" with one argument, the name of the file -# that has the commit message. The hook should exit with non-zero -# status after issuing an appropriate message if it wants to stop the -# commit. The hook is allowed to edit the commit message file. -# -# To enable this hook, rename this file to "commit-msg". - -# Uncomment the below to add a Signed-off-by line to the message. -# Doing this in a hook is a bad idea in general, but the prepare-commit-msg -# hook is more suited to it. -# -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/xet_error/_git/hooks/fsmonitor-watchman.sample b/xet_error/_git/hooks/fsmonitor-watchman.sample deleted file mode 100755 index 23e856f5..00000000 --- a/xet_error/_git/hooks/fsmonitor-watchman.sample +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use IPC::Open2; - -# An example hook script to integrate Watchman -# (https://facebook.github.io/watchman/) with git to speed up detecting -# new and modified files. -# -# The hook is passed a version (currently 2) and last update token -# formatted as a string and outputs to stdout a new update token and -# all files that have been modified since the update token. Paths must -# be relative to the root of the working tree and separated by a single NUL. -# -# To enable this hook, rename this file to "query-watchman" and set -# 'git config core.fsmonitor .git/hooks/query-watchman' -# -my ($version, $last_update_token) = @ARGV; - -# Uncomment for debugging -# print STDERR "$0 $version $last_update_token\n"; - -# Check the hook interface version -if ($version ne 2) { - die "Unsupported query-fsmonitor hook version '$version'.\n" . - "Falling back to scanning...\n"; -} - -my $git_work_tree = get_working_dir(); - -my $retry = 1; - -my $json_pkg; -eval { - require JSON::XS; - $json_pkg = "JSON::XS"; - 1; -} or do { - require JSON::PP; - $json_pkg = "JSON::PP"; -}; - -launch_watchman(); - -sub launch_watchman { - my $o = watchman_query(); - if (is_work_tree_watched($o)) { - output_result($o->{clock}, @{$o->{files}}); - } -} - -sub output_result { - my ($clockid, @files) = @_; - - # Uncomment for debugging watchman output - # open (my $fh, ">", ".git/watchman-output.out"); - # binmode $fh, ":utf8"; - # print $fh "$clockid\n@files\n"; - # close $fh; - - binmode STDOUT, ":utf8"; - print $clockid; - print "\0"; - local $, = "\0"; - print @files; -} - -sub watchman_clock { - my $response = qx/watchman clock "$git_work_tree"/; - die "Failed to get clock id on '$git_work_tree'.\n" . - "Falling back to scanning...\n" if $? != 0; - - return $json_pkg->new->utf8->decode($response); -} - -sub watchman_query { - my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') - or die "open2() failed: $!\n" . - "Falling back to scanning...\n"; - - # In the query expression below we're asking for names of files that - # changed since $last_update_token but not from the .git folder. - # - # To accomplish this, we're using the "since" generator to use the - # recency index to select candidate nodes and "fields" to limit the - # output to file names only. Then we're using the "expression" term to - # further constrain the results. - my $last_update_line = ""; - if (substr($last_update_token, 0, 1) eq "c") { - $last_update_token = "\"$last_update_token\""; - $last_update_line = qq[\n"since": $last_update_token,]; - } - my $query = <<" END"; - ["query", "$git_work_tree", {$last_update_line - "fields": ["name"], - "expression": ["not", ["dirname", ".git"]] - }] - END - - # Uncomment for debugging the watchman query - # open (my $fh, ">", ".git/watchman-query.json"); - # print $fh $query; - # close $fh; - - print CHLD_IN $query; - close CHLD_IN; - my $response = do {local $/; }; - - # Uncomment for debugging the watch response - # open ($fh, ">", ".git/watchman-response.json"); - # print $fh $response; - # close $fh; - - die "Watchman: command returned no output.\n" . - "Falling back to scanning...\n" if $response eq ""; - die "Watchman: command returned invalid output: $response\n" . - "Falling back to scanning...\n" unless $response =~ /^\{/; - - return $json_pkg->new->utf8->decode($response); -} - -sub is_work_tree_watched { - my ($output) = @_; - my $error = $output->{error}; - if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { - $retry--; - my $response = qx/watchman watch "$git_work_tree"/; - die "Failed to make watchman watch '$git_work_tree'.\n" . - "Falling back to scanning...\n" if $? != 0; - $output = $json_pkg->new->utf8->decode($response); - $error = $output->{error}; - die "Watchman: $error.\n" . - "Falling back to scanning...\n" if $error; - - # Uncomment for debugging watchman output - # open (my $fh, ">", ".git/watchman-output.out"); - # close $fh; - - # Watchman will always return all files on the first query so - # return the fast "everything is dirty" flag to git and do the - # Watchman query just to get it over with now so we won't pay - # the cost in git to look up each individual file. - my $o = watchman_clock(); - $error = $output->{error}; - - die "Watchman: $error.\n" . - "Falling back to scanning...\n" if $error; - - output_result($o->{clock}, ("/")); - $last_update_token = $o->{clock}; - - eval { launch_watchman() }; - return 0; - } - - die "Watchman: $error.\n" . - "Falling back to scanning...\n" if $error; - - return 1; -} - -sub get_working_dir { - my $working_dir; - if ($^O =~ 'msys' || $^O =~ 'cygwin') { - $working_dir = Win32::GetCwd(); - $working_dir =~ tr/\\/\//; - } else { - require Cwd; - $working_dir = Cwd::cwd(); - } - - return $working_dir; -} diff --git a/xet_error/_git/hooks/post-update.sample b/xet_error/_git/hooks/post-update.sample deleted file mode 100755 index ec17ec19..00000000 --- a/xet_error/_git/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/xet_error/_git/hooks/pre-applypatch.sample b/xet_error/_git/hooks/pre-applypatch.sample deleted file mode 100755 index 4142082b..00000000 --- a/xet_error/_git/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -precommit="$(git rev-parse --git-path hooks/pre-commit)" -test -x "$precommit" && exec "$precommit" ${1+"$@"} -: diff --git a/xet_error/_git/hooks/pre-commit.sample b/xet_error/_git/hooks/pre-commit.sample deleted file mode 100755 index e144712c..00000000 --- a/xet_error/_git/hooks/pre-commit.sample +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=$(git hash-object -t tree /dev/null) -fi - -# If you want to allow non-ASCII filenames set this variable to true. -allownonascii=$(git config --type=bool hooks.allownonascii) - -# Redirect output to stderr. -exec 1>&2 - -# Cross platform projects tend to avoid non-ASCII filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test $(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 -then - cat <<\EOF -Error: Attempt to add a non-ASCII file name. - -This can cause problems if you want to work with people on other platforms. - -To be portable it is advisable to rename the file. - -If you know what you are doing you can disable this check using: - - git config hooks.allownonascii true -EOF - exit 1 -fi - -# If there are whitespace errors, print the offending file names and fail. -exec git diff-index --check --cached $against -- diff --git a/xet_error/_git/hooks/pre-merge-commit.sample b/xet_error/_git/hooks/pre-merge-commit.sample deleted file mode 100755 index 399eab19..00000000 --- a/xet_error/_git/hooks/pre-merge-commit.sample +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git merge" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message to -# stderr if it wants to stop the merge commit. -# -# To enable this hook, rename this file to "pre-merge-commit". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" -: diff --git a/xet_error/_git/hooks/pre-push.sample b/xet_error/_git/hooks/pre-push.sample deleted file mode 100755 index 4ce688d3..00000000 --- a/xet_error/_git/hooks/pre-push.sample +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -# An example hook script to verify what is about to be pushed. Called by "git -# push" after it has checked the remote status, but before anything has been -# pushed. If this script exits with a non-zero status nothing will be pushed. -# -# This hook is called with the following parameters: -# -# $1 -- Name of the remote to which the push is being done -# $2 -- URL to which the push is being done -# -# If pushing without using a named remote those arguments will be equal. -# -# Information about the commits which are being pushed is supplied as lines to -# the standard input in the form: -# -# -# -# This sample shows how to prevent push of commits where the log message starts -# with "WIP" (work in progress). - -remote="$1" -url="$2" - -zero=$(git hash-object --stdin &2 "Found WIP commit in $local_ref, not pushing" - exit 1 - fi - fi -done - -exit 0 diff --git a/xet_error/_git/hooks/pre-rebase.sample b/xet_error/_git/hooks/pre-rebase.sample deleted file mode 100755 index 6cbef5c3..00000000 --- a/xet_error/_git/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up to date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -<<\DOC_END - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". - -DOC_END diff --git a/xet_error/_git/hooks/pre-receive.sample b/xet_error/_git/hooks/pre-receive.sample deleted file mode 100755 index a1fd29ec..00000000 --- a/xet_error/_git/hooks/pre-receive.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to make use of push options. -# The example simply echoes all push options that start with 'echoback=' -# and rejects all pushes when the "reject" push option is used. -# -# To enable this hook, rename this file to "pre-receive". - -if test -n "$GIT_PUSH_OPTION_COUNT" -then - i=0 - while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" - do - eval "value=\$GIT_PUSH_OPTION_$i" - case "$value" in - echoback=*) - echo "echo from the pre-receive-hook: ${value#*=}" >&2 - ;; - reject) - exit 1 - esac - i=$((i + 1)) - done -fi diff --git a/xet_error/_git/hooks/prepare-commit-msg.sample b/xet_error/_git/hooks/prepare-commit-msg.sample deleted file mode 100755 index 10fa14c5..00000000 --- a/xet_error/_git/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first one removes the -# "# Please enter the commit message..." help message. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -COMMIT_MSG_FILE=$1 -COMMIT_SOURCE=$2 -SHA1=$3 - -/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" - -# case "$COMMIT_SOURCE,$SHA1" in -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; -# *) ;; -# esac - -# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" -# if test -z "$COMMIT_SOURCE" -# then -# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" -# fi diff --git a/xet_error/_git/hooks/push-to-checkout.sample b/xet_error/_git/hooks/push-to-checkout.sample deleted file mode 100755 index af5a0c00..00000000 --- a/xet_error/_git/hooks/push-to-checkout.sample +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -# An example hook script to update a checked-out tree on a git push. -# -# This hook is invoked by git-receive-pack(1) when it reacts to git -# push and updates reference(s) in its repository, and when the push -# tries to update the branch that is currently checked out and the -# receive.denyCurrentBranch configuration variable is set to -# updateInstead. -# -# By default, such a push is refused if the working tree and the index -# of the remote repository has any difference from the currently -# checked out commit; when both the working tree and the index match -# the current commit, they are updated to match the newly pushed tip -# of the branch. This hook is to be used to override the default -# behaviour; however the code below reimplements the default behaviour -# as a starting point for convenient modification. -# -# The hook receives the commit with which the tip of the current -# branch is going to be updated: -commit=$1 - -# It can exit with a non-zero status to refuse the push (when it does -# so, it must not modify the index or the working tree). -die () { - echo >&2 "$*" - exit 1 -} - -# Or it can make any necessary changes to the working tree and to the -# index to bring them to the desired state when the tip of the current -# branch is updated to the new commit, and exit with a zero status. -# -# For example, the hook can simply run git read-tree -u -m HEAD "$1" -# in order to emulate git fetch that is run in the reverse direction -# with git push, as the two-tree form of git read-tree -u -m is -# essentially the same as git switch or git checkout that switches -# branches while keeping the local changes in the working tree that do -# not interfere with the difference between the branches. - -# The below is a more-or-less exact translation to shell of the C code -# for the default behaviour for git's push-to-checkout hook defined in -# the push_to_deploy() function in builtin/receive-pack.c. -# -# Note that the hook will be executed from the repository directory, -# not from the working tree, so if you want to perform operations on -# the working tree, you will have to adapt your code accordingly, e.g. -# by adding "cd .." or using relative paths. - -if ! git update-index -q --ignore-submodules --refresh -then - die "Up-to-date check failed" -fi - -if ! git diff-files --quiet --ignore-submodules -- -then - die "Working directory has unstaged changes" -fi - -# This is a rough translation of: -# -# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX -if git cat-file -e HEAD 2>/dev/null -then - head=HEAD -else - head=$(git hash-object -t tree --stdin &2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --type=bool hooks.allowunannotated) -allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch) -denycreatebranch=$(git config --type=bool hooks.denycreatebranch) -allowdeletetag=$(git config --type=bool hooks.allowdeletetag) -allowmodifytag=$(git config --type=bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero=$(git hash-object --stdin &2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/xet_error/_git/index b/xet_error/_git/index deleted file mode 100644 index 7c89b61e..00000000 Binary files a/xet_error/_git/index and /dev/null differ diff --git a/xet_error/_git/info/exclude b/xet_error/_git/info/exclude deleted file mode 100644 index a5196d1b..00000000 --- a/xet_error/_git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/xet_error/_git/logs/HEAD b/xet_error/_git/logs/HEAD deleted file mode 100644 index a4c80ab5..00000000 --- a/xet_error/_git/logs/HEAD +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 e9ea67c7e251764c3c2d839b6c06d9f35b154647 Hoyt Koepke 1701979145 -0800 clone: from github.com:dtolnay/thiserror.git diff --git a/xet_error/_git/logs/refs/heads/master b/xet_error/_git/logs/refs/heads/master deleted file mode 100644 index a4c80ab5..00000000 --- a/xet_error/_git/logs/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 e9ea67c7e251764c3c2d839b6c06d9f35b154647 Hoyt Koepke 1701979145 -0800 clone: from github.com:dtolnay/thiserror.git diff --git a/xet_error/_git/logs/refs/remotes/origin/HEAD b/xet_error/_git/logs/refs/remotes/origin/HEAD deleted file mode 100644 index a4c80ab5..00000000 --- a/xet_error/_git/logs/refs/remotes/origin/HEAD +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 e9ea67c7e251764c3c2d839b6c06d9f35b154647 Hoyt Koepke 1701979145 -0800 clone: from github.com:dtolnay/thiserror.git diff --git a/xet_error/_git/objects/pack/pack-81ea73449d91d43b55b4cc3c27f14c04e0583fd5.idx b/xet_error/_git/objects/pack/pack-81ea73449d91d43b55b4cc3c27f14c04e0583fd5.idx deleted file mode 100644 index 3b608a3a..00000000 Binary files a/xet_error/_git/objects/pack/pack-81ea73449d91d43b55b4cc3c27f14c04e0583fd5.idx and /dev/null differ diff --git a/xet_error/_git/objects/pack/pack-81ea73449d91d43b55b4cc3c27f14c04e0583fd5.pack b/xet_error/_git/objects/pack/pack-81ea73449d91d43b55b4cc3c27f14c04e0583fd5.pack deleted file mode 100644 index f27bb9e6..00000000 Binary files a/xet_error/_git/objects/pack/pack-81ea73449d91d43b55b4cc3c27f14c04e0583fd5.pack and /dev/null differ diff --git a/xet_error/_git/packed-refs b/xet_error/_git/packed-refs deleted file mode 100644 index c000fac6..00000000 --- a/xet_error/_git/packed-refs +++ /dev/null @@ -1,104 +0,0 @@ -# pack-refs with: peeled fully-peeled sorted -e9ea67c7e251764c3c2d839b6c06d9f35b154647 refs/remotes/origin/master -224faec8ab7f91ce07ac19021074edcec4af6523 refs/tags/1.0.0 -^86f6b3bc4a4083434dcafe467f60abda0c2fbfc4 -a1f59e471a2558bdf5e13186f9d532cf8cc6cf98 refs/tags/1.0.1 -^87c80e72c803f6fccb7ad36cae9be33ee143704b -1bc27180c8d3183c903e0b0ea6347d9d950029fb refs/tags/1.0.10 -^ccbb2ab862cdff9912a438aca9c54d5945e20351 -1879eacc1ad0a3ab865f44fdab1364f7b2a299e9 refs/tags/1.0.11 -^55d6fbb46032887f21e9c387671e01bca5392818 -8f711d2464bc8b3c2c50915c77e15216942c68df refs/tags/1.0.12 -^e160f5d90878bb81005ba24876d025f88aec066b -a25f699d27a9e4f5a7156bff25a9fb5396a48180 refs/tags/1.0.13 -^14b54d22564bbb6d75ddcc6fc732e1f6cf882311 -39cfbb8aded4ccd9228d33e38617e87c01eb24da refs/tags/1.0.14 -^6fd405929807e73ac4b1bd026192a91f64a08636 -11a589eddfae8c0a40cfadb4c4176adab0e219f4 refs/tags/1.0.15 -^d8d55e6655fa31a80d8852d7c4146ff1c839c014 -f06fe299e106bf91dfd7e98791c32394a634f569 refs/tags/1.0.16 -^94e62a81bc6da67efb06a45a8f45caf49768d5e4 -35d5607e3913a8e0a293b6848de0e5bbad8d9bbd refs/tags/1.0.17 -^f79a85f72be0a04644b392acf1ba7f97380c1e4f -7bd36700988a4f8c9efde08fdc188f84f09afbb4 refs/tags/1.0.18 -^25632e8afb175cd3bed58d5723bd8e927c9c6c90 -ad0459b00e4d9329026dd018345883d9057c889a refs/tags/1.0.19 -^8305a8cc8a1024aa657ae17ab65c040865bedd2a -cacf444a0d2a8cc68987c5011f91286f043fdd33 refs/tags/1.0.2 -^ee864e16419ae8a6e8ded983b53fc4514262d449 -059125bccb3e69d6653e2d0ccf2f2f472f80cd0c refs/tags/1.0.20 -^42b537acf08de385dcf6138f24e3274ff8a18148 -d6b8873a64fb1bfc1ef74ca8311f3c9f925623af refs/tags/1.0.21 -^f757a0489b2cddfea15ab870b49f159ce1aa71cd -6f7cf6fb5f7ff993f42949cddf4bbed2c76eeb2f refs/tags/1.0.22 -^09f247addaf6c5f57353f9558ba131e6619390c7 -9833025380d1892a39616e34a4f2f8610067b36e refs/tags/1.0.23 -^d263b4b7e4f8e3ad9558256d8f6b2ac916985f7b -49d87f0ffd4c8f957128ba8ca034d0981d728e85 refs/tags/1.0.24 -^1b0a84996b9492c0dc5779127a91c930f23a259e -4a1604743b75f662df9d884584540e8c8813c5b5 refs/tags/1.0.25 -^19cb5cee4b51203f6801daa3ff0185761d0d3d4c -1d2b3fcc2dc47961a01f71a49284492f0b1c21b3 refs/tags/1.0.26 -^031fea6f3b82c72be11477e7550c6ae3579e6139 -9bbadcc514eb0024e1401cad1cc89af1dfa84566 refs/tags/1.0.27 -^b087faf217affd8248a1019cc20db218f1059e36 -088e7803667a2a82a6f012347be98a0fadfc53b6 refs/tags/1.0.28 -^b47c75d3f5fc3f9d4101feb1b1ab30dbcd543141 -b09700ea714447a1d949bb9d3dbcd6b853e06c0e refs/tags/1.0.29 -^c7dd271dcd92af17168746a809503ee392d6f6ad -6432c0da0b396f387ac38f95a58080d41d7b9392 refs/tags/1.0.3 -^b2b3bae1db325cd52b79c438d30987e0d19891b4 -f7313db835060de51a0979c096d9bbd999b700e9 refs/tags/1.0.30 -^672e9525bbc2e5682c380d36974f34716b963591 -d0506c84f5f7f957386f9caf0c148bb830135ee5 refs/tags/1.0.31 -^cbe821249595aa5e389d5cb96e84da80adca8531 -fe783a404e3519aa4e9b22b06022d4b1b6691c99 refs/tags/1.0.32 -^8cb98afb749ec24cf703b8b89af2e159d529c4a0 -3714b0500645100c921f56d5cd3eda49ff750333 refs/tags/1.0.33 -^fdb266af297fa8531dad0859615b0a8e0b22da36 -83041b5614f548bd40ee08cf277498fd26818788 refs/tags/1.0.34 -^48f697af3d66e69be1923eaf474f175dc2c825b7 -0170a4168ac2ce7730220a0de3919685115416fb refs/tags/1.0.35 -^10ffe038172ef47a742b438f5c8dad059628c417 -f49fe93952201a37add6d04a7d748a80b8be3f33 refs/tags/1.0.36 -^7b226e33c7e83999363ce6a0eeb341aeb38ca8b2 -a637dba2ca00e048465e5935cea93a5dd1187cf8 refs/tags/1.0.37 -^8a996a5bfd5303c2fab64827cbfde02caa6cef66 -882fca502f3edbaf72bc463710106ceef98e3a38 refs/tags/1.0.38 -^74bfe75eb25ba9d39b0ae5b570d611855cbc5086 -6363d7c1e743ac9aefde4c8d0c22d9c0a73b2fbe refs/tags/1.0.39 -^f729af95d16fbec0ee167ed79231c6ff1a4d88c7 -deb7a091213b191020f37fe075081749e2302bc3 refs/tags/1.0.4 -^507914148ad4c69837ae42eb7930cb9e4f2fdc5b -4362e83fcccbd532c8df82715216cf6f71b6cd11 refs/tags/1.0.40 -^3cec8c487953298acd00c61ef9a81d0461517974 -ea119db6fbbea7b075bbc0c8e7f58413cf51ba7e refs/tags/1.0.41 -^281997e7606bd90c70b39e114a4d26b733e63b30 -7411eaf4a7892a51b8ba25fe3f38eac2d394a4b8 refs/tags/1.0.42 -^305be4a9798449ef757b8c9ddd2a6c3f6a10a101 -09fa746eb4300f95d9b9a7869e7c32194041d77d refs/tags/1.0.43 -^225adab854715459bc81dd3e788805debcf7f310 -f3299c409beecbe776ac0faeb397b6744e143ae8 refs/tags/1.0.44 -^54b70cfe109981e6349aebae4393c62c93cccafc -5261ef0e6aea7074d60065765cbc2ba60dde9d13 refs/tags/1.0.45 -^06f189583213cf2bce239af2f7e24c921c58bc8e -696672060b3c8213799abc2961e90ed31fc87e52 refs/tags/1.0.46 -^5ada5d5198d1f616d296c8dcbbbeef88f1118ab1 -8dbc28829b26f79c0abd45240afda59e5508e554 refs/tags/1.0.47 -^0495eaa802c73454ed6969fa1a3520db635bb901 -7a7b341383f762c035c562138baf64ca7b6991e9 refs/tags/1.0.48 -^5c5f342a5e601e4bfb49c8c095cb57c9f14eb0c8 -36c15814f5c009d620e999002b219133607034ab refs/tags/1.0.49 -^54465b7475517e10735f699e31d81a1d511baaeb -a1782c57d35a5168bcd0ab4c4b2cd8211e0ec11f refs/tags/1.0.5 -^10b8e5817acdcd052f335c4ea9b6c8909eab76e7 -0c59fa236fadc75ca8d8b88d23cfda1d221b1c70 refs/tags/1.0.50 -^a7d220d7915fb888413aa7978efd70f7006bda9d -771cd65ff35a849f59ffe1b796aeb6e48325d8a6 refs/tags/1.0.6 -^938bcec8f963c3e50895d3527a3ecea9d6a83150 -a367f64b558933ff2c9f4f39a0c253415c370d3a refs/tags/1.0.7 -^79b740e3d77d6303798397e94166a48d1ea10edc -890917feef8e0ce48bb68d227c9b04ae45d4d419 refs/tags/1.0.8 -^d53be52a3b0236ce34e0cd3b7af8ba8d490b0e7c -6569022b6ca6d79f33b47a1d275f7443de16bd30 refs/tags/1.0.9 -^1d0b3999af726e816010d108431492865e6df018 diff --git a/xet_error/_git/refs/heads/master b/xet_error/_git/refs/heads/master deleted file mode 100644 index 246de2c8..00000000 --- a/xet_error/_git/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -e9ea67c7e251764c3c2d839b6c06d9f35b154647 diff --git a/xet_error/_git/refs/remotes/origin/HEAD b/xet_error/_git/refs/remotes/origin/HEAD deleted file mode 100644 index 6efe28ff..00000000 --- a/xet_error/_git/refs/remotes/origin/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/remotes/origin/master diff --git a/xet_error/build.rs b/xet_error/build.rs deleted file mode 100644 index a6388f4f..00000000 --- a/xet_error/build.rs +++ /dev/null @@ -1,95 +0,0 @@ -#![allow(clippy::needless_raw_string_hashes)] - -use std::path::Path; -use std::process::{Command, ExitStatus, Stdio}; -use std::{env, fs, str}; - -// 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 -// xet_error is able to provide backtrace support. -const PROBE: &str = r#" - #![feature(error_generic_member_access)] - - use std::error::{Error, Request}; - use std::fmt::{self, Debug, Display}; - - struct MyError(Thing); - struct Thing; - - 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>) { - request.provide_ref(&self.0); - } - } -"#; - -fn main() { - match compile_probe() { - Some(status) if status.success() => println!("cargo:rustc-cfg=error_generic_member_access"), - _ => {}, - } -} - -fn compile_probe() -> Option { - 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 None; - } - - let rustc = env::var_os("RUSTC")?; - let out_dir = env::var_os("OUT_DIR")?; - let probefile = Path::new(&out_dir).join("probe.rs"); - fs::write(&probefile, PROBE).ok()?; - - // Make sure to pick up Cargo rustc configuration. - let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER") { - let mut cmd = Command::new(wrapper); - // The wrapper's first argument is supposed to be the path to rustc. - cmd.arg(rustc); - cmd - } else { - Command::new(rustc) - }; - - cmd.stderr(Stdio::null()) - .arg("--edition=2018") - .arg("--crate-name=xet_error_build") - .arg("--crate-type=lib") - .arg("--emit=metadata") - .arg("--out-dir") - .arg(out_dir) - .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); - } - } - } - - cmd.status().ok() -} diff --git a/xet_error/impl/Cargo.toml b/xet_error/impl/Cargo.toml deleted file mode 100644 index fc76bded..00000000 --- a/xet_error/impl/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "xet-error-impl" -version = "1.0.50" -authors = ["David Tolnay "] -description = "Implementation detail of the `thiserror` crate" -edition = "2021" -license = "MIT OR Apache-2.0" -repository = "https://github.com/dtolnay/thiserror" -rust-version = "1.56" - -[lib] -proc-macro = true - -[dependencies] -proc-macro2 = "1.0.63" -quote = "1.0.29" -syn = "2.0.23" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = ["--generate-link-to-definition"] diff --git a/xet_error/impl/LICENSE-APACHE b/xet_error/impl/LICENSE-APACHE deleted file mode 120000 index 965b606f..00000000 --- a/xet_error/impl/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/xet_error/impl/LICENSE-MIT b/xet_error/impl/LICENSE-MIT deleted file mode 120000 index 76219eb7..00000000 --- a/xet_error/impl/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/xet_error/impl/src/ast.rs b/xet_error/impl/src/ast.rs deleted file mode 100644 index da4f8a3b..00000000 --- a/xet_error/impl/src/ast.rs +++ /dev/null @@ -1,150 +0,0 @@ -use proc_macro2::Span; -use syn::{Data, DataEnum, DataStruct, DeriveInput, Error, Fields, Generics, Ident, Index, Member, Result, Type}; - -use crate::attr::{self, Attrs}; -use crate::generics::ParamsInScope; - -pub enum Input<'a> { - Struct(Struct<'a>), - Enum(Enum<'a>), -} - -pub struct Struct<'a> { - pub original: &'a DeriveInput, - pub attrs: Attrs<'a>, - pub ident: Ident, - pub generics: &'a Generics, - pub fields: Vec>, -} - -pub struct Enum<'a> { - pub original: &'a DeriveInput, - pub attrs: Attrs<'a>, - pub ident: Ident, - pub generics: &'a Generics, - pub variants: Vec>, -} - -pub struct Variant<'a> { - pub original: &'a syn::Variant, - pub attrs: Attrs<'a>, - pub ident: Ident, - pub fields: Vec>, -} - -pub struct Field<'a> { - pub original: &'a syn::Field, - pub attrs: Attrs<'a>, - pub member: Member, - pub ty: &'a Type, - pub contains_generic: bool, -} - -impl<'a> Input<'a> { - pub fn from_syn(node: &'a DeriveInput) -> Result { - match &node.data { - Data::Struct(data) => Struct::from_syn(node, data).map(Input::Struct), - Data::Enum(data) => Enum::from_syn(node, data).map(Input::Enum), - Data::Union(_) => Err(Error::new_spanned(node, "union as errors are not supported")), - } - } -} - -impl<'a> Struct<'a> { - fn from_syn(node: &'a DeriveInput, data: &'a DataStruct) -> Result { - let mut attrs = attr::get(&node.attrs)?; - let scope = ParamsInScope::new(&node.generics); - let span = attrs.span().unwrap_or_else(Span::call_site); - let fields = Field::multiple_from_syn(&data.fields, &scope, span)?; - if let Some(display) = &mut attrs.display { - display.expand_shorthand(&fields); - } - Ok(Struct { - original: node, - attrs, - ident: node.ident.clone(), - generics: &node.generics, - fields, - }) - } -} - -impl<'a> Enum<'a> { - fn from_syn(node: &'a DeriveInput, data: &'a DataEnum) -> Result { - let attrs = attr::get(&node.attrs)?; - let scope = ParamsInScope::new(&node.generics); - let span = attrs.span().unwrap_or_else(Span::call_site); - let variants = data - .variants - .iter() - .map(|node| { - let mut variant = Variant::from_syn(node, &scope, span)?; - if let display @ None = &mut variant.attrs.display { - display.clone_from(&attrs.display); - } - if let Some(display) = &mut variant.attrs.display { - display.expand_shorthand(&variant.fields); - } else if variant.attrs.transparent.is_none() { - variant.attrs.transparent = attrs.transparent; - } - Ok(variant) - }) - .collect::>()?; - Ok(Enum { - original: node, - attrs, - ident: node.ident.clone(), - generics: &node.generics, - variants, - }) - } -} - -impl<'a> Variant<'a> { - fn from_syn(node: &'a syn::Variant, scope: &ParamsInScope<'a>, span: Span) -> Result { - let attrs = attr::get(&node.attrs)?; - let span = attrs.span().unwrap_or(span); - Ok(Variant { - original: node, - attrs, - ident: node.ident.clone(), - fields: Field::multiple_from_syn(&node.fields, scope, span)?, - }) - } -} - -impl<'a> Field<'a> { - fn multiple_from_syn(fields: &'a Fields, scope: &ParamsInScope<'a>, span: Span) -> Result> { - fields - .iter() - .enumerate() - .map(|(i, field)| Field::from_syn(i, field, scope, span)) - .collect() - } - - fn from_syn(i: usize, node: &'a syn::Field, scope: &ParamsInScope<'a>, span: Span) -> Result { - Ok(Field { - original: node, - attrs: attr::get(&node.attrs)?, - member: node - .ident - .clone() - .map(Member::Named) - .unwrap_or_else(|| Member::Unnamed(Index { index: i as u32, span })), - ty: &node.ty, - contains_generic: scope.intersects(&node.ty), - }) - } -} - -impl Attrs<'_> { - pub fn span(&self) -> Option { - if let Some(display) = &self.display { - Some(display.fmt.span()) - } else if let Some(transparent) = &self.transparent { - Some(transparent.span) - } else { - None - } - } -} diff --git a/xet_error/impl/src/attr.rs b/xet_error/impl/src/attr.rs deleted file mode 100644 index f8d7081d..00000000 --- a/xet_error/impl/src/attr.rs +++ /dev/null @@ -1,204 +0,0 @@ -use std::collections::BTreeSet as Set; - -use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree}; -use quote::{format_ident, quote, ToTokens}; -use syn::parse::ParseStream; -use syn::{ - braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, Meta, Result, Token, -}; - -pub struct Attrs<'a> { - pub display: Option>, - pub source: Option<&'a Attribute>, - pub backtrace: Option<&'a Attribute>, - pub from: Option<&'a Attribute>, - pub transparent: Option>, -} - -#[derive(Clone)] -pub struct Display<'a> { - pub original: &'a Attribute, - pub fmt: LitStr, - pub args: TokenStream, - pub has_bonus_display: bool, - pub implied_bounds: Set<(usize, Trait)>, -} - -#[derive(Copy, Clone)] -pub struct Transparent<'a> { - pub original: &'a Attribute, - pub span: Span, -} - -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] -pub enum Trait { - Debug, - Display, - Octal, - LowerHex, - UpperHex, - Pointer, - Binary, - LowerExp, - UpperExp, -} - -pub fn get(input: &[Attribute]) -> Result { - let mut attrs = Attrs { - display: None, - source: None, - backtrace: None, - from: None, - transparent: None, - }; - - for attr in input { - if attr.path().is_ident("error") { - parse_error_attribute(&mut attrs, attr)?; - } else if attr.path().is_ident("source") { - attr.meta.require_path_only()?; - if attrs.source.is_some() { - return Err(Error::new_spanned(attr, "duplicate #[source] attribute")); - } - attrs.source = Some(attr); - } else if attr.path().is_ident("backtrace") { - attr.meta.require_path_only()?; - if attrs.backtrace.is_some() { - return Err(Error::new_spanned(attr, "duplicate #[backtrace] attribute")); - } - attrs.backtrace = Some(attr); - } else if attr.path().is_ident("from") { - match attr.meta { - Meta::Path(_) => {}, - Meta::List(_) | Meta::NameValue(_) => { - // Assume this is meant for derive_more crate or something. - continue; - }, - } - if attrs.from.is_some() { - return Err(Error::new_spanned(attr, "duplicate #[from] attribute")); - } - attrs.from = Some(attr); - } - } - - Ok(attrs) -} - -fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Result<()> { - syn::custom_keyword!(transparent); - - attr.parse_args_with(|input: ParseStream| { - if let Some(kw) = input.parse::>()? { - if attrs.transparent.is_some() { - return Err(Error::new_spanned(attr, "duplicate #[error(transparent)] attribute")); - } - attrs.transparent = Some(Transparent { - original: attr, - span: kw.span, - }); - return Ok(()); - } - - let display = Display { - original: attr, - fmt: input.parse()?, - args: parse_token_expr(input, false)?, - has_bonus_display: false, - implied_bounds: Set::new(), - }; - if attrs.display.is_some() { - return Err(Error::new_spanned(attr, "only one #[error(...)] attribute is allowed")); - } - attrs.display = Some(display); - Ok(()) - }) -} - -fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result { - let mut tokens = Vec::new(); - while !input.is_empty() { - if begin_expr && input.peek(Token![.]) { - if input.peek2(Ident) { - input.parse::()?; - begin_expr = false; - continue; - } - if input.peek2(LitInt) { - input.parse::()?; - let int: Index = input.parse()?; - let ident = format_ident!("_{}", int.index, span = int.span); - tokens.push(TokenTree::Ident(ident)); - begin_expr = false; - continue; - } - } - - begin_expr = input.peek(Token![break]) - || input.peek(Token![continue]) - || input.peek(Token![if]) - || input.peek(Token![in]) - || input.peek(Token![match]) - || input.peek(Token![mut]) - || input.peek(Token![return]) - || input.peek(Token![while]) - || input.peek(Token![+]) - || input.peek(Token![&]) - || input.peek(Token![!]) - || input.peek(Token![^]) - || input.peek(Token![,]) - || input.peek(Token![/]) - || input.peek(Token![=]) - || input.peek(Token![>]) - || input.peek(Token![<]) - || input.peek(Token![|]) - || input.peek(Token![%]) - || input.peek(Token![;]) - || input.peek(Token![*]) - || input.peek(Token![-]); - - let token: TokenTree = if input.peek(token::Paren) { - let content; - let delimiter = parenthesized!(content in input); - let nested = parse_token_expr(&content, true)?; - let mut group = Group::new(Delimiter::Parenthesis, nested); - group.set_span(delimiter.span.join()); - TokenTree::Group(group) - } else if input.peek(token::Brace) { - let content; - let delimiter = braced!(content in input); - let nested = parse_token_expr(&content, true)?; - let mut group = Group::new(Delimiter::Brace, nested); - group.set_span(delimiter.span.join()); - TokenTree::Group(group) - } else if input.peek(token::Bracket) { - let content; - let delimiter = bracketed!(content in input); - let nested = parse_token_expr(&content, true)?; - let mut group = Group::new(Delimiter::Bracket, nested); - group.set_span(delimiter.span.join()); - TokenTree::Group(group) - } else { - input.parse()? - }; - tokens.push(token); - } - Ok(TokenStream::from_iter(tokens)) -} - -impl ToTokens for Display<'_> { - fn to_tokens(&self, tokens: &mut TokenStream) { - let fmt = &self.fmt; - let args = &self.args; - tokens.extend(quote! { - ::core::write!(__formatter, #fmt #args) - }); - } -} - -impl ToTokens for Trait { - fn to_tokens(&self, tokens: &mut TokenStream) { - let trait_name = format_ident!("{}", format!("{:?}", self)); - tokens.extend(quote!(::core::fmt::#trait_name)); - } -} diff --git a/xet_error/impl/src/expand.rs b/xet_error/impl/src/expand.rs deleted file mode 100644 index cedb19ff..00000000 --- a/xet_error/impl/src/expand.rs +++ /dev/null @@ -1,545 +0,0 @@ -use std::collections::BTreeSet as Set; - -use proc_macro2::TokenStream; -use quote::{format_ident, quote, quote_spanned, ToTokens}; -use syn::{Data, DeriveInput, GenericArgument, Member, PathArguments, Result, Token, Type, Visibility}; - -use crate::ast::{Enum, Field, Input, Struct}; -use crate::attr::Trait; -use crate::generics::InferredBounds; -use crate::span::MemberSpan; - -pub fn derive(node: &DeriveInput) -> Result { - let input = Input::from_syn(node)?; - input.validate()?; - Ok(match input { - Input::Struct(input) => impl_struct(input), - Input::Enum(input) => impl_enum(input), - }) -} - -fn impl_struct(input: Struct) -> TokenStream { - let ty = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - let mut error_inferred_bounds = InferredBounds::new(); - - let source_body = if let Some(transparent_attr) = &input.attrs.transparent { - let only_field = &input.fields[0]; - if only_field.contains_generic { - error_inferred_bounds.insert(only_field.ty, quote!(std::error::Error)); - } - let member = &only_field.member; - Some(quote_spanned! {transparent_attr.span=> - std::error::Error::source(self.#member.as_dyn_error()) - }) - } else if let Some(source_field) = input.source_field() { - let source = &source_field.member; - if source_field.contains_generic { - let ty = unoptional_type(source_field.ty); - error_inferred_bounds.insert(ty, quote!(std::error::Error + 'static)); - } - let asref = if type_is_option(source_field.ty) { - Some(quote_spanned!(source.member_span()=> .as_ref()?)) - } else { - None - }; - let dyn_error = quote_spanned! {source_field.source_span()=> - self.#source #asref.as_dyn_error() - }; - Some(quote! { - ::core::option::Option::Some(#dyn_error) - }) - } else { - None - }; - let source_method = source_body.map(|body| { - quote! { - fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> { - use xet_error::__private::AsDynError; - #body - } - } - }); - - let provide_method = input.backtrace_field().map(|backtrace_field| { - let request = quote!(request); - let backtrace = &backtrace_field.member; - let body = if let Some(source_field) = input.source_field() { - let source = &source_field.member; - let source_provide = if type_is_option(source_field.ty) { - quote_spanned! {source.member_span()=> - if let ::core::option::Option::Some(source) = &self.#source { - source.xet_error_provide(#request); - } - } - } else { - quote_spanned! {source.member_span()=> - self.#source.xet_error_provide(#request); - } - }; - let self_provide = if source == backtrace { - None - } else if type_is_option(backtrace_field.ty) { - Some(quote! { - if let ::core::option::Option::Some(backtrace) = &self.#backtrace { - #request.provide_ref::(backtrace); - } - }) - } else { - Some(quote! { - #request.provide_ref::(&self.#backtrace); - }) - }; - quote! { - use xet_error::__private::ThiserrorProvide; - #source_provide - #self_provide - } - } else if type_is_option(backtrace_field.ty) { - quote! { - if let ::core::option::Option::Some(backtrace) = &self.#backtrace { - #request.provide_ref::(backtrace); - } - } - } else { - quote! { - #request.provide_ref::(&self.#backtrace); - } - }; - quote! { - fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) { - #body - } - } - }); - - let mut display_implied_bounds = Set::new(); - let display_body = if input.attrs.transparent.is_some() { - let only_field = &input.fields[0].member; - display_implied_bounds.insert((0, Trait::Display)); - Some(quote! { - ::core::fmt::Display::fmt(&self.#only_field, __formatter) - }) - } else if let Some(display) = &input.attrs.display { - display_implied_bounds.clone_from(&display.implied_bounds); - let use_as_display = use_as_display(display.has_bonus_display); - let pat = fields_pat(&input.fields); - Some(quote! { - #use_as_display - #[allow(unused_variables, deprecated)] - let Self #pat = self; - #display - }) - } else { - None - }; - let display_impl = display_body.map(|body| { - let mut display_inferred_bounds = InferredBounds::new(); - for (field, bound) in display_implied_bounds { - let field = &input.fields[field]; - if field.contains_generic { - display_inferred_bounds.insert(field.ty, bound); - } - } - let display_where_clause = display_inferred_bounds.augment_where_clause(input.generics); - quote! { - #[allow(unused_qualifications)] - impl #impl_generics ::core::fmt::Display for #ty #ty_generics #display_where_clause { - #[allow(clippy::used_underscore_binding)] - fn fmt(&self, __formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - #body - } - } - } - }); - - let from_impl = input.from_field().map(|from_field| { - let backtrace_field = input.distinct_backtrace_field(); - let from = unoptional_type(from_field.ty); - let body = from_initializer(from_field, backtrace_field); - quote! { - #[allow(unused_qualifications)] - impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause { - #[allow(deprecated)] - fn from(source: #from) -> Self { - xet_error::error_hook(&format!("{source:?}")); - #ty #body - } - } - } - }); - - let error_trait = spanned_error_trait(input.original); - if input.generics.type_params().next().is_some() { - let self_token = ::default(); - error_inferred_bounds.insert(self_token, Trait::Debug); - error_inferred_bounds.insert(self_token, Trait::Display); - } - let error_where_clause = error_inferred_bounds.augment_where_clause(input.generics); - - quote! { - #[allow(unused_qualifications)] - impl #impl_generics #error_trait for #ty #ty_generics #error_where_clause { - #source_method - #provide_method - } - #display_impl - #from_impl - } -} - -fn impl_enum(input: Enum) -> TokenStream { - let ty = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - let mut error_inferred_bounds = InferredBounds::new(); - - let source_method = if input.has_source() { - let arms = input.variants.iter().map(|variant| { - let ident = &variant.ident; - if let Some(transparent_attr) = &variant.attrs.transparent { - let only_field = &variant.fields[0]; - if only_field.contains_generic { - error_inferred_bounds.insert(only_field.ty, quote!(std::error::Error)); - } - let member = &only_field.member; - let source = quote_spanned! {transparent_attr.span=> - std::error::Error::source(transparent.as_dyn_error()) - }; - quote! { - #ty::#ident {#member: transparent} => #source, - } - } else if let Some(source_field) = variant.source_field() { - let source = &source_field.member; - if source_field.contains_generic { - let ty = unoptional_type(source_field.ty); - error_inferred_bounds.insert(ty, quote!(std::error::Error + 'static)); - } - let asref = if type_is_option(source_field.ty) { - Some(quote_spanned!(source.member_span()=> .as_ref()?)) - } else { - None - }; - let varsource = quote!(source); - let dyn_error = quote_spanned! {source_field.source_span()=> - #varsource #asref.as_dyn_error() - }; - quote! { - #ty::#ident {#source: #varsource, ..} => ::core::option::Option::Some(#dyn_error), - } - } else { - quote! { - #ty::#ident {..} => ::core::option::Option::None, - } - } - }); - Some(quote! { - fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> { - use xet_error::__private::AsDynError; - #[allow(deprecated)] - match self { - #(#arms)* - } - } - }) - } else { - None - }; - - let provide_method = if input.has_backtrace() { - let request = quote!(request); - let arms = input.variants.iter().map(|variant| { - let ident = &variant.ident; - match (variant.backtrace_field(), variant.source_field()) { - (Some(backtrace_field), Some(source_field)) if backtrace_field.attrs.backtrace.is_none() => { - let backtrace = &backtrace_field.member; - let source = &source_field.member; - let varsource = quote!(source); - let source_provide = if type_is_option(source_field.ty) { - quote_spanned! {source.member_span()=> - if let ::core::option::Option::Some(source) = #varsource { - source.xet_error_provide(#request); - } - } - } else { - quote_spanned! {source.member_span()=> - #varsource.xet_error_provide(#request); - } - }; - let self_provide = if type_is_option(backtrace_field.ty) { - quote! { - if let ::core::option::Option::Some(backtrace) = backtrace { - #request.provide_ref::(backtrace); - } - } - } else { - quote! { - #request.provide_ref::(backtrace); - } - }; - quote! { - #ty::#ident { - #backtrace: backtrace, - #source: #varsource, - .. - } => { - use xet_error::__private::ThiserrorProvide; - #source_provide - #self_provide - } - } - }, - (Some(backtrace_field), Some(source_field)) if backtrace_field.member == source_field.member => { - let backtrace = &backtrace_field.member; - let varsource = quote!(source); - let source_provide = if type_is_option(source_field.ty) { - quote_spanned! {backtrace.member_span()=> - if let ::core::option::Option::Some(source) = #varsource { - source.xet_error_provide(#request); - } - } - } else { - quote_spanned! {backtrace.member_span()=> - #varsource.xet_error_provide(#request); - } - }; - quote! { - #ty::#ident {#backtrace: #varsource, ..} => { - use xet_error::__private::ThiserrorProvide; - #source_provide - } - } - }, - (Some(backtrace_field), _) => { - let backtrace = &backtrace_field.member; - let body = if type_is_option(backtrace_field.ty) { - quote! { - if let ::core::option::Option::Some(backtrace) = backtrace { - #request.provide_ref::(backtrace); - } - } - } else { - quote! { - #request.provide_ref::(backtrace); - } - }; - quote! { - #ty::#ident {#backtrace: backtrace, ..} => { - #body - } - } - }, - (None, _) => quote! { - #ty::#ident {..} => {} - }, - } - }); - Some(quote! { - fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) { - #[allow(deprecated)] - match self { - #(#arms)* - } - } - }) - } else { - None - }; - - let display_impl = if input.has_display() { - let mut display_inferred_bounds = InferredBounds::new(); - let has_bonus_display = input - .variants - .iter() - .any(|v| v.attrs.display.as_ref().map_or(false, |display| display.has_bonus_display)); - let use_as_display = use_as_display(has_bonus_display); - let void_deref = if input.variants.is_empty() { - Some(quote!(*)) - } else { - None - }; - let arms = input.variants.iter().map(|variant| { - let mut display_implied_bounds = Set::new(); - let display = match &variant.attrs.display { - Some(display) => { - display_implied_bounds.clone_from(&display.implied_bounds); - display.to_token_stream() - }, - None => { - let only_field = match &variant.fields[0].member { - Member::Named(ident) => ident.clone(), - Member::Unnamed(index) => format_ident!("_{}", index), - }; - display_implied_bounds.insert((0, Trait::Display)); - quote!(::core::fmt::Display::fmt(#only_field, __formatter)) - }, - }; - for (field, bound) in display_implied_bounds { - let field = &variant.fields[field]; - if field.contains_generic { - display_inferred_bounds.insert(field.ty, bound); - } - } - let ident = &variant.ident; - let pat = fields_pat(&variant.fields); - quote! { - #ty::#ident #pat => #display - } - }); - let arms = arms.collect::>(); - let display_where_clause = display_inferred_bounds.augment_where_clause(input.generics); - Some(quote! { - #[allow(unused_qualifications)] - impl #impl_generics ::core::fmt::Display for #ty #ty_generics #display_where_clause { - fn fmt(&self, __formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - #use_as_display - #[allow(unused_variables, deprecated, clippy::used_underscore_binding)] - match #void_deref self { - #(#arms,)* - } - } - } - }) - } else { - None - }; - - let from_impls = input.variants.iter().filter_map(|variant| { - let from_field = variant.from_field()?; - let backtrace_field = variant.distinct_backtrace_field(); - let variant = &variant.ident; - let from = unoptional_type(from_field.ty); - let body = from_initializer(from_field, backtrace_field); - Some(quote! { - #[allow(unused_qualifications)] - impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause { - - #[allow(deprecated)] - fn from(source: #from) -> Self { - xet_error::error_hook(&format!("{source:?}")); - #ty::#variant #body - } - } - }) - }); - - let error_trait = spanned_error_trait(input.original); - if input.generics.type_params().next().is_some() { - let self_token = ::default(); - error_inferred_bounds.insert(self_token, Trait::Debug); - error_inferred_bounds.insert(self_token, Trait::Display); - } - let error_where_clause = error_inferred_bounds.augment_where_clause(input.generics); - - quote! { - #[allow(unused_qualifications)] - impl #impl_generics #error_trait for #ty #ty_generics #error_where_clause { - #source_method - #provide_method - } - #display_impl - #(#from_impls)* - } -} - -fn fields_pat(fields: &[Field]) -> TokenStream { - let mut members = fields.iter().map(|field| &field.member).peekable(); - match members.peek() { - Some(Member::Named(_)) => quote!({ #(#members),* }), - Some(Member::Unnamed(_)) => { - let vars = members.map(|member| match member { - Member::Unnamed(member) => format_ident!("_{}", member), - Member::Named(_) => unreachable!(), - }); - quote!((#(#vars),*)) - }, - None => quote!({}), - } -} - -fn use_as_display(needs_as_display: bool) -> Option { - if needs_as_display { - Some(quote! { - use xet_error::__private::AsDisplay as _; - }) - } else { - None - } -} - -fn from_initializer(from_field: &Field, backtrace_field: Option<&Field>) -> TokenStream { - let from_member = &from_field.member; - let some_source = if type_is_option(from_field.ty) { - quote!(::core::option::Option::Some(source)) - } else { - quote!(source) - }; - let backtrace = backtrace_field.map(|backtrace_field| { - let backtrace_member = &backtrace_field.member; - if type_is_option(backtrace_field.ty) { - quote! { - #backtrace_member: ::core::option::Option::Some(std::backtrace::Backtrace::capture()), - } - } else { - quote! { - #backtrace_member: ::core::convert::From::from(std::backtrace::Backtrace::capture()), - } - } - }); - quote!({ - #from_member: #some_source, - #backtrace - }) -} - -fn type_is_option(ty: &Type) -> bool { - type_parameter_of_option(ty).is_some() -} - -fn unoptional_type(ty: &Type) -> TokenStream { - let unoptional = type_parameter_of_option(ty).unwrap_or(ty); - quote!(#unoptional) -} - -fn type_parameter_of_option(ty: &Type) -> Option<&Type> { - let path = match ty { - Type::Path(ty) => &ty.path, - _ => return None, - }; - - let last = path.segments.last().unwrap(); - if last.ident != "Option" { - return None; - } - - let bracketed = match &last.arguments { - PathArguments::AngleBracketed(bracketed) => bracketed, - _ => return None, - }; - - if bracketed.args.len() != 1 { - return None; - } - - match &bracketed.args[0] { - GenericArgument::Type(arg) => Some(arg), - _ => None, - } -} - -fn spanned_error_trait(input: &DeriveInput) -> TokenStream { - let vis_span = match &input.vis { - Visibility::Public(vis) => Some(vis.span), - Visibility::Restricted(vis) => Some(vis.pub_token.span), - Visibility::Inherited => None, - }; - let data_span = match &input.data { - Data::Struct(data) => data.struct_token.span, - Data::Enum(data) => data.enum_token.span, - Data::Union(data) => data.union_token.span, - }; - let first_span = vis_span.unwrap_or(data_span); - let last_span = input.ident.span(); - let path = quote_spanned!(first_span=> std::error::); - let error = quote_spanned!(last_span=> Error); - quote!(#path #error) -} diff --git a/xet_error/impl/src/fmt.rs b/xet_error/impl/src/fmt.rs deleted file mode 100644 index 9a9d75e0..00000000 --- a/xet_error/impl/src/fmt.rs +++ /dev/null @@ -1,172 +0,0 @@ -use std::collections::{BTreeSet as Set, HashMap as Map}; - -use proc_macro2::TokenTree; -use quote::{format_ident, quote_spanned}; -use syn::ext::IdentExt; -use syn::parse::{ParseStream, Parser}; -use syn::{Ident, Index, LitStr, Member, Result, Token}; - -use crate::ast::Field; -use crate::attr::{Display, Trait}; - -impl Display<'_> { - // Transform `"error {var}"` to `"error {}", var`. - pub fn expand_shorthand(&mut self, fields: &[Field]) { - let raw_args = self.args.clone(); - let mut named_args = explicit_named_args.parse2(raw_args).unwrap(); - let mut member_index = Map::new(); - for (i, field) in fields.iter().enumerate() { - member_index.insert(&field.member, i); - } - - let span = self.fmt.span(); - let fmt = self.fmt.value(); - let mut read = fmt.as_str(); - let mut out = String::new(); - let mut args = self.args.clone(); - let mut has_bonus_display = false; - let mut implied_bounds = Set::new(); - - let mut has_trailing_comma = false; - if let Some(TokenTree::Punct(punct)) = args.clone().into_iter().last() { - if punct.as_char() == ',' { - has_trailing_comma = true; - } - } - - while let Some(brace) = read.find('{') { - out += &read[..brace + 1]; - read = &read[brace + 1..]; - if read.starts_with('{') { - out.push('{'); - read = &read[1..]; - continue; - } - let next = match read.chars().next() { - Some(next) => next, - None => return, - }; - let member = match next { - '0'..='9' => { - let int = take_int(&mut read); - let member = match int.parse::() { - Ok(index) => Member::Unnamed(Index { index, span }), - Err(_) => return, - }; - if !member_index.contains_key(&member) { - out += ∫ - continue; - } - member - }, - 'a'..='z' | 'A'..='Z' | '_' => { - let mut ident = take_ident(&mut read); - ident.set_span(span); - Member::Named(ident) - }, - _ => continue, - }; - if let Some(&field) = member_index.get(&member) { - let end_spec = match read.find('}') { - Some(end_spec) => end_spec, - None => return, - }; - let bound = match read[..end_spec].chars().next_back() { - Some('?') => Trait::Debug, - Some('o') => Trait::Octal, - Some('x') => Trait::LowerHex, - Some('X') => Trait::UpperHex, - Some('p') => Trait::Pointer, - Some('b') => Trait::Binary, - Some('e') => Trait::LowerExp, - Some('E') => Trait::UpperExp, - Some(_) | None => Trait::Display, - }; - implied_bounds.insert((field, bound)); - } - let local = match &member { - Member::Unnamed(index) => format_ident!("_{}", index), - Member::Named(ident) => ident.clone(), - }; - let mut formatvar = local.clone(); - if formatvar.to_string().starts_with("r#") { - formatvar = format_ident!("r_{}", formatvar); - } - if formatvar.to_string().starts_with('_') { - // Work around leading underscore being rejected by 1.40 and - // older compilers. https://github.com/rust-lang/rust/pull/66847 - formatvar = format_ident!("field_{}", formatvar); - } - out += &formatvar.to_string(); - if !named_args.insert(formatvar.clone()) { - // Already specified in the format argument list. - continue; - } - if !has_trailing_comma { - args.extend(quote_spanned!(span=> ,)); - } - args.extend(quote_spanned!(span=> #formatvar = #local)); - if read.starts_with('}') && member_index.contains_key(&member) { - has_bonus_display = true; - args.extend(quote_spanned!(span=> .as_display())); - } - has_trailing_comma = false; - } - - out += read; - self.fmt = LitStr::new(&out, self.fmt.span()); - self.args = args; - self.has_bonus_display = has_bonus_display; - self.implied_bounds = implied_bounds; - } -} - -fn explicit_named_args(input: ParseStream) -> Result> { - let mut named_args = Set::new(); - - while !input.is_empty() { - if input.peek(Token![,]) && input.peek2(Ident::peek_any) && input.peek3(Token![=]) { - input.parse::()?; - let ident = input.call(Ident::parse_any)?; - input.parse::()?; - named_args.insert(ident); - } else { - input.parse::()?; - } - } - - Ok(named_args) -} - -fn take_int(read: &mut &str) -> String { - let mut int = String::new(); - for (i, ch) in read.char_indices() { - match ch { - '0'..='9' => int.push(ch), - _ => { - *read = &read[i..]; - break; - }, - } - } - int -} - -fn take_ident(read: &mut &str) -> Ident { - let mut ident = String::new(); - let raw = read.starts_with("r#"); - if raw { - ident.push_str("r#"); - *read = &read[2..]; - } - for (i, ch) in read.char_indices() { - match ch { - 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => ident.push(ch), - _ => { - *read = &read[i..]; - break; - }, - } - } - Ident::parse_any.parse_str(&ident).unwrap() -} diff --git a/xet_error/impl/src/generics.rs b/xet_error/impl/src/generics.rs deleted file mode 100644 index 03bac395..00000000 --- a/xet_error/impl/src/generics.rs +++ /dev/null @@ -1,84 +0,0 @@ -use std::collections::btree_map::Entry; -use std::collections::{BTreeMap as Map, BTreeSet as Set}; - -use proc_macro2::TokenStream; -use quote::ToTokens; -use syn::punctuated::Punctuated; -use syn::{parse_quote, GenericArgument, Generics, Ident, PathArguments, Token, Type, WhereClause}; - -pub struct ParamsInScope<'a> { - names: Set<&'a Ident>, -} - -impl<'a> ParamsInScope<'a> { - pub fn new(generics: &'a Generics) -> Self { - ParamsInScope { - names: generics.type_params().map(|param| ¶m.ident).collect(), - } - } - - pub fn intersects(&self, ty: &Type) -> bool { - let mut found = false; - crawl(self, ty, &mut found); - found - } -} - -fn crawl(in_scope: &ParamsInScope, ty: &Type, found: &mut bool) { - if let Type::Path(ty) = ty { - if ty.qself.is_none() { - if let Some(ident) = ty.path.get_ident() { - if in_scope.names.contains(ident) { - *found = true; - } - } - } - for segment in &ty.path.segments { - if let PathArguments::AngleBracketed(arguments) = &segment.arguments { - for arg in &arguments.args { - if let GenericArgument::Type(ty) = arg { - crawl(in_scope, ty, found); - } - } - } - } - } -} - -pub struct InferredBounds { - bounds: Map, Punctuated)>, - order: Vec, -} - -impl InferredBounds { - pub fn new() -> Self { - InferredBounds { - bounds: Map::new(), - order: Vec::new(), - } - } - - #[allow(clippy::type_repetition_in_bounds, clippy::trait_duplication_in_bounds)] // clippy bug: https://github.com/rust-lang/rust-clippy/issues/8771 - pub fn insert(&mut self, ty: impl ToTokens, bound: impl ToTokens) { - let ty = ty.to_token_stream(); - let bound = bound.to_token_stream(); - let entry = self.bounds.entry(ty.to_string()); - if let Entry::Vacant(_) = entry { - self.order.push(ty); - } - let (set, tokens) = entry.or_default(); - if set.insert(bound.to_string()) { - tokens.push(bound); - } - } - - pub fn augment_where_clause(&self, generics: &Generics) -> WhereClause { - let mut generics = generics.clone(); - let where_clause = generics.make_where_clause(); - for ty in &self.order { - let (_set, bounds) = &self.bounds[&ty.to_string()]; - where_clause.predicates.push(parse_quote!(#ty: #bounds)); - } - generics.where_clause.unwrap() - } -} diff --git a/xet_error/impl/src/lib.rs b/xet_error/impl/src/lib.rs deleted file mode 100644 index 0af8569b..00000000 --- a/xet_error/impl/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![allow( - unknown_lints, - renamed_and_removed_lints, - clippy::blocks_in_conditions, - clippy::blocks_in_if_conditions, - clippy::cast_lossless, - clippy::cast_possible_truncation, - clippy::manual_find, - clippy::manual_let_else, - clippy::manual_map, - clippy::map_unwrap_or, - clippy::module_name_repetitions, - clippy::needless_pass_by_value, - clippy::option_if_let_else, - clippy::range_plus_one, - clippy::single_match_else, - clippy::struct_field_names, - clippy::too_many_lines, - clippy::wrong_self_convention -)] - -extern crate proc_macro; - -mod ast; -mod attr; -mod expand; -mod fmt; -mod generics; -mod prop; -mod span; -mod valid; - -use proc_macro::TokenStream; -use syn::{parse_macro_input, DeriveInput}; - -#[proc_macro_derive(Error, attributes(backtrace, error, from, source))] -pub fn derive_error(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - expand::derive(&input).unwrap_or_else(|err| err.to_compile_error()).into() -} diff --git a/xet_error/impl/src/prop.rs b/xet_error/impl/src/prop.rs deleted file mode 100644 index b4b1e9e4..00000000 --- a/xet_error/impl/src/prop.rs +++ /dev/null @@ -1,138 +0,0 @@ -use proc_macro2::Span; -use syn::{Member, Type}; - -use crate::ast::{Enum, Field, Struct, Variant}; -use crate::span::MemberSpan; - -impl Struct<'_> { - pub(crate) fn from_field(&self) -> Option<&Field> { - from_field(&self.fields) - } - - pub(crate) fn source_field(&self) -> Option<&Field> { - source_field(&self.fields) - } - - pub(crate) fn backtrace_field(&self) -> Option<&Field> { - backtrace_field(&self.fields) - } - - pub(crate) fn distinct_backtrace_field(&self) -> Option<&Field> { - let backtrace_field = self.backtrace_field()?; - distinct_backtrace_field(backtrace_field, self.from_field()) - } -} - -impl Enum<'_> { - pub(crate) fn has_source(&self) -> bool { - self.variants - .iter() - .any(|variant| variant.source_field().is_some() || variant.attrs.transparent.is_some()) - } - - pub(crate) fn has_backtrace(&self) -> bool { - self.variants.iter().any(|variant| variant.backtrace_field().is_some()) - } - - pub(crate) fn has_display(&self) -> bool { - self.attrs.display.is_some() - || self.attrs.transparent.is_some() - || self.variants.iter().any(|variant| variant.attrs.display.is_some()) - || self.variants.iter().all(|variant| variant.attrs.transparent.is_some()) - } -} - -impl Variant<'_> { - pub(crate) fn from_field(&self) -> Option<&Field> { - from_field(&self.fields) - } - - pub(crate) fn source_field(&self) -> Option<&Field> { - source_field(&self.fields) - } - - pub(crate) fn backtrace_field(&self) -> Option<&Field> { - backtrace_field(&self.fields) - } - - pub(crate) fn distinct_backtrace_field(&self) -> Option<&Field> { - let backtrace_field = self.backtrace_field()?; - distinct_backtrace_field(backtrace_field, self.from_field()) - } -} - -impl Field<'_> { - pub(crate) fn is_backtrace(&self) -> bool { - type_is_backtrace(self.ty) - } - - pub(crate) fn source_span(&self) -> Span { - if let Some(source_attr) = &self.attrs.source { - source_attr.path().get_ident().unwrap().span() - } else if let Some(from_attr) = &self.attrs.from { - from_attr.path().get_ident().unwrap().span() - } else { - self.member.member_span() - } - } -} - -fn from_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { - for field in fields { - if field.attrs.from.is_some() { - return Some(field); - } - } - None -} - -fn source_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { - for field in fields { - if field.attrs.from.is_some() || field.attrs.source.is_some() { - return Some(field); - } - } - for field in fields { - match &field.member { - Member::Named(ident) if ident == "source" => return Some(field), - _ => {}, - } - } - None -} - -fn backtrace_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { - for field in fields { - if field.attrs.backtrace.is_some() { - return Some(field); - } - } - for field in fields { - if field.is_backtrace() { - return Some(field); - } - } - None -} - -// The #[backtrace] field, if it is not the same as the #[from] field. -fn distinct_backtrace_field<'a, 'b>( - backtrace_field: &'a Field<'b>, - from_field: Option<&Field>, -) -> Option<&'a Field<'b>> { - if from_field.map_or(false, |from_field| from_field.member == backtrace_field.member) { - None - } else { - Some(backtrace_field) - } -} - -fn type_is_backtrace(ty: &Type) -> bool { - let path = match ty { - Type::Path(ty) => &ty.path, - _ => return false, - }; - - let last = path.segments.last().unwrap(); - last.ident == "Backtrace" && last.arguments.is_empty() -} diff --git a/xet_error/impl/src/span.rs b/xet_error/impl/src/span.rs deleted file mode 100644 index c1237ddf..00000000 --- a/xet_error/impl/src/span.rs +++ /dev/null @@ -1,15 +0,0 @@ -use proc_macro2::Span; -use syn::Member; - -pub trait MemberSpan { - fn member_span(&self) -> Span; -} - -impl MemberSpan for Member { - fn member_span(&self) -> Span { - match self { - Member::Named(ident) => ident.span(), - Member::Unnamed(index) => index.span, - } - } -} diff --git a/xet_error/impl/src/valid.rs b/xet_error/impl/src/valid.rs deleted file mode 100644 index 88125aa1..00000000 --- a/xet_error/impl/src/valid.rs +++ /dev/null @@ -1,215 +0,0 @@ -use std::collections::BTreeSet as Set; - -use quote::ToTokens; -use syn::{Error, GenericArgument, Member, PathArguments, Result, Type}; - -use crate::ast::{Enum, Field, Input, Struct, Variant}; -use crate::attr::Attrs; - -impl Input<'_> { - pub(crate) fn validate(&self) -> Result<()> { - match self { - Input::Struct(input) => input.validate(), - Input::Enum(input) => input.validate(), - } - } -} - -impl Struct<'_> { - fn validate(&self) -> Result<()> { - check_non_field_attrs(&self.attrs)?; - if let Some(transparent) = self.attrs.transparent { - if self.fields.len() != 1 { - return Err(Error::new_spanned( - transparent.original, - "#[error(transparent)] requires exactly one field", - )); - } - if let Some(source) = self.fields.iter().find_map(|f| f.attrs.source) { - return Err(Error::new_spanned(source, "transparent error struct can't contain #[source]")); - } - } - check_field_attrs(&self.fields)?; - for field in &self.fields { - field.validate()?; - } - Ok(()) - } -} - -impl Enum<'_> { - fn validate(&self) -> Result<()> { - check_non_field_attrs(&self.attrs)?; - let has_display = self.has_display(); - for variant in &self.variants { - variant.validate()?; - if has_display && variant.attrs.display.is_none() && variant.attrs.transparent.is_none() { - return Err(Error::new_spanned(variant.original, "missing #[error(\"...\")] display attribute")); - } - } - let mut from_types = Set::new(); - for variant in &self.variants { - if let Some(from_field) = variant.from_field() { - let repr = from_field.ty.to_token_stream().to_string(); - if !from_types.insert(repr) { - return Err(Error::new_spanned( - from_field.original, - "cannot derive From because another variant has the same source type", - )); - } - } - } - Ok(()) - } -} - -impl Variant<'_> { - fn validate(&self) -> Result<()> { - check_non_field_attrs(&self.attrs)?; - if self.attrs.transparent.is_some() { - if self.fields.len() != 1 { - return Err(Error::new_spanned(self.original, "#[error(transparent)] requires exactly one field")); - } - if let Some(source) = self.fields.iter().find_map(|f| f.attrs.source) { - return Err(Error::new_spanned(source, "transparent variant can't contain #[source]")); - } - } - check_field_attrs(&self.fields)?; - for field in &self.fields { - field.validate()?; - } - Ok(()) - } -} - -impl Field<'_> { - fn validate(&self) -> Result<()> { - if let Some(display) = &self.attrs.display { - return Err(Error::new_spanned( - display.original, - "not expected here; the #[error(...)] attribute belongs on top of a struct or an enum variant", - )); - } - Ok(()) - } -} - -fn check_non_field_attrs(attrs: &Attrs) -> Result<()> { - if let Some(from) = &attrs.from { - return Err(Error::new_spanned(from, "not expected here; the #[from] attribute belongs on a specific field")); - } - if let Some(source) = &attrs.source { - return Err(Error::new_spanned( - source, - "not expected here; the #[source] attribute belongs on a specific field", - )); - } - if let Some(backtrace) = &attrs.backtrace { - return Err(Error::new_spanned( - backtrace, - "not expected here; the #[backtrace] attribute belongs on a specific field", - )); - } - if let Some(display) = &attrs.display { - if attrs.transparent.is_some() { - return Err(Error::new_spanned( - display.original, - "cannot have both #[error(transparent)] and a display attribute", - )); - } - } - Ok(()) -} - -fn check_field_attrs(fields: &[Field]) -> Result<()> { - let mut from_field = None; - let mut source_field = None; - let mut backtrace_field = None; - let mut has_backtrace = false; - for field in fields { - if let Some(from) = field.attrs.from { - if from_field.is_some() { - return Err(Error::new_spanned(from, "duplicate #[from] attribute")); - } - from_field = Some(field); - } - if let Some(source) = field.attrs.source { - if source_field.is_some() { - return Err(Error::new_spanned(source, "duplicate #[source] attribute")); - } - source_field = Some(field); - } - if let Some(backtrace) = field.attrs.backtrace { - if backtrace_field.is_some() { - return Err(Error::new_spanned(backtrace, "duplicate #[backtrace] attribute")); - } - backtrace_field = Some(field); - has_backtrace = true; - } - if let Some(transparent) = field.attrs.transparent { - return Err(Error::new_spanned( - transparent.original, - "#[error(transparent)] needs to go outside the enum or struct, not on an individual field", - )); - } - has_backtrace |= field.is_backtrace(); - } - if let (Some(from_field), Some(source_field)) = (from_field, source_field) { - if !same_member(from_field, source_field) { - return Err(Error::new_spanned( - from_field.attrs.from, - "#[from] is only supported on the source field, not any other field", - )); - } - } - if let Some(from_field) = from_field { - let max_expected_fields = match backtrace_field { - Some(backtrace_field) => 1 + !same_member(from_field, backtrace_field) as usize, - None => 1 + has_backtrace as usize, - }; - if fields.len() > max_expected_fields { - return Err(Error::new_spanned( - from_field.attrs.from, - "deriving From requires no fields other than source and backtrace", - )); - } - } - if let Some(source_field) = source_field.or(from_field) { - if contains_non_static_lifetime(source_field.ty) { - return Err(Error::new_spanned( - &source_field.original.ty, - "non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static", - )); - } - } - Ok(()) -} - -fn same_member(one: &Field, two: &Field) -> bool { - match (&one.member, &two.member) { - (Member::Named(one), Member::Named(two)) => one == two, - (Member::Unnamed(one), Member::Unnamed(two)) => one.index == two.index, - _ => unreachable!(), - } -} - -fn contains_non_static_lifetime(ty: &Type) -> bool { - match ty { - Type::Path(ty) => { - let bracketed = match &ty.path.segments.last().unwrap().arguments { - PathArguments::AngleBracketed(bracketed) => bracketed, - _ => return false, - }; - for arg in &bracketed.args { - match arg { - GenericArgument::Type(ty) if contains_non_static_lifetime(ty) => return true, - GenericArgument::Lifetime(lifetime) if lifetime.ident != "static" => return true, - _ => {}, - } - } - false - }, - Type::Reference(ty) => ty.lifetime.as_ref().map_or(false, |lifetime| lifetime.ident != "static"), - _ => false, // maybe implement later if there are common other cases - } -} diff --git a/xet_error/rust-toolchain.toml b/xet_error/rust-toolchain.toml deleted file mode 100644 index 20fe888c..00000000 --- a/xet_error/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -components = ["rust-src"] diff --git a/xet_error/src/aserror.rs b/xet_error/src/aserror.rs deleted file mode 100644 index 54fc6f11..00000000 --- a/xet_error/src/aserror.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::error::Error; -use std::panic::UnwindSafe; - -#[doc(hidden)] -pub trait AsDynError<'a>: Sealed { - fn as_dyn_error(&self) -> &(dyn Error + 'a); -} - -impl<'a, T: Error + 'a> AsDynError<'a> for T { - #[inline] - fn as_dyn_error(&self) -> &(dyn Error + 'a) { - self - } -} - -impl<'a> AsDynError<'a> for dyn Error + 'a { - #[inline] - fn as_dyn_error(&self) -> &(dyn Error + 'a) { - self - } -} - -impl<'a> AsDynError<'a> for dyn Error + Send + 'a { - #[inline] - fn as_dyn_error(&self) -> &(dyn Error + 'a) { - self - } -} - -impl<'a> AsDynError<'a> for dyn Error + Send + Sync + 'a { - #[inline] - fn as_dyn_error(&self) -> &(dyn Error + 'a) { - self - } -} - -impl<'a> AsDynError<'a> for dyn Error + Send + Sync + UnwindSafe + 'a { - #[inline] - fn as_dyn_error(&self) -> &(dyn Error + 'a) { - self - } -} - -#[doc(hidden)] -pub trait Sealed {} -impl<'a, T: Error + 'a> Sealed for T {} -impl<'a> Sealed for dyn Error + 'a {} -impl<'a> Sealed for dyn Error + Send + 'a {} -impl<'a> Sealed for dyn Error + Send + Sync + 'a {} -impl<'a> Sealed for dyn Error + Send + Sync + UnwindSafe + 'a {} diff --git a/xet_error/src/display.rs b/xet_error/src/display.rs deleted file mode 100644 index 27098f16..00000000 --- a/xet_error/src/display.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::fmt::Display; -use std::path::{self, Path, PathBuf}; - -#[doc(hidden)] -pub trait AsDisplay<'a> { - // TODO: convert to generic associated type. - // https://github.com/dtolnay/thiserror/pull/253 - type Target: Display; - - fn as_display(&'a self) -> Self::Target; -} - -impl<'a, T> AsDisplay<'a> for &T -where - T: Display + 'a, -{ - type Target = &'a T; - - fn as_display(&'a self) -> Self::Target { - *self - } -} - -impl<'a> AsDisplay<'a> for Path { - type Target = path::Display<'a>; - - #[inline] - fn as_display(&'a self) -> Self::Target { - self.display() - } -} - -impl<'a> AsDisplay<'a> for PathBuf { - type Target = path::Display<'a>; - - #[inline] - fn as_display(&'a self) -> Self::Target { - self.display() - } -} diff --git a/xet_error/src/lib.rs b/xet_error/src/lib.rs deleted file mode 100644 index 8eed23f0..00000000 --- a/xet_error/src/lib.rs +++ /dev/null @@ -1,259 +0,0 @@ -//! [![github]](https://github.com/dtolnay/thiserror) [![crates-io]](https://crates.io/crates/thiserror) [![docs-rs]](https://docs.rs/thiserror) -//! -//! [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 a convenient derive macro for the standard library's -//! [`std::error::Error`] trait. -//! -//! [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html -//! -//!
-//! -//! # Example -//! -//! ```rust -//! # use std::io; -//! use xet_error::Error; -//! -//! #[derive(Error, Debug)] -//! pub enum DataStoreError { -//! #[error("data store disconnected")] -//! Disconnect(#[from] io::Error), -//! #[error("the data for key `{0}` is not available")] -//! Redaction(String), -//! #[error("invalid header (expected {expected:?}, found {found:?})")] -//! InvalidHeader { expected: String, found: String }, -//! #[error("unknown data store error")] -//! Unknown, -//! } -//! ``` -//! -//!
-//! -//! # Details -//! -//! - Thiserror deliberately does not appear in your public API. You get the same thing as if you had written an -//! implementation of `std::error::Error` by hand, and switching from handwritten impls to xet_error or vice versa is -//! not a breaking change. -//! -//! - Errors may be enums, structs with named fields, tuple structs, or unit structs. -//! -//! - A `Display` impl is generated for your error if you provide `#[error("...")]` messages on the struct or each -//! variant of your enum, as shown above in the example. -//! -//! The messages support a shorthand for interpolating fields from the error. -//! -//! - `#[error("{var}")]` ⟶ `write!("{}", self.var)` -//! - `#[error("{0}")]` ⟶ `write!("{}", self.0)` -//! - `#[error("{var:?}")]` ⟶ `write!("{:?}", self.var)` -//! - `#[error("{0:?}")]` ⟶ `write!("{:?}", self.0)` -//! -//! These shorthands can be used together with any additional format args, -//! which may be arbitrary expressions. For example: -//! -//! ```rust -//! # use std::i32; -//! # use xet_error::Error; -//! # -//! #[derive(Error, Debug)] -//! pub enum Error { -//! #[error("invalid rdo_lookahead_frames {0} (expected < {})", i32::MAX)] -//! InvalidLookahead(u32), -//! } -//! ``` -//! -//! If one of the additional expression arguments needs to refer to a field of -//! the struct or enum, then refer to named fields as `.var` and tuple fields -//! as `.0`. -//! -//! ```rust -//! # use xet_error::Error; -//! # -//! # fn first_char(s: &String) -> char { -//! # s.chars().next().unwrap() -//! # } -//! # -//! # #[derive(Debug)] -//! # struct Limits { -//! # lo: usize, -//! # hi: usize, -//! # } -//! # -//! #[derive(Error, Debug)] -//! pub enum Error { -//! #[error("first letter must be lowercase but was {:?}", first_char(.0))] -//! WrongCase(String), -//! #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)] -//! OutOfBounds { idx: usize, limits: Limits }, -//! } -//! ``` -//! -//! - A `From` impl is generated for each variant containing a `#[from]` attribute. -//! -//! Note that the variant must not contain any other fields beyond the source -//! error and possibly a backtrace. A backtrace is captured from within the -//! `From` impl if there is a field for it. -//! -//! ```rust -//! # const IGNORE: &str = stringify! { -//! #[derive(Error, Debug)] -//! pub enum MyError { -//! Io { -//! #[from] -//! source: io::Error, -//! backtrace: Backtrace, -//! }, -//! } -//! # }; -//! ``` -//! -//! - The Error trait's `source()` method is implemented to return whichever field has a `#[source]` attribute or is -//! named `source`, if any. This is for identifying the underlying lower level error that caused your error. -//! -//! The `#[from]` attribute always implies that the same field is `#[source]`, -//! so you don't ever need to specify both attributes. -//! -//! Any error type that implements `std::error::Error` or dereferences to `dyn -//! std::error::Error` will work as a source. -//! -//! ```rust -//! # use std::fmt::{self, Display}; -//! # use xet_error::Error; -//! # -//! #[derive(Error, Debug)] -//! pub struct MyError { -//! msg: String, -//! #[source] // optional if field name is `source` -//! source: anyhow::Error, -//! } -//! # -//! # impl Display for MyError { -//! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { -//! # unimplemented!() -//! # } -//! # } -//! ``` -//! -//! - The Error trait's `provide()` method is implemented to provide whichever field has a type named `Backtrace`, if -//! any, as a `std::backtrace::Backtrace`. -//! -//! ```rust -//! # const IGNORE: &str = stringify! { -//! use std::backtrace::Backtrace; -//! -//! #[derive(Error, Debug)] -//! pub struct MyError { -//! msg: String, -//! backtrace: Backtrace, // automatically detected -//! } -//! # }; -//! ``` -//! -//! - If a field is both a source (named `source`, or has `#[source]` or `#[from]` attribute) *and* is marked -//! `#[backtrace]`, then the Error trait's `provide()` method is forwarded to the source's `provide` so that both -//! layers of the error share the same backtrace. -//! -//! ```rust -//! # const IGNORE: &str = stringify! { -//! #[derive(Error, Debug)] -//! pub enum MyError { -//! Io { -//! #[backtrace] -//! source: io::Error, -//! }, -//! } -//! # }; -//! ``` -//! -//! - Errors may use `error(transparent)` to forward the source and Display methods straight through to an underlying -//! error without adding an additional message. This would be appropriate for enums that need an "anything else" -//! variant. -//! -//! ``` -//! # use xet_error::Error; -//! # -//! #[derive(Error, Debug)] -//! pub enum MyError { -//! # /* -//! ... -//! # */ -//! -//! #[error(transparent)] -//! Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error -//! } -//! ``` -//! -//! Another use case is hiding implementation details of an error -//! representation behind an opaque error type, so that the representation is -//! able to evolve without breaking the crate's public API. -//! -//! ``` -//! # use xet_error::Error; -//! # -//! // PublicError is public, but opaque and easy to keep compatible. -//! #[derive(Error, Debug)] -//! #[error(transparent)] -//! pub struct PublicError(#[from] ErrorRepr); -//! -//! impl PublicError { -//! // Accessors for anything we do want to expose publicly. -//! } -//! -//! // Private and free to change across minor version of the crate. -//! #[derive(Error, Debug)] -//! enum ErrorRepr { -//! # /* -//! ... -//! # */ -//! } -//! ``` -//! -//! - See also the [`anyhow`] library for a convenient single error type to use in application code. -//! -//! [`anyhow`]: https://github.com/dtolnay/anyhow - -#![doc(html_root_url = "https://docs.rs/thiserror/1.0.50")] -#![allow( - clippy::module_name_repetitions, - clippy::needless_lifetimes, - clippy::return_self_not_must_use, - clippy::wildcard_imports -)] - -mod aserror; -mod display; -#[cfg(feature = "error_generic_member_access")] -mod provide; - -pub use xet_error_impl::*; - -// Not public API. -#[doc(hidden)] -pub mod __private { - #[doc(hidden)] - pub use crate::aserror::AsDynError; - #[doc(hidden)] - pub use crate::display::AsDisplay; - #[cfg(feature = "error_generic_member_access")] - #[doc(hidden)] - pub use crate::provide::ThiserrorProvide; -} - -use lazy_static::lazy_static; -lazy_static! { - static ref LOG_EXCEPTION_FUNCTION: std::sync::Mutex = std::sync::Mutex::new(|_| ()); -} - -pub fn enable_exception_logging(logger: fn(&str)) { - *(LOG_EXCEPTION_FUNCTION.lock().unwrap()) = logger; -} - -#[inline(never)] -#[no_mangle] -pub fn error_hook(source: &str) { - (LOG_EXCEPTION_FUNCTION.lock().unwrap())(source); -} diff --git a/xet_error/src/provide.rs b/xet_error/src/provide.rs deleted file mode 100644 index 20a26f36..00000000 --- a/xet_error/src/provide.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::error::{Error, Request}; - -#[doc(hidden)] -pub trait ThiserrorProvide: Sealed { - fn xet_error_provide<'a>(&'a self, request: &mut Request<'a>); -} - -impl ThiserrorProvide for T -where - T: Error + ?Sized, -{ - #[inline] - fn xet_error_provide<'a>(&'a self, request: &mut Request<'a>) { - self.provide(request); - } -} - -#[doc(hidden)] -pub trait Sealed {} -impl Sealed for T {} diff --git a/xet_error/tests/compiletest.rs b/xet_error/tests/compiletest.rs deleted file mode 100644 index 7974a624..00000000 --- a/xet_error/tests/compiletest.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[rustversion::attr(not(nightly), ignore)] -#[cfg_attr(miri, ignore)] -#[test] -fn ui() { - let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/*.rs"); -} diff --git a/xet_error/tests/test_backtrace.rs b/xet_error/tests/test_backtrace.rs deleted file mode 100644 index 230aa56b..00000000 --- a/xet_error/tests/test_backtrace.rs +++ /dev/null @@ -1,276 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("...")] -pub struct Inner; - -#[cfg(feature = "error_generic_member_access")] -#[derive(Error, Debug)] -#[error("...")] -pub struct InnerBacktrace { - backtrace: std::backtrace::Backtrace, -} - -#[cfg(feature = "error_generic_member_access")] -pub mod structs { - use std::backtrace::Backtrace; - use std::error::{self, Error}; - use std::sync::Arc; - - use xet_error::Error; - - use super::{Inner, InnerBacktrace}; - - #[derive(Error, Debug)] - #[error("...")] - pub struct PlainBacktrace { - backtrace: Backtrace, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct ExplicitBacktrace { - #[backtrace] - backtrace: Backtrace, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct OptBacktrace { - #[backtrace] - backtrace: Option, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct ArcBacktrace { - #[backtrace] - backtrace: Arc, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct BacktraceFrom { - #[from] - source: Inner, - #[backtrace] - backtrace: Backtrace, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct CombinedBacktraceFrom { - #[from] - #[backtrace] - source: InnerBacktrace, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct OptBacktraceFrom { - #[from] - source: Inner, - #[backtrace] - backtrace: Option, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct ArcBacktraceFrom { - #[from] - source: Inner, - #[backtrace] - backtrace: Arc, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct AnyhowBacktrace { - #[backtrace] - source: anyhow::Error, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct BoxDynErrorBacktrace { - #[backtrace] - source: Box, - } - - #[test] - fn test_backtrace() { - let error = PlainBacktrace { - backtrace: Backtrace::capture(), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = ExplicitBacktrace { - backtrace: Backtrace::capture(), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = OptBacktrace { - backtrace: Some(Backtrace::capture()), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = ArcBacktrace { - backtrace: Arc::new(Backtrace::capture()), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = BacktraceFrom::from(Inner); - assert!(error::request_ref::(&error).is_some()); - - let error = CombinedBacktraceFrom::from(InnerBacktrace { - backtrace: Backtrace::capture(), - }); - assert!(error::request_ref::(&error).is_some()); - - let error = OptBacktraceFrom::from(Inner); - assert!(error::request_ref::(&error).is_some()); - - let error = ArcBacktraceFrom::from(Inner); - assert!(error::request_ref::(&error).is_some()); - - let error = AnyhowBacktrace { - source: anyhow::Error::msg("..."), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = BoxDynErrorBacktrace { - source: Box::new(PlainBacktrace { - backtrace: Backtrace::capture(), - }), - }; - assert!(error::request_ref::(&error).is_some()); - } -} - -#[cfg(feature = "error_generic_member_access")] -pub mod enums { - use std::backtrace::Backtrace; - use std::error; - use std::sync::Arc; - - use xet_error::Error; - - use super::{Inner, InnerBacktrace}; - - #[derive(Error, Debug)] - pub enum PlainBacktrace { - #[error("...")] - Test { backtrace: Backtrace }, - } - - #[derive(Error, Debug)] - pub enum ExplicitBacktrace { - #[error("...")] - Test { - #[backtrace] - backtrace: Backtrace, - }, - } - - #[derive(Error, Debug)] - pub enum OptBacktrace { - #[error("...")] - Test { - #[backtrace] - backtrace: Option, - }, - } - - #[derive(Error, Debug)] - pub enum ArcBacktrace { - #[error("...")] - Test { - #[backtrace] - backtrace: Arc, - }, - } - - #[derive(Error, Debug)] - pub enum BacktraceFrom { - #[error("...")] - Test { - #[from] - source: Inner, - #[backtrace] - backtrace: Backtrace, - }, - } - - #[derive(Error, Debug)] - pub enum CombinedBacktraceFrom { - #[error("...")] - Test { - #[from] - #[backtrace] - source: InnerBacktrace, - }, - } - - #[derive(Error, Debug)] - pub enum OptBacktraceFrom { - #[error("...")] - Test { - #[from] - source: Inner, - #[backtrace] - backtrace: Option, - }, - } - - #[derive(Error, Debug)] - pub enum ArcBacktraceFrom { - #[error("...")] - Test { - #[from] - source: Inner, - #[backtrace] - backtrace: Arc, - }, - } - - #[test] - fn test_backtrace() { - let error = PlainBacktrace::Test { - backtrace: Backtrace::capture(), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = ExplicitBacktrace::Test { - backtrace: Backtrace::capture(), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = OptBacktrace::Test { - backtrace: Some(Backtrace::capture()), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = ArcBacktrace::Test { - backtrace: Arc::new(Backtrace::capture()), - }; - assert!(error::request_ref::(&error).is_some()); - - let error = BacktraceFrom::from(Inner); - assert!(error::request_ref::(&error).is_some()); - - let error = CombinedBacktraceFrom::from(InnerBacktrace { - backtrace: Backtrace::capture(), - }); - assert!(error::request_ref::(&error).is_some()); - - let error = OptBacktraceFrom::from(Inner); - assert!(error::request_ref::(&error).is_some()); - - let error = ArcBacktraceFrom::from(Inner); - assert!(error::request_ref::(&error).is_some()); - } -} - -#[test] -#[cfg_attr(not(feature = "error_generic_member_access"), ignore)] -fn test_backtrace() {} diff --git a/xet_error/tests/test_deprecated.rs b/xet_error/tests/test_deprecated.rs deleted file mode 100644 index 719b1b82..00000000 --- a/xet_error/tests/test_deprecated.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![deny(deprecated, clippy::all, clippy::pedantic)] - -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[deprecated] - #[error("...")] - Deprecated, -} diff --git a/xet_error/tests/test_display.rs b/xet_error/tests/test_display.rs deleted file mode 100644 index e9679eb7..00000000 --- a/xet_error/tests/test_display.rs +++ /dev/null @@ -1,292 +0,0 @@ -#![allow(clippy::uninlined_format_args)] - -use std::fmt::{self, Display}; - -use xet_error::Error; - -fn assert(expected: &str, value: T) { - assert_eq!(expected, value.to_string()); -} - -#[test] -fn test_braced() { - #[derive(Error, Debug)] - #[error("braced error: {msg}")] - struct Error { - msg: String, - } - - let msg = "T".to_owned(); - assert("braced error: T", Error { msg }); -} - -#[test] -fn test_braced_unused() { - #[derive(Error, Debug)] - #[error("braced error")] - struct Error { - extra: usize, - } - - assert("braced error", Error { extra: 0 }); -} - -#[test] -fn test_tuple() { - #[derive(Error, Debug)] - #[error("tuple error: {0}")] - struct Error(usize); - - assert("tuple error: 0", Error(0)); -} - -#[test] -fn test_unit() { - #[derive(Error, Debug)] - #[error("unit error")] - struct Error; - - assert("unit error", Error); -} - -#[test] -fn test_enum() { - #[derive(Error, Debug)] - enum Error { - #[error("braced error: {id}")] - Braced { id: usize }, - #[error("tuple error: {0}")] - Tuple(usize), - #[error("unit error")] - Unit, - } - - assert("braced error: 0", Error::Braced { id: 0 }); - assert("tuple error: 0", Error::Tuple(0)); - assert("unit error", Error::Unit); -} - -#[test] -fn test_constants() { - #[derive(Error, Debug)] - #[error("{MSG}: {id:?} (code {CODE:?})")] - struct Error { - id: &'static str, - } - - const MSG: &str = "failed to do"; - const CODE: usize = 9; - - assert("failed to do: \"\" (code 9)", Error { id: "" }); -} - -#[test] -fn test_inherit() { - #[derive(Error, Debug)] - #[error("{0}")] - enum Error { - Some(&'static str), - #[error("other error")] - Other(&'static str), - } - - assert("some error", Error::Some("some error")); - assert("other error", Error::Other("...")); -} - -#[test] -fn test_brace_escape() { - #[derive(Error, Debug)] - #[error("fn main() {{}}")] - struct Error; - - assert("fn main() {}", Error); -} - -#[test] -fn test_expr() { - #[derive(Error, Debug)] - #[error("1 + 1 = {}", 1 + 1)] - struct Error; - assert("1 + 1 = 2", Error); -} - -#[test] -fn test_nested() { - #[derive(Error, Debug)] - #[error("!bool = {}", not(.0))] - struct Error(bool); - - #[allow(clippy::trivially_copy_pass_by_ref)] - fn not(bool: &bool) -> bool { - !*bool - } - - assert("!bool = false", Error(true)); -} - -#[test] -fn test_match() { - #[derive(Error, Debug)] - #[error("{}: {0}", match .1 { - Some(n) => format!("error occurred with {}", n), - None => "there was an empty error".to_owned(), - })] - struct Error(String, Option); - - assert("error occurred with 1: ...", Error("...".to_owned(), Some(1))); - assert("there was an empty error: ...", Error("...".to_owned(), None)); -} - -#[test] -fn test_nested_display() { - // Same behavior as the one in `test_match`, but without String allocations. - #[derive(Error, Debug)] - #[error("{}", { - struct Msg<'a>(&'a String, &'a Option); - impl<'a> Display for Msg<'a> { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - match self.1 { - Some(n) => write!(formatter, "error occurred with {}", n), - None => write!(formatter, "there was an empty error"), - }?; - write!(formatter, ": {}", self.0) - } - } - Msg(.0, .1) - })] - struct Error(String, Option); - - assert("error occurred with 1: ...", Error("...".to_owned(), Some(1))); - assert("there was an empty error: ...", Error("...".to_owned(), None)); -} - -#[test] -fn test_void() { - #[allow(clippy::empty_enum)] - #[derive(Error, Debug)] - #[error("...")] - pub enum Error {} - - let _: Error; -} - -#[test] -fn test_mixed() { - #[derive(Error, Debug)] - #[error("a={a} :: b={} :: c={c} :: d={d}", 1, c = 2, d = 3)] - struct Error { - a: usize, - d: usize, - } - - assert("a=0 :: b=1 :: c=2 :: d=3", Error { a: 0, d: 0 }); -} - -#[test] -fn test_ints() { - #[derive(Error, Debug)] - enum Error { - #[error("error {0}")] - Tuple(usize, usize), - #[error("error {0}", '?')] - Struct { v: usize }, - } - - assert("error 9", Error::Tuple(9, 0)); - assert("error ?", Error::Struct { v: 0 }); -} - -#[test] -fn test_trailing_comma() { - #[derive(Error, Debug)] - #[error( - "error {0}", - )] - #[rustfmt::skip] - struct Error(char); - - assert("error ?", Error('?')); -} - -#[test] -fn test_field() { - #[derive(Debug)] - struct Inner { - data: usize, - } - - #[derive(Error, Debug)] - #[error("{}", .0.data)] - struct Error(Inner); - - assert("0", Error(Inner { data: 0 })); -} - -#[test] -fn test_macro_rules() { - // Regression test for https://github.com/dtolnay/thiserror/issues/86 - - macro_rules! decl_error { - ($variant:ident($value:ident)) => { - #[derive(Debug, Error)] - pub enum Error0 { - #[error("{0:?}")] - $variant($value), - } - - #[derive(Debug, Error)] - #[error("{0:?}")] - pub enum Error1 { - $variant($value), - } - }; - } - - decl_error!(Repro(u8)); - - assert("0", Error0::Repro(0)); - assert("0", Error1::Repro(0)); -} - -#[test] -fn test_raw() { - #[derive(Error, Debug)] - #[error("braced raw error: {r#fn}")] - struct Error { - r#fn: &'static str, - } - - assert("braced raw error: T", Error { r#fn: "T" }); -} - -#[test] -fn test_raw_enum() { - #[derive(Error, Debug)] - enum Error { - #[error("braced raw error: {r#fn}")] - Braced { r#fn: &'static str }, - } - - assert("braced raw error: T", Error::Braced { r#fn: "T" }); -} - -#[test] -fn test_raw_conflict() { - #[derive(Error, Debug)] - enum Error { - #[error("braced raw error: {r#func}, {func}", func = "U")] - Braced { r#func: &'static str }, - } - - assert("braced raw error: T, U", Error::Braced { r#func: "T" }); -} - -#[test] -fn test_keyword() { - #[derive(Error, Debug)] - #[error("error: {type}", type = 1)] - struct Error; - - assert("error: 1", Error); -} diff --git a/xet_error/tests/test_error.rs b/xet_error/tests/test_error.rs deleted file mode 100644 index 7041bd8d..00000000 --- a/xet_error/tests/test_error.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(dead_code)] - -use std::fmt::{self, Display}; -use std::io; - -use xet_error::Error; - -macro_rules! unimplemented_display { - ($ty:ty) => { - impl Display for $ty { - fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { - unimplemented!() - } - } - }; -} - -#[derive(Error, Debug)] -struct BracedError { - msg: String, - pos: usize, -} - -#[derive(Error, Debug)] -struct TupleError(String, usize); - -#[derive(Error, Debug)] -struct UnitError; - -#[derive(Error, Debug)] -struct WithSource { - #[source] - cause: io::Error, -} - -#[derive(Error, Debug)] -struct WithAnyhow { - #[source] - cause: anyhow::Error, -} - -#[derive(Error, Debug)] -enum EnumError { - Braced { - #[source] - cause: io::Error, - }, - Tuple(#[source] io::Error), - Unit, -} - -unimplemented_display!(BracedError); -unimplemented_display!(TupleError); -unimplemented_display!(UnitError); -unimplemented_display!(WithSource); -unimplemented_display!(WithAnyhow); -unimplemented_display!(EnumError); diff --git a/xet_error/tests/test_expr.rs b/xet_error/tests/test_expr.rs deleted file mode 100644 index e74e4aa2..00000000 --- a/xet_error/tests/test_expr.rs +++ /dev/null @@ -1,87 +0,0 @@ -#![allow( - clippy::iter_cloned_collect, - clippy::option_if_let_else, - clippy::uninlined_format_args -)] - -use std::fmt::Display; - -use xet_error::Error; - -// Some of the elaborate cases from the rcc codebase, which is a C compiler in -// Rust. https://github.com/jyn514/rcc/blob/0.8.0/src/data/error.rs -#[derive(Error, Debug)] -pub enum CompilerError { - #[error("cannot shift {} by {maximum} or more bits (got {current})", if *.is_left { "left" } else { "right" })] - TooManyShiftBits { is_left: bool, maximum: u64, current: u64 }, - - #[error("#error {}", (.0).iter().copied().collect::>().join(" "))] - User(Vec<&'static str>), - - #[error("overflow while parsing {}integer literal", - if let Some(signed) = .is_signed { - if *signed { "signed "} else { "unsigned "} - } else { - "" - } - )] - IntegerOverflow { is_signed: Option }, - - #[error("overflow while parsing {}integer literal", match .is_signed { - Some(true) => "signed ", - Some(false) => "unsigned ", - None => "", - })] - IntegerOverflow2 { is_signed: Option }, -} - -// Examples drawn from Rustup. -#[derive(Error, Debug)] -pub enum RustupError { - #[error( - "toolchain '{name}' does not contain component {component}{}", - .suggestion - .as_ref() - .map_or_else(String::new, |s| format!("; did you mean '{}'?", s)), - )] - UnknownComponent { - name: String, - component: String, - suggestion: Option, - }, -} - -fn assert(expected: &str, value: T) { - assert_eq!(expected, value.to_string()); -} - -#[test] -fn test_rcc() { - assert( - "cannot shift left by 32 or more bits (got 50)", - CompilerError::TooManyShiftBits { - is_left: true, - maximum: 32, - current: 50, - }, - ); - - assert("#error A B C", CompilerError::User(vec!["A", "B", "C"])); - - assert( - "overflow while parsing signed integer literal", - CompilerError::IntegerOverflow { is_signed: Some(true) }, - ); -} - -#[test] -fn test_rustup() { - assert( - "toolchain 'nightly' does not contain component clipy; did you mean 'clippy'?", - RustupError::UnknownComponent { - name: "nightly".to_owned(), - component: "clipy".to_owned(), - suggestion: Some("clippy".to_owned()), - }, - ); -} diff --git a/xet_error/tests/test_from.rs b/xet_error/tests/test_from.rs deleted file mode 100644 index 09bd1a1f..00000000 --- a/xet_error/tests/test_from.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![allow(clippy::extra_unused_type_parameters)] - -use std::io; - -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("...")] -pub struct ErrorStruct { - #[from] - source: io::Error, -} - -#[derive(Error, Debug)] -#[error("...")] -pub struct ErrorStructOptional { - #[from] - source: Option, -} - -#[derive(Error, Debug)] -#[error("...")] -pub struct ErrorTuple(#[from] io::Error); - -#[derive(Error, Debug)] -#[error("...")] -pub struct ErrorTupleOptional(#[from] Option); - -#[derive(Error, Debug)] -#[error("...")] -pub enum ErrorEnum { - Test { - #[from] - source: io::Error, - }, -} - -#[derive(Error, Debug)] -#[error("...")] -pub enum ErrorEnumOptional { - Test { - #[from] - source: Option, - }, -} - -#[derive(Error, Debug)] -#[error("...")] -pub enum Many { - Any(#[from] anyhow::Error), - Io(#[from] io::Error), -} - -fn assert_impl>() {} - -#[test] -fn test_from() { - assert_impl::(); - assert_impl::(); - assert_impl::(); - assert_impl::(); - assert_impl::(); - assert_impl::(); - assert_impl::(); -} diff --git a/xet_error/tests/test_generics.rs b/xet_error/tests/test_generics.rs deleted file mode 100644 index 54a207ab..00000000 --- a/xet_error/tests/test_generics.rs +++ /dev/null @@ -1,162 +0,0 @@ -#![allow(clippy::needless_late_init, clippy::uninlined_format_args)] - -use std::fmt::{self, Debug, Display}; - -use xet_error::Error; - -pub struct NoFormat; - -#[derive(Debug)] -pub struct DebugOnly; - -pub struct DisplayOnly; - -impl Display for DisplayOnly { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("display only") - } -} - -#[derive(Debug)] -pub struct DebugAndDisplay; - -impl Display for DebugAndDisplay { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("debug and display") - } -} - -// Should expand to: -// -// impl Display for EnumDebugField -// where -// E: Debug; -// -// impl Error for EnumDebugField -// where -// Self: Debug + Display; -// -#[derive(Error, Debug)] -pub enum EnumDebugGeneric { - #[error("{0:?}")] - FatalError(E), -} - -// Should expand to: -// -// impl Display for EnumFromGeneric; -// -// impl Error for EnumFromGeneric -// where -// EnumDebugGeneric: Error + 'static, -// Self: Debug + Display; -// -#[derive(Error, Debug)] -pub enum EnumFromGeneric { - #[error("enum from generic")] - Source(#[from] EnumDebugGeneric), -} - -// Should expand to: -// -// impl Display -// for EnumCompound -// where -// HasDisplay: Display, -// HasDebug: Debug; -// -// impl Error -// for EnumCompound -// where -// Self: Debug + Display; -// -#[derive(Error)] -pub enum EnumCompound { - #[error("{0} {1:?}")] - DisplayDebug(HasDisplay, HasDebug), - #[error("{0}")] - Display(HasDisplay, HasNeither), - #[error("{1:?}")] - Debug(HasNeither, HasDebug), -} - -impl Debug for EnumCompound { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("EnumCompound") - } -} - -#[test] -fn test_display_enum_compound() { - let mut instance: EnumCompound; - - instance = EnumCompound::DisplayDebug(DisplayOnly, DebugOnly); - assert_eq!(format!("{}", instance), "display only DebugOnly"); - - instance = EnumCompound::Display(DisplayOnly, NoFormat); - assert_eq!(format!("{}", instance), "display only"); - - instance = EnumCompound::Debug(NoFormat, DebugOnly); - assert_eq!(format!("{}", instance), "DebugOnly"); -} - -// Should expand to: -// -// impl Display for EnumTransparentGeneric -// where -// E: Display; -// -// impl Error for EnumTransparentGeneric -// where -// E: Error, -// Self: Debug + Display; -// -#[derive(Error, Debug)] -pub enum EnumTransparentGeneric { - #[error(transparent)] - Other(E), -} - -// Should expand to: -// -// impl Display for StructDebugGeneric -// where -// E: Debug; -// -// impl Error for StructDebugGeneric -// where -// Self: Debug + Display; -// -#[derive(Error, Debug)] -#[error("{underlying:?}")] -pub struct StructDebugGeneric { - pub underlying: E, -} - -// Should expand to: -// -// impl Error for StructFromGeneric -// where -// StructDebugGeneric: Error + 'static, -// Self: Debug + Display; -// -#[derive(Error, Debug)] -pub struct StructFromGeneric { - #[from] - pub source: StructDebugGeneric, -} - -// Should expand to: -// -// impl Display for StructTransparentGeneric -// where -// E: Display; -// -// impl Error for StructTransparentGeneric -// where -// E: Error, -// Self: Debug + Display; -// -#[derive(Error, Debug)] -#[error(transparent)] -pub struct StructTransparentGeneric(E); diff --git a/xet_error/tests/test_lints.rs b/xet_error/tests/test_lints.rs deleted file mode 100644 index 5f9f1e2c..00000000 --- a/xet_error/tests/test_lints.rs +++ /dev/null @@ -1,18 +0,0 @@ -pub use std::error::Error; - -use xet_error::Error; - -#[test] -fn test_unused_qualifications() { - #![deny(unused_qualifications)] - - // Expansion of derive(Error) macro can't know whether something like - // std::error::Error is already imported in the caller's scope so it must - // suppress unused_qualifications. - - #[derive(Debug, Error)] - #[error("...")] - pub struct MyError; - - let _: MyError; -} diff --git a/xet_error/tests/test_option.rs b/xet_error/tests/test_option.rs deleted file mode 100644 index 70b5ad32..00000000 --- a/xet_error/tests/test_option.rs +++ /dev/null @@ -1,105 +0,0 @@ -#[cfg(feature = "error_generic_member_access")] -pub mod structs { - use std::backtrace::Backtrace; - - use xet_error::Error; - - #[derive(Error, Debug)] - #[error("...")] - pub struct OptSourceNoBacktrace { - #[source] - source: Option, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct OptSourceAlwaysBacktrace { - #[source] - source: Option, - backtrace: Backtrace, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct NoSourceOptBacktrace { - #[backtrace] - backtrace: Option, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct AlwaysSourceOptBacktrace { - source: anyhow::Error, - #[backtrace] - backtrace: Option, - } - - #[derive(Error, Debug)] - #[error("...")] - pub struct OptSourceOptBacktrace { - #[source] - source: Option, - #[backtrace] - backtrace: Option, - } -} - -#[cfg(feature = "error_generic_member_access")] -pub mod enums { - use std::backtrace::Backtrace; - - use xet_error::Error; - - #[derive(Error, Debug)] - pub enum OptSourceNoBacktrace { - #[error("...")] - Test { - #[source] - source: Option, - }, - } - - #[derive(Error, Debug)] - pub enum OptSourceAlwaysBacktrace { - #[error("...")] - Test { - #[source] - source: Option, - backtrace: Backtrace, - }, - } - - #[derive(Error, Debug)] - pub enum NoSourceOptBacktrace { - #[error("...")] - Test { - #[backtrace] - backtrace: Option, - }, - } - - #[derive(Error, Debug)] - pub enum AlwaysSourceOptBacktrace { - #[error("...")] - Test { - source: anyhow::Error, - #[backtrace] - backtrace: Option, - }, - } - - #[derive(Error, Debug)] - pub enum OptSourceOptBacktrace { - #[error("...")] - Test { - #[source] - source: Option, - #[backtrace] - backtrace: Option, - }, - } -} - -#[test] -#[cfg_attr(not(feature = "error_generic_member_access"), ignore)] -fn test_option() {} diff --git a/xet_error/tests/test_path.rs b/xet_error/tests/test_path.rs deleted file mode 100644 index 09f74cb8..00000000 --- a/xet_error/tests/test_path.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::fmt::Display; -use std::path::{Path, PathBuf}; - -use ref_cast::RefCast; -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("failed to read '{file}'")] -struct StructPathBuf { - file: PathBuf, -} - -#[derive(Error, Debug, RefCast)] -#[repr(C)] -#[error("failed to read '{file}'")] -struct StructPath { - file: Path, -} - -#[derive(Error, Debug)] -enum EnumPathBuf { - #[error("failed to read '{0}'")] - Read(PathBuf), -} - -fn assert(expected: &str, value: T) { - assert_eq!(expected, value.to_string()); -} - -#[test] -fn test_display() { - let path = Path::new("/thiserror"); - let file = path.to_owned(); - assert("failed to read '/thiserror'", StructPathBuf { file }); - let file = path.to_owned(); - assert("failed to read '/thiserror'", EnumPathBuf::Read(file)); - assert("failed to read '/thiserror'", StructPath::ref_cast(path)); -} diff --git a/xet_error/tests/test_source.rs b/xet_error/tests/test_source.rs deleted file mode 100644 index 01a52fe6..00000000 --- a/xet_error/tests/test_source.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::error::Error as StdError; -use std::io; - -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("implicit source")] -pub struct ImplicitSource { - source: io::Error, -} - -#[derive(Error, Debug)] -#[error("explicit source")] -pub struct ExplicitSource { - source: String, - #[source] - io: io::Error, -} - -#[derive(Error, Debug)] -#[error("boxed source")] -pub struct BoxedSource { - #[source] - source: Box, -} - -#[test] -fn test_implicit_source() { - let io = io::Error::new(io::ErrorKind::Other, "oh no!"); - let error = ImplicitSource { source: io }; - error.source().unwrap().downcast_ref::().unwrap(); -} - -#[test] -fn test_explicit_source() { - let io = io::Error::new(io::ErrorKind::Other, "oh no!"); - let error = ExplicitSource { - source: String::new(), - io, - }; - error.source().unwrap().downcast_ref::().unwrap(); -} - -#[test] -fn test_boxed_source() { - let source = Box::new(io::Error::new(io::ErrorKind::Other, "oh no!")); - let error = BoxedSource { source }; - error.source().unwrap().downcast_ref::().unwrap(); -} - -macro_rules! error_from_macro { - ($($variants:tt)*) => { - #[derive(Error)] - #[derive(Debug)] - pub enum MacroSource { - $($variants)* - } - } -} - -// Test that we generate impls with the proper hygiene -#[rustfmt::skip] -error_from_macro! { - #[error("Something")] - Variant(#[from] io::Error) -} diff --git a/xet_error/tests/test_transparent.rs b/xet_error/tests/test_transparent.rs deleted file mode 100644 index 2cc99999..00000000 --- a/xet_error/tests/test_transparent.rs +++ /dev/null @@ -1,79 +0,0 @@ -use std::error::Error as _; -use std::io; - -use anyhow::anyhow; -use xet_error::Error; - -#[test] -fn test_transparent_struct() { - #[derive(Error, Debug)] - #[error(transparent)] - struct Error(ErrorKind); - - #[derive(Error, Debug)] - enum ErrorKind { - #[error("E0")] - E0, - #[error("E1")] - E1(#[from] io::Error), - } - - let error = Error(ErrorKind::E0); - assert_eq!("E0", error.to_string()); - assert!(error.source().is_none()); - - let io = io::Error::new(io::ErrorKind::Other, "oh no!"); - let error = Error(ErrorKind::from(io)); - assert_eq!("E1", error.to_string()); - error.source().unwrap().downcast_ref::().unwrap(); -} - -#[test] -fn test_transparent_enum() { - #[derive(Error, Debug)] - enum Error { - #[error("this failed")] - This, - #[error(transparent)] - Other(anyhow::Error), - } - - let error = Error::This; - assert_eq!("this failed", error.to_string()); - - let error = Error::Other(anyhow!("inner").context("outer")); - assert_eq!("outer", error.to_string()); - assert_eq!("inner", error.source().unwrap().to_string()); -} - -#[test] -fn test_anyhow() { - #[derive(Error, Debug)] - #[error(transparent)] - struct Any(#[from] anyhow::Error); - - let error = Any::from(anyhow!("inner").context("outer")); - assert_eq!("outer", error.to_string()); - assert_eq!("inner", error.source().unwrap().to_string()); -} - -#[test] -fn test_non_static() { - #[derive(Error, Debug)] - #[error(transparent)] - struct Error<'a> { - inner: ErrorKind<'a>, - } - - #[derive(Error, Debug)] - enum ErrorKind<'a> { - #[error("unexpected token: {:?}", token)] - Unexpected { token: &'a str }, - } - - let error = Error { - inner: ErrorKind::Unexpected { token: "error" }, - }; - assert_eq!("unexpected token: \"error\"", error.to_string()); - assert!(error.source().is_none()); -} diff --git a/xet_error/tests/ui/bad-field-attr.rs b/xet_error/tests/ui/bad-field-attr.rs deleted file mode 100644 index a02992c4..00000000 --- a/xet_error/tests/ui/bad-field-attr.rs +++ /dev/null @@ -1,7 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -pub struct Error(#[error(transparent)] std::io::Error); - -fn main() {} diff --git a/xet_error/tests/ui/bad-field-attr.stderr b/xet_error/tests/ui/bad-field-attr.stderr deleted file mode 100644 index 5fb57441..00000000 --- a/xet_error/tests/ui/bad-field-attr.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: #[error(transparent)] needs to go outside the enum or struct, not on an individual field - --> tests/ui/bad-field-attr.rs:5:18 - | -5 | pub struct Error(#[error(transparent)] std::io::Error); - | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/concat-display.rs b/xet_error/tests/ui/concat-display.rs deleted file mode 100644 index b99f58ad..00000000 --- a/xet_error/tests/ui/concat-display.rs +++ /dev/null @@ -1,15 +0,0 @@ -use xet_error::Error; - -macro_rules! error_type { - ($name:ident, $what:expr) => { - // Use #[error("invalid {}", $what)] instead. - - #[derive(Error, Debug)] - #[error(concat!("invalid ", $what))] - pub struct $name; - }; -} - -error_type!(Error, "foo"); - -fn main() {} diff --git a/xet_error/tests/ui/concat-display.stderr b/xet_error/tests/ui/concat-display.stderr deleted file mode 100644 index dbecd69f..00000000 --- a/xet_error/tests/ui/concat-display.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: expected string literal - --> tests/ui/concat-display.rs:8:17 - | -8 | #[error(concat!("invalid ", $what))] - | ^^^^^^ -... -13 | error_type!(Error, "foo"); - | ------------------------- in this macro invocation - | - = note: this error originates in the macro `error_type` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/xet_error/tests/ui/duplicate-enum-source.rs b/xet_error/tests/ui/duplicate-enum-source.rs deleted file mode 100644 index c5e6981c..00000000 --- a/xet_error/tests/ui/duplicate-enum-source.rs +++ /dev/null @@ -1,13 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum ErrorEnum { - Confusing { - #[source] - a: std::io::Error, - #[source] - b: anyhow::Error, - }, -} - -fn main() {} diff --git a/xet_error/tests/ui/duplicate-enum-source.stderr b/xet_error/tests/ui/duplicate-enum-source.stderr deleted file mode 100644 index 4a4b2d39..00000000 --- a/xet_error/tests/ui/duplicate-enum-source.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: duplicate #[source] attribute - --> tests/ui/duplicate-enum-source.rs:8:9 - | -8 | #[source] - | ^^^^^^^^^ diff --git a/xet_error/tests/ui/duplicate-fmt.rs b/xet_error/tests/ui/duplicate-fmt.rs deleted file mode 100644 index 034967f9..00000000 --- a/xet_error/tests/ui/duplicate-fmt.rs +++ /dev/null @@ -1,8 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("...")] -#[error("...")] -pub struct Error; - -fn main() {} diff --git a/xet_error/tests/ui/duplicate-fmt.stderr b/xet_error/tests/ui/duplicate-fmt.stderr deleted file mode 100644 index 532b16bd..00000000 --- a/xet_error/tests/ui/duplicate-fmt.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: only one #[error(...)] attribute is allowed - --> tests/ui/duplicate-fmt.rs:5:1 - | -5 | #[error("...")] - | ^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/duplicate-struct-source.rs b/xet_error/tests/ui/duplicate-struct-source.rs deleted file mode 100644 index 01d706e6..00000000 --- a/xet_error/tests/ui/duplicate-struct-source.rs +++ /dev/null @@ -1,11 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub struct ErrorStruct { - #[source] - a: std::io::Error, - #[source] - b: anyhow::Error, -} - -fn main() {} diff --git a/xet_error/tests/ui/duplicate-struct-source.stderr b/xet_error/tests/ui/duplicate-struct-source.stderr deleted file mode 100644 index c8de5747..00000000 --- a/xet_error/tests/ui/duplicate-struct-source.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: duplicate #[source] attribute - --> tests/ui/duplicate-struct-source.rs:7:5 - | -7 | #[source] - | ^^^^^^^^^ diff --git a/xet_error/tests/ui/duplicate-transparent.rs b/xet_error/tests/ui/duplicate-transparent.rs deleted file mode 100644 index 8fbe57ae..00000000 --- a/xet_error/tests/ui/duplicate-transparent.rs +++ /dev/null @@ -1,8 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -#[error(transparent)] -pub struct Error(anyhow::Error); - -fn main() {} diff --git a/xet_error/tests/ui/duplicate-transparent.stderr b/xet_error/tests/ui/duplicate-transparent.stderr deleted file mode 100644 index a8308790..00000000 --- a/xet_error/tests/ui/duplicate-transparent.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: duplicate #[error(transparent)] attribute - --> tests/ui/duplicate-transparent.rs:5:1 - | -5 | #[error(transparent)] - | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/from-backtrace-backtrace.rs b/xet_error/tests/ui/from-backtrace-backtrace.rs deleted file mode 100644 index cb6203a5..00000000 --- a/xet_error/tests/ui/from-backtrace-backtrace.rs +++ /dev/null @@ -1,15 +0,0 @@ -// https://github.com/dtolnay/thiserror/issues/163 - -use std::backtrace::Backtrace; -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("...")] -pub struct Error( - #[from] - #[backtrace] - std::io::Error, - Backtrace, -); - -fn main() {} diff --git a/xet_error/tests/ui/from-backtrace-backtrace.stderr b/xet_error/tests/ui/from-backtrace-backtrace.stderr deleted file mode 100644 index 5c0b9a3b..00000000 --- a/xet_error/tests/ui/from-backtrace-backtrace.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: deriving From requires no fields other than source and backtrace - --> tests/ui/from-backtrace-backtrace.rs:9:5 - | -9 | #[from] - | ^^^^^^^ diff --git a/xet_error/tests/ui/from-not-source.rs b/xet_error/tests/ui/from-not-source.rs deleted file mode 100644 index bca0261a..00000000 --- a/xet_error/tests/ui/from-not-source.rs +++ /dev/null @@ -1,11 +0,0 @@ -use xet_error::Error; - -#[derive(Debug, Error)] -pub struct Error { - #[source] - source: std::io::Error, - #[from] - other: anyhow::Error, -} - -fn main() {} diff --git a/xet_error/tests/ui/from-not-source.stderr b/xet_error/tests/ui/from-not-source.stderr deleted file mode 100644 index 97136017..00000000 --- a/xet_error/tests/ui/from-not-source.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: #[from] is only supported on the source field, not any other field - --> tests/ui/from-not-source.rs:7:5 - | -7 | #[from] - | ^^^^^^^ diff --git a/xet_error/tests/ui/lifetime.rs b/xet_error/tests/ui/lifetime.rs deleted file mode 100644 index 00946b6c..00000000 --- a/xet_error/tests/ui/lifetime.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::fmt::Debug; -use xet_error::Error; - -#[derive(Error, Debug)] -#[error("error")] -struct Error<'a>(#[from] Inner<'a>); - -#[derive(Error, Debug)] -#[error("{0}")] -struct Inner<'a>(&'a str); - -#[derive(Error, Debug)] -enum Enum<'a> { - #[error("error")] - Foo(#[from] Generic<&'a str>), -} - -#[derive(Error, Debug)] -#[error("{0:?}")] -struct Generic(T); - -fn main() -> Result<(), Error<'static>> { - Err(Error(Inner("some text"))) -} diff --git a/xet_error/tests/ui/lifetime.stderr b/xet_error/tests/ui/lifetime.stderr deleted file mode 100644 index 8b58136e..00000000 --- a/xet_error/tests/ui/lifetime.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static - --> tests/ui/lifetime.rs:6:26 - | -6 | struct Error<'a>(#[from] Inner<'a>); - | ^^^^^^^^^ - -error: non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static - --> tests/ui/lifetime.rs:15:17 - | -15 | Foo(#[from] Generic<&'a str>), - | ^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/missing-fmt.rs b/xet_error/tests/ui/missing-fmt.rs deleted file mode 100644 index f424ee0f..00000000 --- a/xet_error/tests/ui/missing-fmt.rs +++ /dev/null @@ -1,10 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error("...")] - A(usize), - B(usize), -} - -fn main() {} diff --git a/xet_error/tests/ui/missing-fmt.stderr b/xet_error/tests/ui/missing-fmt.stderr deleted file mode 100644 index c0be3735..00000000 --- a/xet_error/tests/ui/missing-fmt.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: missing #[error("...")] display attribute - --> tests/ui/missing-fmt.rs:7:5 - | -7 | B(usize), - | ^^^^^^^^ diff --git a/xet_error/tests/ui/no-display.rs b/xet_error/tests/ui/no-display.rs deleted file mode 100644 index 38205157..00000000 --- a/xet_error/tests/ui/no-display.rs +++ /dev/null @@ -1,12 +0,0 @@ -use xet_error::Error; - -#[derive(Debug)] -struct NoDisplay; - -#[derive(Error, Debug)] -#[error("thread: {thread}")] -pub struct Error { - thread: NoDisplay, -} - -fn main() {} diff --git a/xet_error/tests/ui/no-display.stderr b/xet_error/tests/ui/no-display.stderr deleted file mode 100644 index 0f47c24b..00000000 --- a/xet_error/tests/ui/no-display.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0599]: the method `as_display` exists for reference `&NoDisplay`, but its trait bounds were not satisfied - --> tests/ui/no-display.rs:7:9 - | -4 | struct NoDisplay; - | ---------------- doesn't satisfy `NoDisplay: std::fmt::Display` -... -7 | #[error("thread: {thread}")] - | ^^^^^^^^^^^^^^^^^^ method cannot be called on `&NoDisplay` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NoDisplay: std::fmt::Display` - which is required by `&NoDisplay: AsDisplay<'_>` -note: the trait `std::fmt::Display` must be implemented - --> $RUST/core/src/fmt/mod.rs - | - | pub trait Display { - | ^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/source-enum-not-error.rs b/xet_error/tests/ui/source-enum-not-error.rs deleted file mode 100644 index 43142ff9..00000000 --- a/xet_error/tests/ui/source-enum-not-error.rs +++ /dev/null @@ -1,12 +0,0 @@ -use xet_error::Error; - -#[derive(Debug)] -pub struct NotError; - -#[derive(Error, Debug)] -#[error("...")] -pub enum ErrorEnum { - Broken { source: NotError }, -} - -fn main() {} diff --git a/xet_error/tests/ui/source-enum-not-error.stderr b/xet_error/tests/ui/source-enum-not-error.stderr deleted file mode 100644 index 4c44742d..00000000 --- a/xet_error/tests/ui/source-enum-not-error.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for reference `&NotError`, but its trait bounds were not satisfied - --> tests/ui/source-enum-not-error.rs:9:14 - | -4 | pub struct NotError; - | ------------------- - | | - | doesn't satisfy `NotError: AsDynError<'_>` - | doesn't satisfy `NotError: std::error::Error` -... -9 | Broken { source: NotError }, - | ^^^^^^ method cannot be called on `&NotError` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NotError: std::error::Error` - which is required by `NotError: AsDynError<'_>` - `&NotError: std::error::Error` - which is required by `&NotError: AsDynError<'_>` -note: the trait `std::error::Error` must be implemented - --> $RUST/core/src/error.rs - | - | pub trait Error: Debug + Display { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/source-enum-unnamed-field-not-error.rs b/xet_error/tests/ui/source-enum-unnamed-field-not-error.rs deleted file mode 100644 index 16b37bc7..00000000 --- a/xet_error/tests/ui/source-enum-unnamed-field-not-error.rs +++ /dev/null @@ -1,12 +0,0 @@ -use xet_error::Error; - -#[derive(Debug)] -pub struct NotError; - -#[derive(Error, Debug)] -#[error("...")] -pub enum ErrorEnum { - Broken(#[source] NotError), -} - -fn main() {} diff --git a/xet_error/tests/ui/source-enum-unnamed-field-not-error.stderr b/xet_error/tests/ui/source-enum-unnamed-field-not-error.stderr deleted file mode 100644 index da6d225f..00000000 --- a/xet_error/tests/ui/source-enum-unnamed-field-not-error.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for reference `&NotError`, but its trait bounds were not satisfied - --> tests/ui/source-enum-unnamed-field-not-error.rs:9:14 - | -4 | pub struct NotError; - | ------------------- - | | - | doesn't satisfy `NotError: AsDynError<'_>` - | doesn't satisfy `NotError: std::error::Error` -... -9 | Broken(#[source] NotError), - | ^^^^^^ method cannot be called on `&NotError` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NotError: std::error::Error` - which is required by `NotError: AsDynError<'_>` - `&NotError: std::error::Error` - which is required by `&NotError: AsDynError<'_>` -note: the trait `std::error::Error` must be implemented - --> $RUST/core/src/error.rs - | - | pub trait Error: Debug + Display { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/source-struct-not-error.rs b/xet_error/tests/ui/source-struct-not-error.rs deleted file mode 100644 index f5378486..00000000 --- a/xet_error/tests/ui/source-struct-not-error.rs +++ /dev/null @@ -1,12 +0,0 @@ -use xet_error::Error; - -#[derive(Debug)] -struct NotError; - -#[derive(Error, Debug)] -#[error("...")] -pub struct ErrorStruct { - source: NotError, -} - -fn main() {} diff --git a/xet_error/tests/ui/source-struct-not-error.stderr b/xet_error/tests/ui/source-struct-not-error.stderr deleted file mode 100644 index b98460fc..00000000 --- a/xet_error/tests/ui/source-struct-not-error.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for struct `NotError`, but its trait bounds were not satisfied - --> tests/ui/source-struct-not-error.rs:9:5 - | -4 | struct NotError; - | --------------- - | | - | method `as_dyn_error` not found for this struct - | doesn't satisfy `NotError: AsDynError<'_>` - | doesn't satisfy `NotError: std::error::Error` -... -9 | source: NotError, - | ^^^^^^ method cannot be called on `NotError` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NotError: std::error::Error` - which is required by `NotError: AsDynError<'_>` -note: the trait `std::error::Error` must be implemented - --> $RUST/core/src/error.rs - | - | pub trait Error: Debug + Display { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/source-struct-unnamed-field-not-error.rs b/xet_error/tests/ui/source-struct-unnamed-field-not-error.rs deleted file mode 100644 index ecf0be1d..00000000 --- a/xet_error/tests/ui/source-struct-unnamed-field-not-error.rs +++ /dev/null @@ -1,10 +0,0 @@ -use xet_error::Error; - -#[derive(Debug)] -struct NotError; - -#[derive(Error, Debug)] -#[error("...")] -pub struct ErrorStruct(#[source] NotError); - -fn main() {} diff --git a/xet_error/tests/ui/source-struct-unnamed-field-not-error.stderr b/xet_error/tests/ui/source-struct-unnamed-field-not-error.stderr deleted file mode 100644 index a23f2682..00000000 --- a/xet_error/tests/ui/source-struct-unnamed-field-not-error.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for struct `NotError`, but its trait bounds were not satisfied - --> tests/ui/source-struct-unnamed-field-not-error.rs:8:26 - | -4 | struct NotError; - | --------------- - | | - | method `as_dyn_error` not found for this struct - | doesn't satisfy `NotError: AsDynError<'_>` - | doesn't satisfy `NotError: std::error::Error` -... -8 | pub struct ErrorStruct(#[source] NotError); - | ^^^^^^ method cannot be called on `NotError` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NotError: std::error::Error` - which is required by `NotError: AsDynError<'_>` -note: the trait `std::error::Error` must be implemented - --> $RUST/core/src/error.rs - | - | pub trait Error: Debug + Display { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/transparent-display.rs b/xet_error/tests/ui/transparent-display.rs deleted file mode 100644 index 1e3ae263..00000000 --- a/xet_error/tests/ui/transparent-display.rs +++ /dev/null @@ -1,8 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -#[error("...")] -pub struct Error(anyhow::Error); - -fn main() {} diff --git a/xet_error/tests/ui/transparent-display.stderr b/xet_error/tests/ui/transparent-display.stderr deleted file mode 100644 index 54d958b2..00000000 --- a/xet_error/tests/ui/transparent-display.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: cannot have both #[error(transparent)] and a display attribute - --> tests/ui/transparent-display.rs:5:1 - | -5 | #[error("...")] - | ^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/transparent-enum-many.rs b/xet_error/tests/ui/transparent-enum-many.rs deleted file mode 100644 index 7f621ef2..00000000 --- a/xet_error/tests/ui/transparent-enum-many.rs +++ /dev/null @@ -1,9 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error(transparent)] - Other(anyhow::Error, String), -} - -fn main() {} diff --git a/xet_error/tests/ui/transparent-enum-many.stderr b/xet_error/tests/ui/transparent-enum-many.stderr deleted file mode 100644 index a9adfa5a..00000000 --- a/xet_error/tests/ui/transparent-enum-many.stderr +++ /dev/null @@ -1,6 +0,0 @@ -error: #[error(transparent)] requires exactly one field - --> tests/ui/transparent-enum-many.rs:5:5 - | -5 | / #[error(transparent)] -6 | | Other(anyhow::Error, String), - | |________________________________^ diff --git a/xet_error/tests/ui/transparent-enum-not-error.rs b/xet_error/tests/ui/transparent-enum-not-error.rs deleted file mode 100644 index c35456bf..00000000 --- a/xet_error/tests/ui/transparent-enum-not-error.rs +++ /dev/null @@ -1,9 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error(transparent)] - Other { message: String }, -} - -fn main() {} diff --git a/xet_error/tests/ui/transparent-enum-not-error.stderr b/xet_error/tests/ui/transparent-enum-not-error.stderr deleted file mode 100644 index 9be51434..00000000 --- a/xet_error/tests/ui/transparent-enum-not-error.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for reference `&String`, but its trait bounds were not satisfied - --> tests/ui/transparent-enum-not-error.rs:5:13 - | -5 | #[error(transparent)] - | ^^^^^^^^^^^ method cannot be called on `&String` due to unsatisfied trait bounds - | - ::: $RUST/alloc/src/string.rs - | - | pub struct String { - | ----------------- - | | - | doesn't satisfy `String: AsDynError<'_>` - | doesn't satisfy `String: std::error::Error` - | - = note: the following trait bounds were not satisfied: - `String: std::error::Error` - which is required by `String: AsDynError<'_>` - `&String: std::error::Error` - which is required by `&String: AsDynError<'_>` - `str: Sized` - which is required by `str: AsDynError<'_>` - `str: std::error::Error` - which is required by `str: AsDynError<'_>` diff --git a/xet_error/tests/ui/transparent-enum-source.rs b/xet_error/tests/ui/transparent-enum-source.rs deleted file mode 100644 index 8ab61abe..00000000 --- a/xet_error/tests/ui/transparent-enum-source.rs +++ /dev/null @@ -1,9 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error(transparent)] - Other(#[source] anyhow::Error), -} - -fn main() {} diff --git a/xet_error/tests/ui/transparent-enum-source.stderr b/xet_error/tests/ui/transparent-enum-source.stderr deleted file mode 100644 index ccb90677..00000000 --- a/xet_error/tests/ui/transparent-enum-source.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: transparent variant can't contain #[source] - --> tests/ui/transparent-enum-source.rs:6:11 - | -6 | Other(#[source] anyhow::Error), - | ^^^^^^^^^ diff --git a/xet_error/tests/ui/transparent-enum-unnamed-field-not-error.rs b/xet_error/tests/ui/transparent-enum-unnamed-field-not-error.rs deleted file mode 100644 index c396dbd2..00000000 --- a/xet_error/tests/ui/transparent-enum-unnamed-field-not-error.rs +++ /dev/null @@ -1,9 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error(transparent)] - Other(String), -} - -fn main() {} diff --git a/xet_error/tests/ui/transparent-enum-unnamed-field-not-error.stderr b/xet_error/tests/ui/transparent-enum-unnamed-field-not-error.stderr deleted file mode 100644 index 3d23c3a0..00000000 --- a/xet_error/tests/ui/transparent-enum-unnamed-field-not-error.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for reference `&String`, but its trait bounds were not satisfied - --> tests/ui/transparent-enum-unnamed-field-not-error.rs:5:13 - | -5 | #[error(transparent)] - | ^^^^^^^^^^^ method cannot be called on `&String` due to unsatisfied trait bounds - | - ::: $RUST/alloc/src/string.rs - | - | pub struct String { - | ----------------- - | | - | doesn't satisfy `String: AsDynError<'_>` - | doesn't satisfy `String: std::error::Error` - | - = note: the following trait bounds were not satisfied: - `String: std::error::Error` - which is required by `String: AsDynError<'_>` - `&String: std::error::Error` - which is required by `&String: AsDynError<'_>` - `str: Sized` - which is required by `str: AsDynError<'_>` - `str: std::error::Error` - which is required by `str: AsDynError<'_>` diff --git a/xet_error/tests/ui/transparent-struct-many.rs b/xet_error/tests/ui/transparent-struct-many.rs deleted file mode 100644 index eefbb80f..00000000 --- a/xet_error/tests/ui/transparent-struct-many.rs +++ /dev/null @@ -1,10 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -pub struct Error { - inner: anyhow::Error, - what: String, -} - -fn main() {} diff --git a/xet_error/tests/ui/transparent-struct-many.stderr b/xet_error/tests/ui/transparent-struct-many.stderr deleted file mode 100644 index c0e3806e..00000000 --- a/xet_error/tests/ui/transparent-struct-many.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: #[error(transparent)] requires exactly one field - --> tests/ui/transparent-struct-many.rs:4:1 - | -4 | #[error(transparent)] - | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/transparent-struct-not-error.rs b/xet_error/tests/ui/transparent-struct-not-error.rs deleted file mode 100644 index c0fcb6e7..00000000 --- a/xet_error/tests/ui/transparent-struct-not-error.rs +++ /dev/null @@ -1,9 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -pub struct Error { - message: String, -} - -fn main() {} diff --git a/xet_error/tests/ui/transparent-struct-not-error.stderr b/xet_error/tests/ui/transparent-struct-not-error.stderr deleted file mode 100644 index d67a6944..00000000 --- a/xet_error/tests/ui/transparent-struct-not-error.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for struct `String`, but its trait bounds were not satisfied - --> tests/ui/transparent-struct-not-error.rs:4:9 - | -4 | #[error(transparent)] - | ^^^^^^^^^^^ method cannot be called on `String` due to unsatisfied trait bounds - | - ::: $RUST/alloc/src/string.rs - | - | pub struct String { - | ----------------- - | | - | doesn't satisfy `String: AsDynError<'_>` - | doesn't satisfy `String: std::error::Error` - | - = note: the following trait bounds were not satisfied: - `String: std::error::Error` - which is required by `String: AsDynError<'_>` - `str: Sized` - which is required by `str: AsDynError<'_>` - `str: std::error::Error` - which is required by `str: AsDynError<'_>` diff --git a/xet_error/tests/ui/transparent-struct-source.rs b/xet_error/tests/ui/transparent-struct-source.rs deleted file mode 100644 index b3b9234c..00000000 --- a/xet_error/tests/ui/transparent-struct-source.rs +++ /dev/null @@ -1,7 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -pub struct Error(#[source] anyhow::Error); - -fn main() {} diff --git a/xet_error/tests/ui/transparent-struct-source.stderr b/xet_error/tests/ui/transparent-struct-source.stderr deleted file mode 100644 index 3012ca31..00000000 --- a/xet_error/tests/ui/transparent-struct-source.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: transparent error struct can't contain #[source] - --> tests/ui/transparent-struct-source.rs:5:18 - | -5 | pub struct Error(#[source] anyhow::Error); - | ^^^^^^^^^ diff --git a/xet_error/tests/ui/transparent-struct-unnamed-field-not-error.rs b/xet_error/tests/ui/transparent-struct-unnamed-field-not-error.rs deleted file mode 100644 index 175d2111..00000000 --- a/xet_error/tests/ui/transparent-struct-unnamed-field-not-error.rs +++ /dev/null @@ -1,7 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[error(transparent)] -pub struct Error(String); - -fn main() {} diff --git a/xet_error/tests/ui/transparent-struct-unnamed-field-not-error.stderr b/xet_error/tests/ui/transparent-struct-unnamed-field-not-error.stderr deleted file mode 100644 index f715a151..00000000 --- a/xet_error/tests/ui/transparent-struct-unnamed-field-not-error.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0599]: the method `as_dyn_error` exists for struct `String`, but its trait bounds were not satisfied - --> tests/ui/transparent-struct-unnamed-field-not-error.rs:4:9 - | -4 | #[error(transparent)] - | ^^^^^^^^^^^ method cannot be called on `String` due to unsatisfied trait bounds - | - ::: $RUST/alloc/src/string.rs - | - | pub struct String { - | ----------------- - | | - | doesn't satisfy `String: AsDynError<'_>` - | doesn't satisfy `String: std::error::Error` - | - = note: the following trait bounds were not satisfied: - `String: std::error::Error` - which is required by `String: AsDynError<'_>` - `str: Sized` - which is required by `str: AsDynError<'_>` - `str: std::error::Error` - which is required by `str: AsDynError<'_>` diff --git a/xet_error/tests/ui/unexpected-field-fmt.rs b/xet_error/tests/ui/unexpected-field-fmt.rs deleted file mode 100644 index d260e4aa..00000000 --- a/xet_error/tests/ui/unexpected-field-fmt.rs +++ /dev/null @@ -1,11 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -pub enum Error { - What { - #[error("...")] - io: std::io::Error, - }, -} - -fn main() {} diff --git a/xet_error/tests/ui/unexpected-field-fmt.stderr b/xet_error/tests/ui/unexpected-field-fmt.stderr deleted file mode 100644 index bf3c24df..00000000 --- a/xet_error/tests/ui/unexpected-field-fmt.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: not expected here; the #[error(...)] attribute belongs on top of a struct or an enum variant - --> tests/ui/unexpected-field-fmt.rs:6:9 - | -6 | #[error("...")] - | ^^^^^^^^^^^^^^^ diff --git a/xet_error/tests/ui/unexpected-struct-source.rs b/xet_error/tests/ui/unexpected-struct-source.rs deleted file mode 100644 index 5aba7da4..00000000 --- a/xet_error/tests/ui/unexpected-struct-source.rs +++ /dev/null @@ -1,7 +0,0 @@ -use xet_error::Error; - -#[derive(Error, Debug)] -#[source] -pub struct Error; - -fn main() {} diff --git a/xet_error/tests/ui/unexpected-struct-source.stderr b/xet_error/tests/ui/unexpected-struct-source.stderr deleted file mode 100644 index 6f15841d..00000000 --- a/xet_error/tests/ui/unexpected-struct-source.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: not expected here; the #[source] attribute belongs on a specific field - --> tests/ui/unexpected-struct-source.rs:4:1 - | -4 | #[source] - | ^^^^^^^^^ diff --git a/xet_error/tests/ui/union.rs b/xet_error/tests/ui/union.rs deleted file mode 100644 index bebe4c88..00000000 --- a/xet_error/tests/ui/union.rs +++ /dev/null @@ -1,9 +0,0 @@ -use xet_error::Error; - -#[derive(Error)] -pub union U { - msg: &'static str, - num: usize, -} - -fn main() {} diff --git a/xet_error/tests/ui/union.stderr b/xet_error/tests/ui/union.stderr deleted file mode 100644 index 3ec4d71c..00000000 --- a/xet_error/tests/ui/union.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: union as errors are not supported - --> tests/ui/union.rs:4:1 - | -4 | / pub union U { -5 | | msg: &'static str, -6 | | num: usize, -7 | | } - | |_^