diff --git a/Cargo.lock b/Cargo.lock index 2bf9fa1f0610..11264e93f4d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -316,8 +316,8 @@ version = "0.2.0" dependencies = [ "bits 0.2.0", "comedy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "guid_win 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -332,8 +332,8 @@ dependencies = [ "bits_client 0.2.0", "comedy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "moz_task 0.1.0", @@ -537,8 +537,8 @@ name = "comedy" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -645,8 +645,8 @@ dependencies = [ "cranelift-codegen-meta 0.46.1 (git+https://github.com/CraneStation/Cranelift?rev=da179e4fd83d49b7ad6c9f286b1ea04d4f64907e)", "cranelift-codegen-shared 0.46.1 (git+https://github.com/CraneStation/Cranelift?rev=da179e4fd83d49b7ad6c9f286b1ea04d4f64907e)", "cranelift-entity 0.46.1 (git+https://github.com/CraneStation/Cranelift?rev=da179e4fd83d49b7ad6c9f286b1ea04d4f64907e)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -695,8 +695,8 @@ dependencies = [ "cranelift-codegen 0.46.1 (git+https://github.com/CraneStation/Cranelift?rev=da179e4fd83d49b7ad6c9f286b1ea04d4f64907e)", "cranelift-entity 0.46.1 (git+https://github.com/CraneStation/Cranelift?rev=da179e4fd83d49b7ad6c9f286b1ea04d4f64907e)", "cranelift-frontend 0.46.1 (git+https://github.com/CraneStation/Cranelift?rev=da179e4fd83d49b7ad6c9f286b1ea04d4f64907e)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1089,22 +1089,22 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "failure_derive" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1737,7 +1737,7 @@ version = "0.1.0" dependencies = [ "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-rkv 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1881,7 +1881,7 @@ dependencies = [ "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-entity 0.41.0 (git+https://github.com/PLSysSec/lucet_sandbox_compiler)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "object 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1911,7 +1911,7 @@ dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1930,7 +1930,7 @@ version = "0.1.1" source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler#5c22392b5b1aaa60e915c75e92b57391e1e61e6d" dependencies = [ "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)", "lucet-module 0.1.1 (git+https://github.com/PLSysSec/lucet_sandbox_compiler)", "lucet-runtime 0.1.1 (git+https://github.com/PLSysSec/lucet_sandbox_compiler)", @@ -1978,12 +1978,12 @@ dependencies = [ [[package]] name = "malloc_size_of_derive" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2996,7 +2996,7 @@ name = "redox_users" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3078,7 +3078,7 @@ dependencies = [ "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-rkv 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3097,7 +3097,7 @@ dependencies = [ "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "id-arena 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-rkv 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3114,7 +3114,7 @@ name = "rlbox_lucet_sandbox" version = "0.1.0" source = "git+https://github.com/PLSysSec/rlbox_lucet_sandbox/?rev=997c648eb0eaeaaa7a00a9eee20431f750b4e190#997c648eb0eaeaaa7a00a9eee20431f750b4e190" dependencies = [ - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.24 (registry+https://github.com/rust-lang/crates.io-index)", "lucet-module 0.1.1 (git+https://github.com/PLSysSec/lucet_sandbox_compiler)", "lucet-runtime 0.1.1 (git+https://github.com/PLSysSec/lucet_sandbox_compiler)", @@ -3170,7 +3170,7 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "murmurhash3 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3551,7 +3551,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", - "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "malloc_size_of_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "nsstring 0.1.0", @@ -3607,7 +3607,7 @@ dependencies = [ "euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", - "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "malloc_size_of_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.21.0", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "servo_arc 0.1.1", @@ -3661,17 +3661,6 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "synstructure" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "synstructure" version = "0.12.1" @@ -3688,8 +3677,8 @@ name = "target-lexicon" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4182,7 +4171,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "malloc_size_of_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "plane-split 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4211,7 +4200,7 @@ dependencies = [ "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", - "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "malloc_size_of_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "peek-poke 0.2.0", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4451,7 +4440,7 @@ version = "0.1.0" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "cstr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-rkv 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4585,8 +4574,8 @@ dependencies = [ "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" "checksum euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4786521fec183792e755bf32cd0188e4e7628c6d0fcfd51426435b9081a106" -"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" -"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" +"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum filetime_win 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c37abd4a58e0cb794bcae4a7dc4f02fff376949d8d1066d4c729e97bfb38ec" "checksum flate2 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "2adaffba6388640136149e18ed080b77a78611c1e1d6de75aedcdf78df5d4682" @@ -4654,7 +4643,7 @@ dependencies = [ "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" "checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -"checksum malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "35adee9ed962cf7d07d62cb58bc45029f3227f5b5b86246caa8632f06c187bc3" +"checksum malloc_size_of_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e37c5d4cd9473c5f4c9c111f033f15d4df9bd378fdf615944e360a4f55a05f0b" "checksum mapped_hyph 0.3.0 (git+https://github.com/jfkthame/mapped_hyph.git?tag=v0.3.0)" = "" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" @@ -4800,7 +4789,6 @@ dependencies = [ "checksum svg_fmt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c666f0fed8e1e20e057af770af9077d72f3d5a33157b8537c1475dd8ffd6d32b" "checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2" "checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203" "checksum target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7975cb2c6f37d77b190bc5004a2bb015971464756fde9514651a525ada2a741a" "checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" diff --git a/third_party/rust/failure/.cargo-checksum.json b/third_party/rust/failure/.cargo-checksum.json index d5a4f8275231..c342ccce002d 100644 --- a/third_party/rust/failure/.cargo-checksum.json +++ b/third_party/rust/failure/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"CODE_OF_CONDUCT.md":"9a7bc3fdffac1288f51485e70a910a4e9de1260a64fbe894f60ad73b3386dda9","Cargo.toml":"2e6b46b3ac49b9890868cd4ea2118efbaf4ca80e136a1b5b417ce95ea91fb293","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","Makefile":"61a649ecb55115ba0f357215eb322fa6676ce163ca20bff59d7c5e275aa37035","README.md":"d4dba8ed8b388c1e24bcaaa0f0e75a0830885d6db9bedc9630591a180c744f73","RELEASES.md":"42304b5bc4cfd3a5f93d17bfe34d24f6b8bb918e89c57425adbb503f500b558c","book/src/SUMMARY.md":"32f211f5aeb51a05b3c6a41a128bdb9e410ae84008a93e6b13442e45cd1c91d4","book/src/bail-and-ensure.md":"08fb463570143ec6568189468f1f54a7210b0a1ad66a57f7f7c36619831b4d72","book/src/custom-fail.md":"d4b1501201f9c54637bc40a2413e333f6f7d4fcfc8e3de74bf40d48eca0d4e41","book/src/derive-fail.md":"69916338286f970ae6709fb309bd4d80c321fea10b927f14efe402e3c0a5fdc9","book/src/error-errorkind.md":"40663de622bfb89a3dedcf6e093ec61eb1ab704d512d725e33f66aec38911757","book/src/error-msg.md":"2ab003bde8e88e0e3b9d1559d95e84b0ca7068522e324235bc4b2fdb88996d51","book/src/error.md":"c978778e7986e5febfb37e635525053ef73c534e4b6e9fc25deb576fdbdc111d","book/src/fail.md":"076ed560e9ad293bf99611f9407d4dc17310c42cf1652dd1f3f4be85fb5f17b8","book/src/guidance.md":"614cb85ae32c2b59119cd1db7eea008e50b051563c15ba1305f312fa2eeb3ac0","book/src/howto.md":"e18744011f5cc5779f5bb981ebd10f0af440c98398b2eb5af0ee27b9662ee410","book/src/intro.md":"eeb23e1ac3ccf75c4779603662910e96df647a02c73665a206dcc34c56d77eaf","book/src/string-custom-error.md":"f1d94e211f1d2dfb2d9d9a0d7eb745b8ea7f08f26243283fddb440cb099893ff","book/src/use-error.md":"a7f91e06eb676318da04a56e4b31c73dd7db888d43c215e1534a5bc415e98258","build-docs.sh":"27b611219773192b9f972b2054522481fd5c2c9419c155535f58d05bfc31fffe","examples/bail_ensure.rs":"fffc71e41f9fbbc2a7db453ef20779716007ed6bbb01e45fbcefb1e073745ecc","examples/error_as_cause.rs":"e0a6472455db5e484febc196667bc46c939d9f890bfe550ab7435d52b1ac6b2b","examples/simple.rs":"7a5fc0673b6bb5bd3716416a6545f7ff471d182292a2c8424cf18bc4a72f6936","examples/string_custom_error_pattern.rs":"23b5bf79a7219aa8a80484c0df70cd43d882b7dccd91de9ceb1aac05b0b1b4f2","src/as_fail.rs":"8a381a9624b3d28b45f92f8b527d7496e7a722c8aa0d632f0b23bbe0af98a76e","src/backtrace/internal.rs":"3fc4943061d4396c855571f134cd922f428cbe930689c8191376867b729d7b08","src/backtrace/mod.rs":"df3a348300775182c2780c542f119c989a6004cff841d817bdf7b93eef9a0dd3","src/box_std.rs":"224f3e3f48ad217ba34a54a62f608f9cba3ce95b176558684706c2f7fe72ce72","src/compat.rs":"97ed4fa49ac80c915b384b29a1bf678430cf1ea8ea61aa794a6014a1c3217762","src/context.rs":"d91ed85add638af7c9d481cb82ee6633c3678978951a5530c166fc156efac2e4","src/error/error_impl.rs":"063b9d9127f455b7555184af2576bc59e650add13c820be4960a3a5e5da0a9e4","src/error/error_impl_small.rs":"e6cbbd4d12e8eec1bd0f15713d33a0e525599268c9316dd40240eb7cd9e19a9d","src/error/mod.rs":"103621b313bd729c94054c5d88edd59d8c07311b650873e81b5021362647ae7a","src/error_message.rs":"2a45a3bd142e6547fc5da27c182fb690e2990de11db2a9b8ce63e50d9c589997","src/lib.rs":"0969303376ab328e16d7c64d690fc71a1e4eee00b413e79009cd590a2c4abbc0","src/macros.rs":"47cc9c73291e6edb3365d72b772d781215d123240f89a5fff914d23927781efa","src/result_ext.rs":"8088c3cb1481e81891014c99cc0f1b75f25a2f212b52ae856583e4c1f1901d09","src/small_error.rs":"652bf6ff2016d8e31b6ee709ad3efaff9f4e96d5aec8120ea3986a0bb8f57c54","src/sync_failure.rs":"a92a2e8b416196322718a4e7e1262f5b1b0a6be47b849d9a7e1050c1d33490db","travis.sh":"836024f7a56fdbe24a99ab9ce9350713831f4375a60f02593aad6637b766a330"},"package":"6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"} \ No newline at end of file +{"files":{"CODE_OF_CONDUCT.md":"9a7bc3fdffac1288f51485e70a910a4e9de1260a64fbe894f60ad73b3386dda9","Cargo.lock":"3206fd88e783a8cc7da73232c080b0b7d7a3c8332d5b2976f0c0c4afa873befb","Cargo.lock.ci":"3c1120d0dc287aa2966eb168521ec84016b09f7f335c6d320f1bee1d367a618e","Cargo.toml":"55a4adc0822ccc0826689542349068af9b83eec4523802b410c1c607daa0e029","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","Makefile":"61a649ecb55115ba0f357215eb322fa6676ce163ca20bff59d7c5e275aa37035","README.md":"bce9d1eae485cda6c5f9ed94fef92c30d60de117a1e3a23563b9308be1bf5d55","RELEASES.md":"3314fd66e694c74ee389796c0307c1ac94e93c62bf9cb7cc3b029d5396244feb","book/src/SUMMARY.md":"32f211f5aeb51a05b3c6a41a128bdb9e410ae84008a93e6b13442e45cd1c91d4","book/src/bail-and-ensure.md":"08fb463570143ec6568189468f1f54a7210b0a1ad66a57f7f7c36619831b4d72","book/src/custom-fail.md":"d4b1501201f9c54637bc40a2413e333f6f7d4fcfc8e3de74bf40d48eca0d4e41","book/src/derive-fail.md":"69916338286f970ae6709fb309bd4d80c321fea10b927f14efe402e3c0a5fdc9","book/src/error-errorkind.md":"5aae25fce531e9740aa70343bcda3de0f2718949922c2e4a91ceb09062c45892","book/src/error-msg.md":"32e17b280379d2bc83e7cb7a6c664a2e9225802f31638beda508056da53ba6af","book/src/error.md":"c978778e7986e5febfb37e635525053ef73c534e4b6e9fc25deb576fdbdc111d","book/src/fail.md":"2865d1fef1d94de5fc086306ba5a734b26dd1d60effa718906919557bf4d779c","book/src/guidance.md":"614cb85ae32c2b59119cd1db7eea008e50b051563c15ba1305f312fa2eeb3ac0","book/src/howto.md":"e18744011f5cc5779f5bb981ebd10f0af440c98398b2eb5af0ee27b9662ee410","book/src/intro.md":"2a6eed661e059016d067d2891e9e27b673425dbc87f077849a302619a182d112","book/src/string-custom-error.md":"55e3ef77748c1dcdfe984fe3c510e7001267ac2b3ece230b90844655dd2da957","book/src/use-error.md":"a7f91e06eb676318da04a56e4b31c73dd7db888d43c215e1534a5bc415e98258","build-docs.sh":"27b611219773192b9f972b2054522481fd5c2c9419c155535f58d05bfc31fffe","examples/bail_ensure.rs":"fffc71e41f9fbbc2a7db453ef20779716007ed6bbb01e45fbcefb1e073745ecc","examples/error_as_cause.rs":"e0a6472455db5e484febc196667bc46c939d9f890bfe550ab7435d52b1ac6b2b","examples/simple.rs":"39b2263d4b92f22c9e1ceefb78b67e1299fc46eba5621d1c47afd937fd7d5318","examples/string_custom_error_pattern.rs":"23b5bf79a7219aa8a80484c0df70cd43d882b7dccd91de9ceb1aac05b0b1b4f2","src/as_fail.rs":"6d4f549f8c9d8abcfbb0a70fe5c0853c82f1c127f87f94fc14c06e2fdaf09db1","src/backtrace/internal.rs":"ff809782e9f9f17928595e00d1bc2f3ff8ccf9b48482126049a318d34957ceb6","src/backtrace/mod.rs":"33c7988b61db9995260fd4470821ea4bce5316052d4c41b4326f99dcc9858b0e","src/box_std.rs":"0455cd53c4a7e5150574ea7c30d5d2692e7e0ff98a83a2fd9656f62600077112","src/compat.rs":"8825b752a92cf1f902424be83b139fa76c85bd016e27565e2ec2fe5dfb4759aa","src/context.rs":"0ee2a96a5c84761bdba37c65babdfd8c556747778a8cac649cdc18747f7d15ba","src/error/error_impl.rs":"74b3337d9dc16de0bdd1cd355841f7035972cded053d7a213590c11c3463d595","src/error/error_impl_small.rs":"e6cbbd4d12e8eec1bd0f15713d33a0e525599268c9316dd40240eb7cd9e19a9d","src/error/mod.rs":"a4f7c1db02d3d16034993b78f5e93d36f70a23ef9218375f952034effd5d58bc","src/error_message.rs":"9c45597e8237c601c4c49aa07adeab41126d38f0886789acf3f8874bb149c6be","src/lib.rs":"11ff9348d697afbf44f73eb82d1cd22509ce4064bd41929fd5fbc677e4d04a42","src/macros.rs":"351758673f77384f82ff3373d96f378706b07ff7ef9c98788a21ae8b1cc70359","src/result_ext.rs":"8088c3cb1481e81891014c99cc0f1b75f25a2f212b52ae856583e4c1f1901d09","src/small_error.rs":"652bf6ff2016d8e31b6ee709ad3efaff9f4e96d5aec8120ea3986a0bb8f57c54","src/sync_failure.rs":"a92a2e8b416196322718a4e7e1262f5b1b0a6be47b849d9a7e1050c1d33490db","tests/basic_fail.rs":"d24b8a90a5a122287eedc91c7322a162f2e0c124494a1084c8dc13c711db278b","tests/fail_compat.rs":"ffc1db79138168a618889d8eb1917d3963e6367a3fc5b2541d3120c480a73310","tests/macro_trailing_comma.rs":"e98caf539fa5e34bb11cd0f7c2a315190cdb8b2aeadeb12c706c19f1f5e8cf3e","travis.sh":"836024f7a56fdbe24a99ab9ce9350713831f4375a60f02593aad6637b766a330"},"package":"f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"} \ No newline at end of file diff --git a/third_party/rust/failure/Cargo.lock b/third_party/rust/failure/Cargo.lock new file mode 100644 index 000000000000..ed9035492a27 --- /dev/null +++ b/third_party/rust/failure/Cargo.lock @@ -0,0 +1,116 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "backtrace" +version = "0.3.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cc" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "failure" +version = "0.1.6" +dependencies = [ + "backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synstructure" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)" = "690a62be8920ccf773ee00ef0968649b0e724cda8bd5b12286302b4ae955fdf5" +"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" +"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" +"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" +"checksum proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90cf5f418035b98e655e9cdb225047638296b862b42411c4e45bb88d700f7fc0" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" +"checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" diff --git a/third_party/rust/failure/Cargo.lock.ci b/third_party/rust/failure/Cargo.lock.ci new file mode 100644 index 000000000000..1508fa5c4733 --- /dev/null +++ b/third_party/rust/failure/Cargo.lock.ci @@ -0,0 +1,136 @@ +[[package]] +name = "backtrace" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cc" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "failure" +version = "0.1.6" +dependencies = [ + "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6", +] + +[[package]] +name = "failure_derive" +version = "0.1.6" +dependencies = [ + "failure 0.1.6", + "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.43" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "0.4.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "0.15.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synstructure" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a" +"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0" +"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" +"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" +"checksum rustc-demangle 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "01b90379b8664dd83460d59bdc5dd1fd3172b8913788db483ed1325171eab2f7" +"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" +"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/third_party/rust/failure/Cargo.toml b/third_party/rust/failure/Cargo.toml index e478d731b7ea..4334f50d52ae 100644 --- a/third_party/rust/failure/Cargo.toml +++ b/third_party/rust/failure/Cargo.toml @@ -3,7 +3,7 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g. crates.io) dependencies +# to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're @@ -12,10 +12,10 @@ [package] name = "failure" -version = "0.1.3" +version = "0.1.6" authors = ["Without Boats "] description = "Experimental error handling abstraction." -homepage = "https://boats.gitlab.io/failure" +homepage = "https://rust-lang-nursery.github.io/failure/" documentation = "https://docs.rs/failure" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang-nursery/failure" @@ -24,7 +24,7 @@ version = "0.3.3" optional = true [dependencies.failure_derive] -version = "0.1.3" +version = "0.1.6" optional = true [features] diff --git a/third_party/rust/failure/README.md b/third_party/rust/failure/README.md index 2f228321ba69..56df9a292392 100644 --- a/third_party/rust/failure/README.md +++ b/third_party/rust/failure/README.md @@ -100,8 +100,8 @@ pub fn read_toolchains(path: PathBuf) -> Result ## Requirements Both failure and failure_derive are intended to compile on all stable versions -of Rust newer than 1.18.0, as well as the latest beta and the latest nightly. -If either crate fails to compile on any version newer than 1.18.0, please open +of Rust newer than 1.31.0, as well as the latest beta and the latest nightly. +If either crate fails to compile on any version newer than 1.31.0, please open an issue. failure is **no_std** compatible, though some aspects of it (primarily the diff --git a/third_party/rust/failure/RELEASES.md b/third_party/rust/failure/RELEASES.md index 2de325eb99b0..499df4bcb0dc 100644 --- a/third_party/rust/failure/RELEASES.md +++ b/third_party/rust/failure/RELEASES.md @@ -1,3 +1,21 @@ +# Version 0.1.6 + +- Update `syn`, `quote`, and `proc_macro2` dependencies to 1.0. +- Bump MSRV to 1.31.0. + +# Version 0.1.5 + +- Resolve a regression with error conversions (#290) +- Added `name()` to `Fail` and `Error` + +# Version 0.1.4 + +- Improved error reporting of the derive feature +- Resolved a potential internal ambiguity when using the backtrace feature + that prevented backtrace from improving an upstream API. +- Changed the bounds on std error compat conversions through the From trait + to take Sync and Send into account. + # Version 0.1.3 - Added `Context::map` diff --git a/third_party/rust/failure/book/src/error-errorkind.md b/third_party/rust/failure/book/src/error-errorkind.md index c5968e813c12..4f1cc4c316be 100644 --- a/third_party/rust/failure/book/src/error-errorkind.md +++ b/third_party/rust/failure/book/src/error-errorkind.md @@ -39,6 +39,10 @@ yourself: ```rust impl Fail for MyError { + fn name(&self) -> Option<&str> { + self.inner.name() + } + fn cause(&self) -> Option<&Fail> { self.inner.cause() } @@ -140,4 +144,4 @@ case, you should not use this pattern. [use-error]: ./use-error.html [custom-fail]: ./custom-fail.html -[context-api]: https://boats.gitlab.io/failure/doc/failure/struct.Context.html +[context-api]: https://docs.rs/failure/latest/failure/struct.Context.html diff --git a/third_party/rust/failure/book/src/error-msg.md b/third_party/rust/failure/book/src/error-msg.md index e754aa93b4be..61bde143b109 100644 --- a/third_party/rust/failure/book/src/error-msg.md +++ b/third_party/rust/failure/book/src/error-msg.md @@ -55,5 +55,5 @@ to the users. [custom-fail]: ./custom-fail.html [use-error]: ./use-error.html -[err-msg-api]: https://boats.gitlab.io/failure/doc/failure/fn.err_msg.html -[format-err-api]: https://boats.gitlab.io/failure/doc/failure/macro.format_err.html +[err-msg-api]: https://docs.rs/failure/latest/failure/fn.err_msg.html +[format-err-api]: https://docs.rs/failure/latest/failure/macro.format_err.html diff --git a/third_party/rust/failure/book/src/fail.md b/third_party/rust/failure/book/src/fail.md index 4d337c3270df..720b52e6d898 100644 --- a/third_party/rust/failure/book/src/fail.md +++ b/third_party/rust/failure/book/src/fail.md @@ -147,6 +147,6 @@ The biggest hole in our backwards compatibility story is that you cannot implement `std::error::Error` and also override the backtrace and cause methods on `Fail`. We intend to enable this with specialization when it becomes stable. -[derive-docs]: https://boats.gitlab.io/failure/derive-fail.html +[derive-docs]: ./derive-fail.html [stderror]: https://doc.rust-lang.org/std/error/trait.Error.html [backtrace-crate]: http://alexcrichton.com/backtrace-rs diff --git a/third_party/rust/failure/book/src/intro.md b/third_party/rust/failure/book/src/intro.md index d62093b11058..318477a72dc8 100644 --- a/third_party/rust/failure/book/src/intro.md +++ b/third_party/rust/failure/book/src/intro.md @@ -6,7 +6,7 @@ creating and managing errors in Rust. Additional documentation is found here: * [API documentation][api] * [failure source code][repo] -[api]: https://boats.gitlab.io/failure/doc/failure +[api]: https://docs.rs/failure [repo]: https://github.com/rust-lang-nursery/failure ```rust diff --git a/third_party/rust/failure/book/src/string-custom-error.md b/third_party/rust/failure/book/src/string-custom-error.md index a56783646b85..5ea7b8fc8212 100644 --- a/third_party/rust/failure/book/src/string-custom-error.md +++ b/third_party/rust/failure/book/src/string-custom-error.md @@ -20,6 +20,10 @@ pub struct MyError { } impl Fail for MyError { + fn name(&self) -> Option<&str> { + self.inner.name() + } + fn cause(&self) -> Option<&Fail> { self.inner.cause() } @@ -105,6 +109,10 @@ pub struct MyError { } impl Fail for MyError { + fn name(&self) -> Option<&str> { + self.inner.name() + } + fn cause(&self) -> Option<&Fail> { self.inner.cause() } diff --git a/third_party/rust/failure/examples/simple.rs b/third_party/rust/failure/examples/simple.rs index 35d25e16a5b6..fc39601dce0b 100644 --- a/third_party/rust/failure/examples/simple.rs +++ b/third_party/rust/failure/examples/simple.rs @@ -16,7 +16,7 @@ fn bad_function() -> Result<(), WrappingError> { } fn main() { - for cause in Fail::iter_causes(&bad_function().unwrap_err()) { - println!("{}", cause); + for cause in Fail::iter_chain(&bad_function().unwrap_err()) { + println!("{}: {}", cause.name().unwrap_or("Error"), cause); } } diff --git a/third_party/rust/failure/src/as_fail.rs b/third_party/rust/failure/src/as_fail.rs index dd53a46c6b66..6e4172bd8c9b 100644 --- a/third_party/rust/failure/src/as_fail.rs +++ b/third_party/rust/failure/src/as_fail.rs @@ -8,20 +8,20 @@ use Fail; /// custom cause. pub trait AsFail { /// Converts a reference to `Self` into a dynamic trait object of `Fail`. - fn as_fail(&self) -> &Fail; + fn as_fail(&self) -> &dyn Fail; } impl AsFail for T where T: Fail, { - fn as_fail(&self) -> &Fail { + fn as_fail(&self) -> &dyn Fail { self } } -impl AsFail for Fail { - fn as_fail(&self) -> &Fail { +impl AsFail for dyn Fail { + fn as_fail(&self) -> &dyn Fail { self } } @@ -30,7 +30,7 @@ with_std! { use error::Error; impl AsFail for Error { - fn as_fail(&self) -> &Fail { + fn as_fail(&self) -> &dyn Fail { self.as_fail() } } diff --git a/third_party/rust/failure/src/backtrace/internal.rs b/third_party/rust/failure/src/backtrace/internal.rs index 7be137b75e6f..5e421201fad9 100644 --- a/third_party/rust/failure/src/backtrace/internal.rs +++ b/third_party/rust/failure/src/backtrace/internal.rs @@ -2,6 +2,7 @@ use std::cell::UnsafeCell; use std::env; use std::ffi::OsString; use std::fmt; +#[allow(deprecated)] // to allow for older Rust versions (<1.24) use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::sync::Mutex; @@ -24,6 +25,7 @@ unsafe impl Sync for MaybeResolved {} impl InternalBacktrace { pub(super) fn new() -> InternalBacktrace { + #[allow(deprecated)] // to allow for older Rust versions (<1.24) static ENABLED: AtomicUsize = ATOMIC_USIZE_INIT; match ENABLED.load(Ordering::SeqCst) { diff --git a/third_party/rust/failure/src/backtrace/mod.rs b/third_party/rust/failure/src/backtrace/mod.rs index 58f0477b31c6..9eba16d9cb80 100644 --- a/third_party/rust/failure/src/backtrace/mod.rs +++ b/third_party/rust/failure/src/backtrace/mod.rs @@ -52,6 +52,16 @@ without_backtrace! { pub(crate) fn is_none(&self) -> bool { true } + + /// Returns true if displaying this backtrace would be an empty string. + /// + /// > (We have detected that this crate was documented with no_std + /// > compatibility turned on. The version of this crate that has been + /// > documented here will never generate a backtrace and this method + /// > will always return true.) + pub fn is_empty(&self) -> bool { + true + } } impl Default for Backtrace { @@ -118,6 +128,11 @@ with_backtrace! { pub(crate) fn is_none(&self) -> bool { self.internal.is_none() } + + /// Returns true if displaying this backtrace would be an empty string. + pub fn is_empty(&self) -> bool { + self.internal.is_none() + } } impl Default for Backtrace { @@ -129,7 +144,7 @@ with_backtrace! { impl Debug for Backtrace { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(bt) = self.internal.as_backtrace() { - bt.fmt(f) + Debug::fmt(bt, f) } else { Ok(()) } } } @@ -137,7 +152,7 @@ with_backtrace! { impl Display for Backtrace { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(bt) = self.internal.as_backtrace() { - bt.fmt(f) + Debug::fmt(bt, f) } else { Ok(()) } } } diff --git a/third_party/rust/failure/src/box_std.rs b/third_party/rust/failure/src/box_std.rs index a58ae6666c79..05891db13c2e 100644 --- a/third_party/rust/failure/src/box_std.rs +++ b/third_party/rust/failure/src/box_std.rs @@ -2,7 +2,7 @@ use std::error::Error; use std::fmt; use Fail; -pub struct BoxStd(pub Box); +pub struct BoxStd(pub Box); impl fmt::Display for BoxStd { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/third_party/rust/failure/src/compat.rs b/third_party/rust/failure/src/compat.rs index 9a47bdb24d22..dec53838284b 100644 --- a/third_party/rust/failure/src/compat.rs +++ b/third_party/rust/failure/src/compat.rs @@ -39,8 +39,14 @@ with_std! { } } - impl From for Box { - fn from(error: Error) -> Box { + impl From for Box { + fn from(error: Error) -> Box { + Box::new(Compat { error }) + } + } + + impl From for Box { + fn from(error: Error) -> Box { Box::new(Compat { error }) } } diff --git a/third_party/rust/failure/src/context.rs b/third_party/rust/failure/src/context.rs index 3316b7693945..b5977e9a2817 100644 --- a/third_party/rust/failure/src/context.rs +++ b/third_party/rust/failure/src/context.rs @@ -108,7 +108,11 @@ with_std! { } impl Fail for Context { - fn cause(&self) -> Option<&Fail> { + fn name(&self) -> Option<&str> { + self.failure.as_cause().and_then(|x| x.name()) + } + + fn cause(&self) -> Option<&dyn Fail> { self.failure.as_cause() } @@ -142,7 +146,7 @@ with_std! { } } - fn as_cause(&self) -> Option<&Fail> { + fn as_cause(&self) -> Option<&dyn Fail> { match *self { Either::This(_) => None, Either::That(ref error) => Some(error.as_fail()) diff --git a/third_party/rust/failure/src/error/error_impl.rs b/third_party/rust/failure/src/error/error_impl.rs index d1644caf075a..6a95d92d18ed 100644 --- a/third_party/rust/failure/src/error/error_impl.rs +++ b/third_party/rust/failure/src/error/error_impl.rs @@ -4,7 +4,7 @@ use Fail; use backtrace::Backtrace; pub(crate) struct ErrorImpl { - inner: Box>, + inner: Box>, } struct Inner { @@ -25,11 +25,11 @@ impl From for ErrorImpl { } impl ErrorImpl { - pub(crate) fn failure(&self) -> &Fail { + pub(crate) fn failure(&self) -> &dyn Fail { &self.inner.failure } - pub(crate) fn failure_mut(&mut self) -> &mut Fail { + pub(crate) fn failure_mut(&mut self) -> &mut dyn Fail { &mut self.inner.failure } diff --git a/third_party/rust/failure/src/error/mod.rs b/third_party/rust/failure/src/error/mod.rs index 30e69cc31e27..842dbbae0c4b 100644 --- a/third_party/rust/failure/src/error/mod.rs +++ b/third_party/rust/failure/src/error/mod.rs @@ -60,16 +60,21 @@ impl Error { /// } /// ``` #[cfg(feature = "std")] - pub fn from_boxed_compat(err: Box) -> Error { + pub fn from_boxed_compat(err: Box) -> Error { Error::from(BoxStd(err)) } /// Return a reference to the underlying failure that this `Error` /// contains. - pub fn as_fail(&self) -> &Fail { + pub fn as_fail(&self) -> &dyn Fail { self.imp.failure() } + /// Returns the name of the underlying fail. + pub fn name(&self) -> Option<&str> { + self.as_fail().name() + } + /// Returns a reference to the underlying cause of this `Error`. Unlike the /// method on `Fail`, this does not return an `Option`. The `Error` type /// always has an underlying failure. @@ -77,7 +82,7 @@ impl Error { /// This method has been deprecated in favor of the [Error::as_fail] method, /// which does the same thing. #[deprecated(since = "0.1.2", note = "please use 'as_fail()' method instead")] - pub fn cause(&self) -> &Fail { + pub fn cause(&self) -> &dyn Fail { self.as_fail() } @@ -128,7 +133,7 @@ impl Error { /// Returns the "root cause" of this error - the last value in the /// cause chain which does not return an underlying `cause`. - pub fn find_root_cause(&self) -> &Fail { + pub fn find_root_cause(&self) -> &dyn Fail { self.as_fail().find_root_cause() } @@ -168,7 +173,7 @@ impl Error { /// Deprecated alias to `find_root_cause`. #[deprecated(since = "0.1.2", note = "please use the 'find_root_cause()' method instead")] - pub fn root_cause(&self) -> &Fail { + pub fn root_cause(&self) -> &dyn Fail { ::find_root_cause(self.as_fail()) } @@ -196,8 +201,8 @@ impl Debug for Error { } } -impl AsRef for Error { - fn as_ref(&self) -> &Fail { +impl AsRef for Error { + fn as_ref(&self) -> &dyn Fail { self.as_fail() } } diff --git a/third_party/rust/failure/src/error_message.rs b/third_party/rust/failure/src/error_message.rs index 01ff1ae36c88..560d317b4df7 100644 --- a/third_party/rust/failure/src/error_message.rs +++ b/third_party/rust/failure/src/error_message.rs @@ -19,7 +19,11 @@ struct ErrorMessage { msg: D, } -impl Fail for ErrorMessage { } +impl Fail for ErrorMessage { + fn name(&self) -> Option<&str> { + Some("failure::ErrorMessage") + } +} impl Display for ErrorMessage { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/third_party/rust/failure/src/lib.rs b/third_party/rust/failure/src/lib.rs index 82c021fa6920..41a45ba474d2 100644 --- a/third_party/rust/failure/src/lib.rs +++ b/third_party/rust/failure/src/lib.rs @@ -23,10 +23,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![deny(missing_docs)] #![deny(warnings)] -#![cfg_attr( - feature = "small-error", - feature(extern_types, allocator_api) -)] +#![cfg_attr(feature = "small-error", feature(extern_types, allocator_api))] macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) } macro_rules! without_std { ($($i:item)*) => ($(#[cfg(not(feature = "std"))]$i)*) } @@ -109,6 +106,16 @@ with_std! { /// `std::error::Error`, and are also `Send`, `Sync`, and `'static`, implement /// `Fail` by a blanket impl. pub trait Fail: Display + Debug + Send + Sync + 'static { + /// Returns the "name" of the error. + /// + /// This is typically the type name. Not all errors will implement + /// this. This method is expected to be most useful in situations + /// where errors need to be reported to external instrumentation systems + /// such as crash reporters. + fn name(&self) -> Option<&str> { + None + } + /// Returns a reference to the underlying cause of this failure, if it /// is an error that wraps other errors. /// @@ -119,7 +126,7 @@ pub trait Fail: Display + Debug + Send + Sync + 'static { /// `Some` when it can return a **different** failure. Users may loop /// over the cause chain, and returning `self` would result in an infinite /// loop. - fn cause(&self) -> Option<&Fail> { + fn cause(&self) -> Option<&dyn Fail> { None } @@ -166,10 +173,7 @@ pub trait Fail: Display + Debug + Send + Sync + 'static { } #[doc(hidden)] - #[deprecated( - since = "0.1.2", - note = "please use the 'iter_chain()' method instead" - )] + #[deprecated(since = "0.1.2", note = "please use the 'iter_chain()' method instead")] fn causes(&self) -> Causes where Self: Sized, @@ -182,7 +186,7 @@ pub trait Fail: Display + Debug + Send + Sync + 'static { since = "0.1.2", note = "please use the 'find_root_cause()' method instead" )] - fn root_cause(&self) -> &Fail + fn root_cause(&self) -> &dyn Fail where Self: Sized, { @@ -195,13 +199,13 @@ pub trait Fail: Display + Debug + Send + Sync + 'static { } } -impl Fail { +impl dyn Fail { /// Attempts to downcast this failure to a concrete type by reference. /// /// If the underlying error is not of type `T`, this will return `None`. pub fn downcast_ref(&self) -> Option<&T> { if self.__private_get_type_id__() == TypeId::of::() { - unsafe { Some(&*(self as *const Fail as *const T)) } + unsafe { Some(&*(self as *const dyn Fail as *const T)) } } else { None } @@ -213,7 +217,7 @@ impl Fail { /// If the underlying error is not of type `T`, this will return `None`. pub fn downcast_mut(&mut self) -> Option<&mut T> { if self.__private_get_type_id__() == TypeId::of::() { - unsafe { Some(&mut *(self as *mut Fail as *mut T)) } + unsafe { Some(&mut *(self as *mut dyn Fail as *mut T)) } } else { None } @@ -227,7 +231,7 @@ impl Fail { /// /// This is equivalent to iterating over `iter_causes()` and taking /// the last item. - pub fn find_root_cause(&self) -> &Fail { + pub fn find_root_cause(&self) -> &dyn Fail { find_root_cause(self) } @@ -254,15 +258,12 @@ impl Fail { since = "0.1.2", note = "please use the 'find_root_cause()' method instead" )] - pub fn root_cause(&self) -> &Fail { + pub fn root_cause(&self) -> &dyn Fail { find_root_cause(self) } /// Deprecated alias to `iter_chain`. - #[deprecated( - since = "0.1.2", - note = "please use the 'iter_chain()' method instead" - )] + #[deprecated(since = "0.1.2", note = "please use the 'iter_chain()' method instead")] pub fn causes(&self) -> Causes { Causes { fail: Some(self) } } @@ -272,8 +273,8 @@ impl Fail { impl Fail for E {} #[cfg(feature = "std")] -impl Fail for Box { - fn cause(&self) -> Option<&Fail> { +impl Fail for Box { + fn cause(&self) -> Option<&dyn Fail> { (**self).cause() } @@ -284,12 +285,12 @@ impl Fail for Box { /// A iterator over the causes of a `Fail` pub struct Causes<'f> { - fail: Option<&'f Fail>, + fail: Option<&'f dyn Fail>, } impl<'f> Iterator for Causes<'f> { - type Item = &'f Fail; - fn next(&mut self) -> Option<&'f Fail> { + type Item = &'f dyn Fail; + fn next(&mut self) -> Option<&'f dyn Fail> { self.fail.map(|fail| { self.fail = fail.cause(); fail @@ -297,7 +298,7 @@ impl<'f> Iterator for Causes<'f> { } } -fn find_root_cause(mut fail: &Fail) -> &Fail { +fn find_root_cause(mut fail: &dyn Fail) -> &dyn Fail { while let Some(cause) = fail.cause() { fail = cause; } diff --git a/third_party/rust/failure/src/macros.rs b/third_party/rust/failure/src/macros.rs index b96e91a991a8..c0a9dad294a8 100644 --- a/third_party/rust/failure/src/macros.rs +++ b/third_party/rust/failure/src/macros.rs @@ -11,8 +11,8 @@ macro_rules! bail { ($e:expr) => { return Err($crate::err_msg($e)); }; - ($fmt:expr, $($arg:tt)+) => { - return Err($crate::err_msg(format!($fmt, $($arg)+))); + ($fmt:expr, $($arg:tt)*) => { + return Err($crate::err_msg(format!($fmt, $($arg)*))); }; } @@ -23,18 +23,31 @@ macro_rules! bail { /// it does not panic. #[macro_export(local_inner_macros)] macro_rules! ensure { + ($cond:expr) => { + if !($cond) { + bail!("{}", _failure__stringify!($cond)); + } + }; ($cond:expr, $e:expr) => { if !($cond) { bail!($e); } }; - ($cond:expr, $fmt:expr, $($arg:tt)+) => { + ($cond:expr, $fmt:expr, $($arg:tt)*) => { if !($cond) { - bail!($fmt, $($arg)+); + bail!($fmt, $($arg)*); } }; } +#[doc(hidden)] +#[macro_export] +macro_rules! _failure__stringify { + ($($inner:tt)*) => { + stringify! { $($inner)* } + } +} + /// Constructs an `Error` using the standard string interpolation syntax. /// /// ```rust diff --git a/third_party/rust/failure/tests/basic_fail.rs b/third_party/rust/failure/tests/basic_fail.rs new file mode 100644 index 000000000000..574886db7e71 --- /dev/null +++ b/third_party/rust/failure/tests/basic_fail.rs @@ -0,0 +1,21 @@ +#[macro_use] +extern crate failure; + +use failure::Fail; + +#[test] +fn test_name() { + #[derive(Fail, Debug)] + #[fail(display = "my error")] + struct MyError; + + let err = MyError; + + assert_eq!(err.to_string(), "my error"); + assert_eq!(err.name(), Some("basic_fail::MyError")); + + let ctx = err.context("whatever"); + + assert_eq!(ctx.to_string(), "whatever"); + assert_eq!(ctx.name(), Some("basic_fail::MyError")); +} \ No newline at end of file diff --git a/third_party/rust/failure/tests/fail_compat.rs b/third_party/rust/failure/tests/fail_compat.rs new file mode 100644 index 000000000000..81f84be76a79 --- /dev/null +++ b/third_party/rust/failure/tests/fail_compat.rs @@ -0,0 +1,35 @@ +#[macro_use] +extern crate failure; + +use failure::Fail; + +fn return_failure() -> Result<(), failure::Error> { + #[derive(Fail, Debug)] + #[fail(display = "my error")] + struct MyError; + + let err = MyError; + Err(err.into()) +} + +fn return_error() -> Result<(), Box> { + return_failure()?; + Ok(()) +} + +fn return_error_send_sync() -> Result<(), Box> { + return_failure()?; + Ok(()) +} + +#[test] +fn smoke_default_compat() { + let err = return_error(); + assert!(err.is_err()); +} + +#[test] +fn smoke_compat_send_sync() { + let err = return_error_send_sync(); + assert!(err.is_err()); +} diff --git a/third_party/rust/failure/tests/macro_trailing_comma.rs b/third_party/rust/failure/tests/macro_trailing_comma.rs new file mode 100644 index 000000000000..012d0061700f --- /dev/null +++ b/third_party/rust/failure/tests/macro_trailing_comma.rs @@ -0,0 +1,67 @@ +#[macro_use] +extern crate failure; + +// NOTE: +// +// This test is in a separate file due to the fact that ensure! cannot be used +// from within failure. +// +// (you get: 'macro-expanded `macro_export` macros from the current crate cannot +// be referred to by absolute paths') + +// Encloses an early-returning macro in an IIFE so that we +// can treat it as a Result-returning function. +macro_rules! wrap_early_return { + ($expr:expr) => {{ + fn func() -> Result<(), failure::Error> { + let _ = $expr; + + #[allow(unreachable_code)] + Ok(()) + } + func().map_err(|e| e.to_string()) + }}; +} + +#[test] +fn bail() { + assert_eq!( + wrap_early_return!(bail!("test")), + wrap_early_return!(bail!("test",))); + assert_eq!( + wrap_early_return!(bail!("test {}", 4)), + wrap_early_return!(bail!("test {}", 4,))); +} + +#[test] +fn ensure() { + assert_eq!( + wrap_early_return!(ensure!(false, "test")), + wrap_early_return!(ensure!(false, "test",))); + assert_eq!( + wrap_early_return!(ensure!(false, "test {}", 4)), + wrap_early_return!(ensure!(false, "test {}", 4,))); +} + +#[test] +fn single_arg_ensure() { + assert_eq!( + wrap_early_return!(ensure!(false)), + Err("false".to_string())); + assert_eq!( + wrap_early_return!(ensure!(true == false)), + Err("true == false".to_string())); + assert_eq!( + wrap_early_return!(ensure!(4 == 5)), + Err("4 == 5".to_string())); +} + +#[test] +fn format_err() { + assert_eq!( + format_err!("test").to_string(), + format_err!("test",).to_string()); + assert_eq!( + format_err!("test {}", 4).to_string(), + format_err!("test {}", 4,).to_string()); +} diff --git a/third_party/rust/failure_derive/.cargo-checksum.json b/third_party/rust/failure_derive/.cargo-checksum.json index 9abeff9ea455..44ba84a1a904 100644 --- a/third_party/rust/failure_derive/.cargo-checksum.json +++ b/third_party/rust/failure_derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"e00026aba3492ad169fcb6123e896280d679ffb9a198c6830052c99df3246142","build.rs":"c7481c027fc4c09e2d6dc8ac642ec5314b6a02269fb022b0f3c1850f000d31f5","src/lib.rs":"833b9916cd18b2e0b4fa79cc795afd00089697be7a25bf6895e85ed4cef97916","tests/backtrace.rs":"56b2b97f83e5341108aac403a50491560dc6d897d6002973248c9c9014c0e494","tests/custom_type_bounds.rs":"745d3e488738f5d90bcb1fa66a6784b64a88881b1d62c241cba2f863f4eb31c8","tests/no_derive_display.rs":"3ab159aadf809a95d578b4909470f6ecca24cea0caf514509d326601cc7b933b","tests/tests.rs":"eaf131c01cc101b94fd6478a9964f5e3d919f2260f6d327f0e435ac3520fe71e","tests/wraps.rs":"e00c2761ccd9fe84df47bd102945818f5d8868c95bcab719ebdde0db8334d4a6"},"package":"64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"} \ No newline at end of file +{"files":{"Cargo.toml":"3fe281152af8a1081e0816949e3e476d3c991341c1a294c064414345aa6bc995","build.rs":"c7481c027fc4c09e2d6dc8ac642ec5314b6a02269fb022b0f3c1850f000d31f5","src/lib.rs":"c446d83b42f5aca4453da4e2dd8e40dbfe9aa33ba1a038217174ece5158b7196","tests/backtrace.rs":"56b2b97f83e5341108aac403a50491560dc6d897d6002973248c9c9014c0e494","tests/custom_type_bounds.rs":"745d3e488738f5d90bcb1fa66a6784b64a88881b1d62c241cba2f863f4eb31c8","tests/no_derive_display.rs":"3ab159aadf809a95d578b4909470f6ecca24cea0caf514509d326601cc7b933b","tests/tests.rs":"eaf131c01cc101b94fd6478a9964f5e3d919f2260f6d327f0e435ac3520fe71e","tests/wraps.rs":"cc2bc5a5555756082ec570afa310939ba7f74a20898991a89fab75232380fd21"},"package":"0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"} \ No newline at end of file diff --git a/third_party/rust/failure_derive/Cargo.toml b/third_party/rust/failure_derive/Cargo.toml index cba085a957e6..fe03a51c7429 100644 --- a/third_party/rust/failure_derive/Cargo.toml +++ b/third_party/rust/failure_derive/Cargo.toml @@ -3,7 +3,7 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g. crates.io) dependencies +# to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're @@ -12,28 +12,28 @@ [package] name = "failure_derive" -version = "0.1.3" +version = "0.1.6" authors = ["Without Boats "] build = "build.rs" description = "derives for the failure crate" -homepage = "https://boats.gitlab.io/failure" -documentation = "https://boats.gitlab.io/failure" +homepage = "https://rust-lang-nursery.github.io/failure/" +documentation = "https://docs.rs/failure" license = "MIT OR Apache-2.0" repository = "https://github.com/withoutboats/failure_derive" [lib] proc-macro = true [dependencies.proc-macro2] -version = "0.4.8" +version = "1" [dependencies.quote] -version = "0.6.3" +version = "1" [dependencies.syn] -version = "0.15.0" +version = "1.0.3" [dependencies.synstructure] -version = "0.10.0" +version = "0.12.0" [dev-dependencies.failure] version = "0.1.0" diff --git a/third_party/rust/failure_derive/src/lib.rs b/third_party/rust/failure_derive/src/lib.rs index 4e9b22f8e8e6..fe9e76c4e37f 100644 --- a/third_party/rust/failure_derive/src/lib.rs +++ b/third_party/rust/failure_derive/src/lib.rs @@ -6,17 +6,49 @@ extern crate synstructure; #[macro_use] extern crate quote; -use proc_macro2::TokenStream; +use proc_macro2::{TokenStream, Span}; +use syn::LitStr; +use syn::spanned::Spanned; + +#[derive(Debug)] +struct Error(TokenStream); + +impl Error { + fn new(span: Span, message: &str) -> Error { + Error(quote_spanned! { span => + compile_error!(#message); + }) + } + + fn into_tokens(self) -> TokenStream { + self.0 + } +} + +impl From for Error { + fn from(e: syn::Error) -> Error { + Error(e.to_compile_error()) + } +} decl_derive!([Fail, attributes(fail, cause)] => fail_derive); fn fail_derive(s: synstructure::Structure) -> TokenStream { + match fail_derive_impl(s) { + Err(err) => err.into_tokens(), + Ok(tokens) => tokens, + } +} + +fn fail_derive_impl(s: synstructure::Structure) -> Result { let make_dyn = if cfg!(has_dyn_trait) { quote! { &dyn } } else { quote! { & } }; + let ty_name = LitStr::new(&s.ast().ident.to_string(), Span::call_site()); + let cause_body = s.each_variant(|v| { if let Some(cause) = v.bindings().iter().find(is_cause) { quote!(return Some(::failure::AsFail::as_fail(#cause))) @@ -36,6 +68,10 @@ fn fail_derive(s: synstructure::Structure) -> TokenStream { let fail = s.unbound_impl( quote!(::failure::Fail), quote! { + fn name(&self) -> Option<&str> { + Some(concat!(module_path!(), "::", #ty_name)) + } + #[allow(unreachable_code)] fn cause(&self) -> ::failure::_core::option::Option<#make_dyn(::failure::Fail)> { match *self { #cause_body } @@ -49,7 +85,7 @@ fn fail_derive(s: synstructure::Structure) -> TokenStream { } }, ); - let display = display_body(&s).map(|display_body| { + let display = display_body(&s)?.map(|display_body| { s.unbound_impl( quote!(::failure::_core::fmt::Display), quote! { @@ -62,98 +98,128 @@ fn fail_derive(s: synstructure::Structure) -> TokenStream { ) }); - (quote! { + Ok(quote! { #fail #display - }).into() + }) } -fn display_body(s: &synstructure::Structure) -> Option { +fn display_body(s: &synstructure::Structure) -> Result, Error> { let mut msgs = s.variants().iter().map(|v| find_error_msg(&v.ast().attrs)); - if msgs.all(|msg| msg.is_none()) { - return None; + if msgs.all(|msg| msg.map(|m| m.is_none()).unwrap_or(true)) { + return Ok(None); } - Some(s.each_variant(|v| { + let mut tokens = TokenStream::new(); + for v in s.variants() { let msg = - find_error_msg(&v.ast().attrs).expect("All variants must have display attribute."); + find_error_msg(&v.ast().attrs)? + .ok_or_else(|| Error::new( + v.ast().ident.span(), + "All variants must have display attribute." + ))?; if msg.nested.is_empty() { - panic!("Expected at least one argument to fail attribute"); + return Err(Error::new( + msg.span(), + "Expected at least one argument to fail attribute" + )); } let format_string = match msg.nested[0] { - syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) if nv.ident == "display" => { + syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) if nv.path.is_ident("display") => { nv.lit.clone() } _ => { - panic!("Fail attribute must begin `display = \"\"` to control the Display message.") + return Err(Error::new( + msg.span(), + "Fail attribute must begin `display = \"\"` to control the Display message." + )); } }; let args = msg.nested.iter().skip(1).map(|arg| match *arg { - syn::NestedMeta::Literal(syn::Lit::Int(ref i)) => { - let bi = &v.bindings()[i.value() as usize]; - quote!(#bi) + syn::NestedMeta::Lit(syn::Lit::Int(ref i)) => { + let bi = &v.bindings()[i.base10_parse::()?]; + Ok(quote!(#bi)) } - syn::NestedMeta::Meta(syn::Meta::Word(ref id)) => { - let id_s = id.to_string(); + syn::NestedMeta::Meta(syn::Meta::Path(ref path)) => { + let id_s = path.get_ident().map(syn::Ident::to_string).unwrap_or("".to_string()); if id_s.starts_with("_") { if let Ok(idx) = id_s[1..].parse::() { let bi = match v.bindings().get(idx) { Some(bi) => bi, None => { - panic!( - "display attempted to access field `{}` in `{}::{}` which \ + return Err(Error::new( + arg.span(), + &format!( + "display attempted to access field `{}` in `{}::{}` which \ does not exist (there are {} field{})", - idx, - s.ast().ident, - v.ast().ident, - v.bindings().len(), - if v.bindings().len() != 1 { "s" } else { "" } - ); + idx, + s.ast().ident, + v.ast().ident, + v.bindings().len(), + if v.bindings().len() != 1 { "s" } else { "" } + ) + )); } }; - return quote!(#bi); + return Ok(quote!(#bi)); } } for bi in v.bindings() { - if bi.ast().ident.as_ref() == Some(id) { - return quote!(#bi); + let id = bi.ast().ident.as_ref(); + if id.is_some() && path.is_ident(id.unwrap()) { + return Ok(quote!(#bi)); } } - panic!( - "Couldn't find field `{}` in `{}::{}`", - id, - s.ast().ident, - v.ast().ident - ); + return Err(Error::new( + arg.span(), + &format!( + "Couldn't find field `{:?}` in `{}::{}`", + path, + s.ast().ident, + v.ast().ident + ) + )); } - _ => panic!("Invalid argument to fail attribute!"), + ref arg => { + return Err(Error::new( + arg.span(), + "Invalid argument to fail attribute!" + )); + }, }); + let args = args.collect::, _>>()?; - quote! { - return write!(f, #format_string #(, #args)*) - } - })) + let pat = v.pat(); + tokens.extend(quote!(#pat => { return write!(f, #format_string #(, #args)*) })); + } + Ok(Some(tokens)) } -fn find_error_msg(attrs: &[syn::Attribute]) -> Option { +fn find_error_msg(attrs: &[syn::Attribute]) -> Result, Error> { let mut error_msg = None; for attr in attrs { - if let Some(meta) = attr.interpret_meta() { - if meta.name() == "fail" { + if let Ok(meta) = attr.parse_meta() { + if meta.path().is_ident("fail") { if error_msg.is_some() { - panic!("Cannot have two display attributes") + return Err(Error::new( + meta.span(), + "Cannot have two display attributes" + )); } else { if let syn::Meta::List(list) = meta { error_msg = Some(list); } else { - panic!("fail attribute must take a list in parentheses") + return Err(Error::new( + meta.span(), + "fail attribute must take a list in parentheses" + )); } } } } } - error_msg + Ok(error_msg) } fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool { @@ -164,7 +230,7 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool { segments: ref path, .. }, }) => path.last().map_or(false, |s| { - s.value().ident == "Backtrace" && s.value().arguments.is_empty() + s.ident == "Backtrace" && s.arguments.is_empty() }), _ => false, } @@ -173,18 +239,18 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool { fn is_cause(bi: &&synstructure::BindingInfo) -> bool { let mut found_cause = false; for attr in &bi.ast().attrs { - if let Some(meta) = attr.interpret_meta() { - if meta.name() == "cause" { + if let Ok(meta) = attr.parse_meta() { + if meta.path().is_ident("cause") { if found_cause { panic!("Cannot have two `cause` attributes"); } found_cause = true; } - if meta.name() == "fail" { + if meta.path().is_ident("fail") { if let syn::Meta::List(ref list) = meta { if let Some(ref pair) = list.nested.first() { - if let &&syn::NestedMeta::Meta(syn::Meta::Word(ref word)) = pair.value() { - if word == "cause" { + if let &&syn::NestedMeta::Meta(syn::Meta::Path(ref path)) = pair { + if path.is_ident("cause") { if found_cause { panic!("Cannot have two `cause` attributes"); } diff --git a/third_party/rust/failure_derive/tests/wraps.rs b/third_party/rust/failure_derive/tests/wraps.rs index b33b6da95041..9144325cad5d 100644 --- a/third_party/rust/failure_derive/tests/wraps.rs +++ b/third_party/rust/failure_derive/tests/wraps.rs @@ -18,11 +18,10 @@ struct WrapError { fn wrap_error() { let inner = io::Error::from_raw_os_error(98); let err = WrapError { inner }; - assert!( - err.cause() - .and_then(|err| err.downcast_ref::()) - .is_some() - ); + assert!(err + .cause() + .and_then(|err| err.downcast_ref::()) + .is_some()); } #[derive(Fail, Debug)] @@ -33,11 +32,10 @@ struct WrapTupleError(#[fail(cause)] io::Error); fn wrap_tuple_error() { let io_error = io::Error::from_raw_os_error(98); let err: WrapTupleError = WrapTupleError(io_error); - assert!( - err.cause() - .and_then(|err| err.downcast_ref::()) - .is_some() - ); + assert!(err + .cause() + .and_then(|err| err.downcast_ref::()) + .is_some()); } #[derive(Fail, Debug)] @@ -55,12 +53,13 @@ fn wrap_backtrace_error() { inner, backtrace: Backtrace::new(), }; - assert!( - err.cause() - .and_then(|err| err.downcast_ref::()) - .is_some() - ); + assert!(err + .cause() + .and_then(|err| err.downcast_ref::()) + .is_some()); assert!(err.backtrace().is_some()); + assert!(err.backtrace().unwrap().is_empty()); + assert!(err.backtrace().unwrap().to_string().trim().is_empty()); } #[derive(Fail, Debug)] @@ -79,21 +78,21 @@ enum WrapEnumError { fn wrap_enum_error() { let io_error = io::Error::from_raw_os_error(98); let err: WrapEnumError = WrapEnumError::Io(io_error); - assert!( - err.cause() - .and_then(|err| err.downcast_ref::()) - .is_some() - ); + assert!(err + .cause() + .and_then(|err| err.downcast_ref::()) + .is_some()); assert!(err.backtrace().is_none()); let fmt_error = fmt::Error::default(); let err: WrapEnumError = WrapEnumError::Fmt { inner: fmt_error, backtrace: Backtrace::new(), }; - assert!( - err.cause() - .and_then(|err| err.downcast_ref::()) - .is_some() - ); + assert!(err + .cause() + .and_then(|err| err.downcast_ref::()) + .is_some()); assert!(err.backtrace().is_some()); + assert!(err.backtrace().unwrap().is_empty()); + assert!(err.backtrace().unwrap().to_string().trim().is_empty()); } diff --git a/third_party/rust/malloc_size_of_derive/.cargo-checksum.json b/third_party/rust/malloc_size_of_derive/.cargo-checksum.json index c79b3a155d12..cc8d72be47fd 100644 --- a/third_party/rust/malloc_size_of_derive/.cargo-checksum.json +++ b/third_party/rust/malloc_size_of_derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"ca54d29c0cfac91471c60317233978b7e23f4d82537b3116431f681b44f98b33","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"c6f47e3c516f7dfc1b0eeaa999e557ec129cb0bbe2e70d712293d56af09141c3","lib.rs":"d0aec9f3ccc0a86d4d8979baa7b8c334e211878b12f1a3df9c6489b786894f03"},"package":"35adee9ed962cf7d07d62cb58bc45029f3227f5b5b86246caa8632f06c187bc3"} \ No newline at end of file +{"files":{"Cargo.toml":"8dd7d4c64162814f1633a91c8705ce70e3821da10b1571c7f5702d9985c7e54d","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"c6f47e3c516f7dfc1b0eeaa999e557ec129cb0bbe2e70d712293d56af09141c3","lib.rs":"222afac401a8cb257b30c45afb844f61d06bb031c999f8b2d45992163fbd7706"},"package":"e37c5d4cd9473c5f4c9c111f033f15d4df9bd378fdf615944e360a4f55a05f0b"} \ No newline at end of file diff --git a/third_party/rust/malloc_size_of_derive/Cargo.toml b/third_party/rust/malloc_size_of_derive/Cargo.toml index b7830aafab8b..2a82712558da 100644 --- a/third_party/rust/malloc_size_of_derive/Cargo.toml +++ b/third_party/rust/malloc_size_of_derive/Cargo.toml @@ -3,7 +3,7 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g. crates.io) dependencies +# to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're @@ -12,7 +12,7 @@ [package] name = "malloc_size_of_derive" -version = "0.1.0" +version = "0.1.1" authors = ["The Servo Project Developers"] description = "Crate for Firefox memory reporting, not intended for external use" license = "MIT/Apache-2.0" @@ -22,11 +22,11 @@ repository = "https://github.com/bholley/malloc_size_of_derive" path = "lib.rs" proc-macro = true [dependencies.proc-macro2] -version = "0.4" +version = "1" [dependencies.syn] -version = "0.15" +version = "1" features = ["full"] [dependencies.synstructure] -version = "0.10" +version = "0.12" diff --git a/third_party/rust/malloc_size_of_derive/lib.rs b/third_party/rust/malloc_size_of_derive/lib.rs index 0838f6cfb7fa..c1f9f693f789 100644 --- a/third_party/rust/malloc_size_of_derive/lib.rs +++ b/third_party/rust/malloc_size_of_derive/lib.rs @@ -25,17 +25,17 @@ fn malloc_size_of_derive(s: synstructure::Structure) -> proc_macro2::TokenStream .ast() .attrs .iter() - .any(|attr| match attr.interpret_meta().unwrap() { - syn::Meta::Word(ref ident) | syn::Meta::List(syn::MetaList { ref ident, .. }) - if ident == "ignore_malloc_size_of" => + .any(|attr| match attr.parse_meta().unwrap() { + syn::Meta::Path(ref path) | syn::Meta::List(syn::MetaList { ref path, .. }) + if path.is_ident("ignore_malloc_size_of") => { panic!( "#[ignore_malloc_size_of] should have an explanation, \ e.g. #[ignore_malloc_size_of = \"because reasons\"]" ); } - syn::Meta::NameValue(syn::MetaNameValue { ref ident, .. }) - if ident == "ignore_malloc_size_of" => + syn::Meta::NameValue(syn::MetaNameValue { ref path, .. }) + if path.is_ident("ignore_malloc_size_of") => { true }, diff --git a/third_party/rust/synstructure-0.10.1/.cargo-checksum.json b/third_party/rust/synstructure-0.10.1/.cargo-checksum.json deleted file mode 100644 index df49c14a40a9..000000000000 --- a/third_party/rust/synstructure-0.10.1/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"Cargo.toml":"e36eaee82d5b5aa7864148b96c363f1aa05676de4537d914b244446b685d23c0","LICENSE":"219920e865eee70b7dcfc948a86b099e7f4fe2de01bcca2ca9a20c0a033f2b59","README.md":"1ae9f6797e1affc45eaafac10cd5e2b68f4b7d9463c38d61bccbfb1115523bb1","src/lib.rs":"30ddc0d6d750328f146985d90c8a8e873f4105363722c31f16f466013c58cf82","src/macros.rs":"0db8830809f1e0e9f72767e3a0d45d8bd3f5be78ad20dc6e083e3b80fadebf60"},"package":"73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"} \ No newline at end of file diff --git a/third_party/rust/synstructure-0.10.1/Cargo.toml b/third_party/rust/synstructure-0.10.1/Cargo.toml deleted file mode 100644 index f0e657245854..000000000000 --- a/third_party/rust/synstructure-0.10.1/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g. crates.io) dependencies -# -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) - -[package] -name = "synstructure" -version = "0.10.1" -authors = ["Nika Layzell "] -include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"] -description = "Helper methods and macros for custom derives" -documentation = "https://docs.rs/synstructure" -readme = "README.md" -keywords = ["syn", "macros", "derive", "expand_substructure", "enum"] -license = "MIT" -repository = "https://github.com/mystor/synstructure" -[dependencies.proc-macro2] -version = "0.4" - -[dependencies.quote] -version = "0.6" - -[dependencies.syn] -version = "0.15" -features = ["visit", "extra-traits"] - -[dependencies.unicode-xid] -version = "0.1" -[dev-dependencies.synstructure_test_traits] -version = "0.1" - -[features] -simple-derive = [] diff --git a/third_party/rust/synstructure-0.10.1/LICENSE b/third_party/rust/synstructure-0.10.1/LICENSE deleted file mode 100644 index f78f1c15d129..000000000000 --- a/third_party/rust/synstructure-0.10.1/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2016 Nika Layzell - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/third_party/rust/synstructure-0.10.1/README.md b/third_party/rust/synstructure-0.10.1/README.md deleted file mode 100644 index 65dca6ba45ae..000000000000 --- a/third_party/rust/synstructure-0.10.1/README.md +++ /dev/null @@ -1,159 +0,0 @@ -# synstructure - -[![Latest Version](https://img.shields.io/crates/v/synstructure.svg)](https://crates.io/crates/synstructure) -[![Documentation](https://docs.rs/synstructure/badge.svg)](https://docs.rs/synstructure) -[![Build Status](https://travis-ci.org/mystor/synstructure.svg?branch=master)](https://travis-ci.org/mystor/synstructure) -[![Rustc Version 1.15+](https://img.shields.io/badge/rustc-1.15+-lightgray.svg)](https://blog.rust-lang.org/2017/02/02/Rust-1.15.html) - -> NOTE: What follows is an exerpt from the module level documentation. For full -> details read the docs on [docs.rs](https://docs.rs/synstructure/) - -This crate provides helper types for matching against enum variants, and -extracting bindings to each of the fields in the deriving Struct or Enum in -a generic way. - -If you are writing a `#[derive]` which needs to perform some operation on -every field, then you have come to the right place! - -# Example: `WalkFields` -### Trait Implementation -```rust -pub trait WalkFields: std::any::Any { - fn walk_fields(&self, walk: &mut FnMut(&WalkFields)); -} -impl WalkFields for i32 { - fn walk_fields(&self, _walk: &mut FnMut(&WalkFields)) {} -} -``` - -### Custom Derive -```rust -#[macro_use] -extern crate synstructure; -#[macro_use] -extern crate quote; -extern crate proc_macro2; - -fn walkfields_derive(s: synstructure::Structure) -> proc_macro2::TokenStream { - let body = s.each(|bi| quote!{ - walk(#bi) - }); - - s.bound_impl(quote!(example_traits::WalkFields), quote!{ - fn walk_fields(&self, walk: &mut FnMut(&example_traits::WalkFields)) { - match *self { #body } - } - }) -} -decl_derive!([WalkFields] => walkfields_derive); - -/* - * Test Case - */ -fn main() { - test_derive! { - walkfields_derive { - enum A { - B(i32, T), - C(i32), - } - } - expands to { - #[allow(non_upper_case_globals)] - const _DERIVE_example_traits_WalkFields_FOR_A: () = { - extern crate example_traits; - impl example_traits::WalkFields for A - where T: example_traits::WalkFields - { - fn walk_fields(&self, walk: &mut FnMut(&example_traits::WalkFields)) { - match *self { - A::B(ref __binding_0, ref __binding_1,) => { - { walk(__binding_0) } - { walk(__binding_1) } - } - A::C(ref __binding_0,) => { - { walk(__binding_0) } - } - } - } - } - }; - } - } -} -``` - -# Example: `Interest` -### Trait Implementation -```rust -pub trait Interest { - fn interesting(&self) -> bool; -} -impl Interest for i32 { - fn interesting(&self) -> bool { *self > 0 } -} -``` - -### Custom Derive -```rust -#[macro_use] -extern crate synstructure; -#[macro_use] -extern crate quote; -extern crate proc_macro2; - -fn interest_derive(mut s: synstructure::Structure) -> proc_macro2::TokenStream { - let body = s.fold(false, |acc, bi| quote!{ - #acc || example_traits::Interest::interesting(#bi) - }); - - s.bound_impl(quote!(example_traits::Interest), quote!{ - fn interesting(&self) -> bool { - match *self { - #body - } - } - }) -} -decl_derive!([Interest] => interest_derive); - -/* - * Test Case - */ -fn main() { - test_derive!{ - interest_derive { - enum A { - B(i32, T), - C(i32), - } - } - expands to { - #[allow(non_upper_case_globals)] - const _DERIVE_example_traits_Interest_FOR_A: () = { - extern crate example_traits; - impl example_traits::Interest for A - where T: example_traits::Interest - { - fn interesting(&self) -> bool { - match *self { - A::B(ref __binding_0, ref __binding_1,) => { - false || - example_traits::Interest::interesting(__binding_0) || - example_traits::Interest::interesting(__binding_1) - } - A::C(ref __binding_0,) => { - false || - example_traits::Interest::interesting(__binding_0) - } - } - } - } - }; - } - } -} -``` - -For more example usage, consider investigating the `abomonation_derive` crate, -which makes use of this crate, and is fairly simple. diff --git a/third_party/rust/synstructure-0.10.1/src/lib.rs b/third_party/rust/synstructure-0.10.1/src/lib.rs deleted file mode 100644 index 0bd138375adc..000000000000 --- a/third_party/rust/synstructure-0.10.1/src/lib.rs +++ /dev/null @@ -1,2283 +0,0 @@ -//! This crate provides helper types for matching against enum variants, and -//! extracting bindings to each of the fields in the deriving Struct or Enum in -//! a generic way. -//! -//! If you are writing a `#[derive]` which needs to perform some operation on -//! every field, then you have come to the right place! -//! -//! # Example: `WalkFields` -//! ### Trait Implementation -//! ``` -//! pub trait WalkFields: std::any::Any { -//! fn walk_fields(&self, walk: &mut FnMut(&WalkFields)); -//! } -//! impl WalkFields for i32 { -//! fn walk_fields(&self, _walk: &mut FnMut(&WalkFields)) {} -//! } -//! ``` -//! -//! ### Custom Derive -//! ``` -//! #[macro_use] -//! extern crate synstructure; -//! #[macro_use] -//! extern crate quote; -//! extern crate proc_macro2; -//! -//! fn walkfields_derive(s: synstructure::Structure) -> proc_macro2::TokenStream { -//! let body = s.each(|bi| quote!{ -//! walk(#bi) -//! }); -//! -//! s.gen_impl(quote! { -//! extern crate synstructure_test_traits; -//! -//! gen impl synstructure_test_traits::WalkFields for @Self { -//! fn walk_fields(&self, walk: &mut FnMut(&synstructure_test_traits::WalkFields)) { -//! match *self { #body } -//! } -//! } -//! }) -//! } -//! # const _IGNORE: &'static str = stringify!( -//! decl_derive!([WalkFields] => walkfields_derive); -//! # ); -//! -//! /* -//! * Test Case -//! */ -//! fn main() { -//! test_derive! { -//! walkfields_derive { -//! enum A { -//! B(i32, T), -//! C(i32), -//! } -//! } -//! expands to { -//! #[allow(non_upper_case_globals)] -//! const _DERIVE_synstructure_test_traits_WalkFields_FOR_A: () = { -//! extern crate synstructure_test_traits; -//! impl synstructure_test_traits::WalkFields for A -//! where T: synstructure_test_traits::WalkFields -//! { -//! fn walk_fields(&self, walk: &mut FnMut(&synstructure_test_traits::WalkFields)) { -//! match *self { -//! A::B(ref __binding_0, ref __binding_1,) => { -//! { walk(__binding_0) } -//! { walk(__binding_1) } -//! } -//! A::C(ref __binding_0,) => { -//! { walk(__binding_0) } -//! } -//! } -//! } -//! } -//! }; -//! } -//! } -//! } -//! ``` -//! -//! # Example: `Interest` -//! ### Trait Implementation -//! ``` -//! pub trait Interest { -//! fn interesting(&self) -> bool; -//! } -//! impl Interest for i32 { -//! fn interesting(&self) -> bool { *self > 0 } -//! } -//! ``` -//! -//! ### Custom Derive -//! ``` -//! #[macro_use] -//! extern crate synstructure; -//! #[macro_use] -//! extern crate quote; -//! extern crate proc_macro2; -//! -//! fn interest_derive(mut s: synstructure::Structure) -> proc_macro2::TokenStream { -//! let body = s.fold(false, |acc, bi| quote!{ -//! #acc || synstructure_test_traits::Interest::interesting(#bi) -//! }); -//! -//! s.gen_impl(quote! { -//! extern crate synstructure_test_traits; -//! gen impl synstructure_test_traits::Interest for @Self { -//! fn interesting(&self) -> bool { -//! match *self { -//! #body -//! } -//! } -//! } -//! }) -//! } -//! # const _IGNORE: &'static str = stringify!( -//! decl_derive!([Interest] => interest_derive); -//! # ); -//! -//! /* -//! * Test Case -//! */ -//! fn main() { -//! test_derive!{ -//! interest_derive { -//! enum A { -//! B(i32, T), -//! C(i32), -//! } -//! } -//! expands to { -//! #[allow(non_upper_case_globals)] -//! const _DERIVE_synstructure_test_traits_Interest_FOR_A: () = { -//! extern crate synstructure_test_traits; -//! impl synstructure_test_traits::Interest for A -//! where T: synstructure_test_traits::Interest -//! { -//! fn interesting(&self) -> bool { -//! match *self { -//! A::B(ref __binding_0, ref __binding_1,) => { -//! false || -//! synstructure_test_traits::Interest::interesting(__binding_0) || -//! synstructure_test_traits::Interest::interesting(__binding_1) -//! } -//! A::C(ref __binding_0,) => { -//! false || -//! synstructure_test_traits::Interest::interesting(__binding_0) -//! } -//! } -//! } -//! } -//! }; -//! } -//! } -//! } -//! ``` -//! -//! For more example usage, consider investigating the `abomonation_derive` crate, -//! which makes use of this crate, and is fairly simple. - -extern crate proc_macro; -extern crate proc_macro2; -#[macro_use] -extern crate quote; -#[macro_use] -extern crate syn; -extern crate unicode_xid; - -use std::collections::HashSet; - -use syn::{ - Generics, Ident, Attribute, Field, Fields, Expr, DeriveInput, - TraitBound, WhereClause, GenericParam, Data, WherePredicate, - TypeParamBound, Type, TypeMacro, FieldsUnnamed, FieldsNamed, - PredicateType, TypePath, token, punctuated, -}; -use syn::visit::{self, Visit}; - -// re-export the quote! macro so we can depend on it being around in our macro's -// implementations. -#[doc(hidden)] -pub use quote::*; -use proc_macro2::{TokenStream, TokenTree}; - -use unicode_xid::UnicodeXID; - -use proc_macro2::Span; - -// NOTE: This module has documentation hidden, as it only exports macros (which -// always appear in the root of the crate) and helper methods / re-exports used -// in the implementation of those macros. -#[doc(hidden)] -pub mod macros; - -/// Changes how bounds are added -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum AddBounds { - /// Add for fields and generics - Both, - /// Fields only - Fields, - /// Generics only - Generics, - /// None - None, - #[doc(hidden)] - __Nonexhaustive, -} - -/// The type of binding to use when generating a pattern. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum BindStyle { - /// `x` - Move, - /// `mut x` - MoveMut, - /// `ref x` - Ref, - /// `ref mut x` - RefMut, -} - -impl ToTokens for BindStyle { - fn to_tokens(&self, tokens: &mut TokenStream) { - match *self { - BindStyle::Move => {} - BindStyle::MoveMut => quote_spanned!(Span::call_site() => mut).to_tokens(tokens), - BindStyle::Ref => quote_spanned!(Span::call_site() => ref).to_tokens(tokens), - BindStyle::RefMut => quote_spanned!(Span::call_site() => ref mut).to_tokens(tokens), - } - } -} - -// Internal method for merging seen_generics arrays together. -fn generics_fuse(res: &mut Vec, new: &[bool]) { - for (i, &flag) in new.iter().enumerate() { - if i == res.len() { - res.push(false); - } - if flag { - res[i] = true; - } - } -} - -// Internal method for extracting the set of generics which have been matched. -fn fetch_generics<'a>(set: &[bool], generics: &'a Generics) -> Vec<&'a Ident> { - let mut tys = vec![]; - for (&seen, param) in set.iter().zip(generics.params.iter()) { - if seen { - match *param { - GenericParam::Type(ref tparam) => tys.push(&tparam.ident), - _ => {} - } - } - } - tys -} - -// Internal method for sanitizing an identifier for hygiene purposes. -fn sanitize_ident(s: &str) -> Ident { - let mut res = String::with_capacity(s.len()); - for mut c in s.chars() { - if ! UnicodeXID::is_xid_continue(c) { c = '_' } - // Deduplicate consecutive _ characters. - if res.ends_with('_') && c == '_' { continue } - res.push(c); - } - Ident::new(&res, Span::call_site()) -} - -// Internal method to merge two Generics objects together intelligently. -fn merge_generics(into: &mut Generics, from: &Generics) { - // Try to add the param into `into`, and merge parmas with identical names. - 'outer: for p in &from.params { - for op in &into.params { - match (op, p) { - (&GenericParam::Type(ref otp), &GenericParam::Type(ref tp)) => { - // NOTE: This is only OK because syn ignores the span for equality purposes. - if otp.ident == tp.ident { - panic!("Attempted to merge conflicting generic params: {} and {}", quote!{#op}, quote!{#p}); - } - } - (&GenericParam::Lifetime(ref olp), &GenericParam::Lifetime(ref lp)) => { - // NOTE: This is only OK because syn ignores the span for equality purposes. - if olp.lifetime == lp.lifetime { - panic!("Attempted to merge conflicting generic params: {} and {}", quote!{#op}, quote!{#p}); - } - } - // We don't support merging Const parameters, because that wouldn't make much sense. - _ => (), - } - } - into.params.push(p.clone()); - } - - // Add any where clauses from the input generics object. - if let Some(ref from_clause) = from.where_clause { - into.make_where_clause() - .predicates - .extend(from_clause.predicates.iter().cloned()); - } -} - -/// Information about a specific binding. This contains both an `Ident` -/// reference to the given field, and the syn `&'a Field` descriptor for that -/// field. -/// -/// This type supports `quote::ToTokens`, so can be directly used within the -/// `quote!` macro. It expands to a reference to the matched field. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BindingInfo<'a> { - /// The name which this BindingInfo will bind to. - pub binding: Ident, - - /// The type of binding which this BindingInfo will create. - pub style: BindStyle, - - field: &'a Field, - - // These are used to determine which type parameters are avaliable. - generics: &'a Generics, - seen_generics: Vec, -} - -impl<'a> ToTokens for BindingInfo<'a> { - fn to_tokens(&self, tokens: &mut TokenStream) { - self.binding.to_tokens(tokens); - } -} - -impl<'a> BindingInfo<'a> { - /// Returns a reference to the underlying `syn` AST node which this - /// `BindingInfo` references - pub fn ast(&self) -> &'a Field { - self.field - } - - /// Generates the pattern fragment for this field binding. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B{ a: i32, b: i32 }, - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].bindings()[0].pat().to_string(), - /// quote! { - /// ref __binding_0 - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn pat(&self) -> TokenStream { - let BindingInfo { - ref binding, - ref style, - .. - } = *self; - quote!(#style #binding) - } - - /// Returns a list of the type parameters which are referenced in this - /// field's type. - /// - /// # Caveat - /// - /// If the field contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # extern crate proc_macro2; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// struct A { - /// a: Option, - /// b: U, - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].bindings()[0].referenced_ty_params(), - /// &[&(syn::Ident::new("T", proc_macro2::Span::call_site()))] - /// ); - /// # } - /// ``` - pub fn referenced_ty_params(&self) -> Vec<&'a Ident> { - fetch_generics(&self.seen_generics, self.generics) - } -} - -/// This type is similar to `syn`'s `Variant` type, however each of the fields -/// are references rather than owned. When this is used as the AST for a real -/// variant, this struct simply borrows the fields of the `syn::Variant`, -/// however this type may also be used as the sole variant for a struct. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct VariantAst<'a> { - pub attrs: &'a [Attribute], - pub ident: &'a Ident, - pub fields: &'a Fields, - pub discriminant: &'a Option<(token::Eq, Expr)>, -} - -/// A wrapper around a `syn::DeriveInput`'s variant which provides utilities -/// for destructuring `Variant`s with `match` expressions. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct VariantInfo<'a> { - pub prefix: Option<&'a Ident>, - bindings: Vec>, - omitted_fields: bool, - ast: VariantAst<'a>, - generics: &'a Generics, -} - -/// Helper function used by the VariantInfo constructor. Walks all of the types -/// in `field` and returns a list of the type parameters from `ty_params` which -/// are referenced in the field. -fn get_ty_params<'a>(field: &Field, generics: &Generics) -> Vec { - // Helper type. Discovers all identifiers inside of the visited type, - // and calls a callback with them. - struct BoundTypeLocator<'a> { - result: Vec, - generics: &'a Generics, - } - - impl<'a> Visit<'a> for BoundTypeLocator<'a> { - // XXX: This also (intentionally) captures paths like T::SomeType. Is - // this desirable? - fn visit_ident(&mut self, id: &Ident) { - for (idx, i) in self.generics.params.iter().enumerate() { - if let GenericParam::Type(ref tparam) = *i { - if tparam.ident == *id { - self.result[idx] = true; - } - } - } - } - - fn visit_type_macro(&mut self, x: &'a TypeMacro) { - // If we see a type_mac declaration, then we can't know what type parameters - // it might be binding, so we presume it binds all of them. - for r in &mut self.result { - *r = true; - } - visit::visit_type_macro(self, x) - } - } - - let mut btl = BoundTypeLocator { - result: vec![false; generics.params.len()], - generics: generics, - }; - - btl.visit_type(&field.ty); - - btl.result -} - -impl<'a> VariantInfo<'a> { - fn new(ast: VariantAst<'a>, prefix: Option<&'a Ident>, generics: &'a Generics) -> Self { - let bindings = match *ast.fields { - Fields::Unit => vec![], - Fields::Unnamed(FieldsUnnamed { unnamed: ref fields, .. }) | - Fields::Named(FieldsNamed { named: ref fields, .. }) => { - fields.into_iter() - .enumerate() - .map(|(i, field)| { - BindingInfo { - // XXX: This has to be call_site to avoid privacy - // when deriving on private fields. - binding: Ident::new( - &format!("__binding_{}", i), - Span::call_site(), - ), - style: BindStyle::Ref, - field: field, - generics: generics, - seen_generics: get_ty_params(field, generics), - } - }) - .collect::>() - } - }; - - VariantInfo { - prefix: prefix, - bindings: bindings, - omitted_fields: false, - ast: ast, - generics: generics, - } - } - - /// Returns a slice of the bindings in this Variant. - pub fn bindings(&self) -> &[BindingInfo<'a>] { - &self.bindings - } - - /// Returns a mut slice of the bindings in this Variant. - pub fn bindings_mut(&mut self) -> &mut [BindingInfo<'a>] { - &mut self.bindings - } - - /// Returns a `VariantAst` object which contains references to the - /// underlying `syn` AST node which this `Variant` was created from. - pub fn ast(&self) -> VariantAst<'a> { - self.ast - } - - /// True if any bindings were omitted due to a `filter` call. - pub fn omitted_bindings(&self) -> bool { - self.omitted_fields - } - - /// Generates the match-arm pattern which could be used to match against this Variant. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].pat().to_string(), - /// quote!{ - /// A::B(ref __binding_0, ref __binding_1,) - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn pat(&self) -> TokenStream { - let mut t = TokenStream::new(); - if let Some(prefix) = self.prefix { - prefix.to_tokens(&mut t); - quote!(::).to_tokens(&mut t); - } - self.ast.ident.to_tokens(&mut t); - match *self.ast.fields { - Fields::Unit => { - assert!(self.bindings.len() == 0); - } - Fields::Unnamed(..) => { - token::Paren(Span::call_site()).surround(&mut t, |t| { - for binding in &self.bindings { - binding.pat().to_tokens(t); - quote!(,).to_tokens(t); - } - if self.omitted_fields { - quote!(..).to_tokens(t); - } - }) - } - Fields::Named(..) => { - token::Brace(Span::call_site()).surround(&mut t, |t| { - for binding in &self.bindings { - binding.field.ident.to_tokens(t); - quote!(:).to_tokens(t); - binding.pat().to_tokens(t); - quote!(,).to_tokens(t); - } - if self.omitted_fields { - quote!(..).to_tokens(t); - } - }) - } - } - t - } - - /// Generates the token stream required to construct the current variant. - /// - /// The init array initializes each of the fields in the order they are - /// written in `variant.ast().fields`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(usize, usize), - /// C{ v: usize }, - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].construct(|_, i| quote!(#i)).to_string(), - /// - /// quote!{ - /// A::B(0usize, 1usize,) - /// }.to_string() - /// ); - /// - /// assert_eq!( - /// s.variants()[1].construct(|_, i| quote!(#i)).to_string(), - /// - /// quote!{ - /// A::C{ v: 0usize, } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn construct(&self, mut func: F) -> TokenStream - where - F: FnMut(&Field, usize) -> T, - T: ToTokens, - { - let mut t = TokenStream::new(); - if let Some(prefix) = self.prefix { - quote!(#prefix ::).to_tokens(&mut t); - } - self.ast.ident.to_tokens(&mut t); - - match *self.ast.fields { - Fields::Unit => (), - Fields::Unnamed(FieldsUnnamed { ref unnamed, .. }) => { - token::Paren::default().surround(&mut t, |t| { - for (i, field) in unnamed.into_iter().enumerate() { - func(field, i).to_tokens(t); - quote!(,).to_tokens(t); - } - }) - } - Fields::Named(FieldsNamed { ref named, .. }) => { - token::Brace::default().surround(&mut t, |t| { - for (i, field) in named.into_iter().enumerate() { - field.ident.to_tokens(t); - quote!(:).to_tokens(t); - func(field, i).to_tokens(t); - quote!(,).to_tokens(t); - } - }) - } - } - t - } - - /// Runs the passed-in function once for each bound field, passing in a `BindingInfo`. - /// and generating a `match` arm which evaluates the returned tokens. - /// - /// This method will ignore fields which are ignored through the `filter` - /// method. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B(ref __binding_0, ref __binding_1,) => { - /// { println!("{:?}", __binding_0) } - /// { println!("{:?}", __binding_1) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn each(&self, mut f: F) -> TokenStream - where - F: FnMut(&BindingInfo) -> R, - R: ToTokens, - { - let pat = self.pat(); - let mut body = TokenStream::new(); - for binding in &self.bindings { - token::Brace::default().surround(&mut body, |body| { - f(binding).to_tokens(body); - }); - } - quote!(#pat => { #body }) - } - - /// Runs the passed-in function once for each bound field, passing in the - /// result of the previous call, and a `BindingInfo`. generating a `match` - /// arm which evaluates to the resulting tokens. - /// - /// This method will ignore fields which are ignored through the `filter` - /// method. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].fold(quote!(0), |acc, bi| quote!(#acc + #bi)).to_string(), - /// - /// quote!{ - /// A::B(ref __binding_0, ref __binding_1,) => { - /// 0 + __binding_0 + __binding_1 - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn fold(&self, init: I, mut f: F) -> TokenStream - where - F: FnMut(TokenStream, &BindingInfo) -> R, - I: ToTokens, - R: ToTokens, - { - let pat = self.pat(); - let body = self.bindings.iter().fold(quote!(#init), |i, bi| { - let r = f(i, bi); - quote!(#r) - }); - quote!(#pat => { #body }) - } - - /// Filter the bindings created by this `Variant` object. This has 2 effects: - /// - /// * The bindings will no longer appear in match arms generated by methods - /// on this `Variant` or its subobjects. - /// - /// * Impl blocks created with the `bound_impl` or `unsafe_bound_impl` - /// method only consider type parameters referenced in the types of - /// non-filtered fields. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # extern crate proc_macro2; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B{ a: i32, b: i32 }, - /// C{ a: u32 }, - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.variants_mut()[0].filter(|bi| { - /// bi.ast().ident == Some(syn::Ident::new("b", proc_macro2::Span::call_site())) - /// }); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B{ b: ref __binding_1, .. } => { - /// { println!("{:?}", __binding_1) } - /// } - /// A::C{ a: ref __binding_0, } => { - /// { println!("{:?}", __binding_0) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn filter(&mut self, f: F) -> &mut Self - where - F: FnMut(&BindingInfo) -> bool, - { - let before_len = self.bindings.len(); - self.bindings.retain(f); - if self.bindings.len() != before_len { - self.omitted_fields = true; - } - self - } - - /// Remove the binding at the given index. - /// - /// # Panics - /// - /// Panics if the index is out of range. - pub fn remove_binding(&mut self, idx: usize) -> &mut Self { - self.bindings.remove(idx); - self.omitted_fields = true; - self - } - - /// Updates the `BindStyle` for each of the passed-in fields by calling the - /// passed-in function for each `BindingInfo`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.variants_mut()[0].bind_with(|bi| BindStyle::RefMut); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B(ref mut __binding_0, ref mut __binding_1,) => { - /// { println!("{:?}", __binding_0) } - /// { println!("{:?}", __binding_1) } - /// } - /// A::C(ref __binding_0,) => { - /// { println!("{:?}", __binding_0) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn bind_with(&mut self, mut f: F) -> &mut Self - where - F: FnMut(&BindingInfo) -> BindStyle, - { - for binding in &mut self.bindings { - binding.style = f(&binding); - } - self - } - - /// Updates the binding name for each fo the passed-in fields by calling the - /// passed-in function for each `BindingInfo`. - /// - /// The function will be called with the `BindingInfo` and its index in the - /// enclosing variant. - /// - /// The default name is `__binding_{}` where `{}` is replaced with an - /// increasing number. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B{ a: i32, b: i32 }, - /// C{ a: u32 }, - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.variants_mut()[0].binding_name(|bi, i| bi.ident.clone().unwrap()); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B{ a: ref a, b: ref b, } => { - /// { println!("{:?}", a) } - /// { println!("{:?}", b) } - /// } - /// A::C{ a: ref __binding_0, } => { - /// { println!("{:?}", __binding_0) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn binding_name(&mut self, mut f: F) -> &mut Self - where - F: FnMut(&Field, usize) -> Ident, - { - for (it, binding) in self.bindings.iter_mut().enumerate() { - binding.binding = f(binding.field, it); - } - self - } - - /// Returns a list of the type parameters which are referenced in this - /// field's type. - /// - /// # Caveat - /// - /// If the field contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # extern crate proc_macro2; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// struct A { - /// a: Option, - /// b: U, - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// assert_eq!( - /// s.variants()[0].bindings()[0].referenced_ty_params(), - /// &[&(syn::Ident::new("T", proc_macro2::Span::call_site()))] - /// ); - /// # } - /// ``` - pub fn referenced_ty_params(&self) -> Vec<&'a Ident> { - let mut flags = Vec::new(); - for binding in &self.bindings { - generics_fuse(&mut flags, &binding.seen_generics); - } - fetch_generics(&flags, self.generics) - } -} - -/// A wrapper around a `syn::DeriveInput` which provides utilities for creating -/// custom derive trait implementations. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Structure<'a> { - variants: Vec>, - omitted_variants: bool, - ast: &'a DeriveInput, - extra_impl: Vec, - add_bounds: AddBounds, -} - -impl<'a> Structure<'a> { - /// Create a new `Structure` with the variants and fields from the passed-in - /// `DeriveInput`. - pub fn new(ast: &'a DeriveInput) -> Self { - let variants = match ast.data { - Data::Enum(ref data) => { - (&data.variants).into_iter() - .map(|v| { - VariantInfo::new( - VariantAst { - attrs: &v.attrs, - ident: &v.ident, - fields: &v.fields, - discriminant: &v.discriminant - }, - Some(&ast.ident), - &ast.generics, - ) - }) - .collect::>() - } - Data::Struct(ref data) => { - // SAFETY NOTE: Normally putting an `Expr` in static storage - // wouldn't be safe, because it could contain `Term` objects - // which use thread-local interning. However, this static always - // contains the value `None`. Thus, it will never contain any - // unsafe values. - struct UnsafeMakeSync(Option<(token::Eq, Expr)>); - unsafe impl Sync for UnsafeMakeSync {} - static NONE_DISCRIMINANT: UnsafeMakeSync = UnsafeMakeSync(None); - - vec![ - VariantInfo::new( - VariantAst { - attrs: &ast.attrs, - ident: &ast.ident, - fields: &data.fields, - discriminant: &NONE_DISCRIMINANT.0, - }, - None, - &ast.generics, - ), - ] - } - Data::Union(_) => { - panic!("synstructure does not handle untagged unions \ - (https://github.com/mystor/synstructure/issues/6)"); - } - }; - - Structure { - variants: variants, - omitted_variants: false, - ast: ast, - extra_impl: vec![], - add_bounds: AddBounds::Both, - } - } - - /// Returns a slice of the variants in this Structure. - pub fn variants(&self) -> &[VariantInfo<'a>] { - &self.variants - } - - /// Returns a mut slice of the variants in this Structure. - pub fn variants_mut(&mut self) -> &mut [VariantInfo<'a>] { - &mut self.variants - } - - /// Returns a reference to the underlying `syn` AST node which this - /// `Structure` was created from. - pub fn ast(&self) -> &'a DeriveInput { - self.ast - } - - /// True if any variants were omitted due to a `filter_variants` call. - pub fn omitted_variants(&self) -> bool { - self.omitted_variants - } - - /// Runs the passed-in function once for each bound field, passing in a `BindingInfo`. - /// and generating `match` arms which evaluate the returned tokens. - /// - /// This method will ignore variants or fields which are ignored through the - /// `filter` and `filter_variant` methods. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B(ref __binding_0, ref __binding_1,) => { - /// { println!("{:?}", __binding_0) } - /// { println!("{:?}", __binding_1) } - /// } - /// A::C(ref __binding_0,) => { - /// { println!("{:?}", __binding_0) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn each(&self, mut f: F) -> TokenStream - where - F: FnMut(&BindingInfo) -> R, - R: ToTokens, - { - let mut t = TokenStream::new(); - for variant in &self.variants { - variant.each(&mut f).to_tokens(&mut t); - } - if self.omitted_variants { - quote!(_ => {}).to_tokens(&mut t); - } - t - } - - /// Runs the passed-in function once for each bound field, passing in the - /// result of the previous call, and a `BindingInfo`. generating `match` - /// arms which evaluate to the resulting tokens. - /// - /// This method will ignore variants or fields which are ignored through the - /// `filter` and `filter_variant` methods. - /// - /// If a variant has been ignored, it will return the `init` value. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.fold(quote!(0), |acc, bi| quote!(#acc + #bi)).to_string(), - /// - /// quote!{ - /// A::B(ref __binding_0, ref __binding_1,) => { - /// 0 + __binding_0 + __binding_1 - /// } - /// A::C(ref __binding_0,) => { - /// 0 + __binding_0 - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn fold(&self, init: I, mut f: F) -> TokenStream - where - F: FnMut(TokenStream, &BindingInfo) -> R, - I: ToTokens, - R: ToTokens, - { - let mut t = TokenStream::new(); - for variant in &self.variants { - variant.fold(&init, &mut f).to_tokens(&mut t); - } - if self.omitted_variants { - quote!(_ => { #init }).to_tokens(&mut t); - } - t - } - - /// Runs the passed-in function once for each variant, passing in a - /// `VariantInfo`. and generating `match` arms which evaluate the returned - /// tokens. - /// - /// This method will ignore variants and not bind fields which are ignored - /// through the `filter` and `filter_variant` methods. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let s = Structure::new(&di); - /// - /// assert_eq!( - /// s.each_variant(|v| { - /// let name = &v.ast().ident; - /// quote!(println!(stringify!(#name))) - /// }).to_string(), - /// - /// quote!{ - /// A::B(ref __binding_0, ref __binding_1,) => { - /// println!(stringify!(B)) - /// } - /// A::C(ref __binding_0,) => { - /// println!(stringify!(C)) - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn each_variant(&self, mut f: F) -> TokenStream - where - F: FnMut(&VariantInfo) -> R, - R: ToTokens, - { - let mut t = TokenStream::new(); - for variant in &self.variants { - let pat = variant.pat(); - let body = f(variant); - quote!(#pat => { #body }).to_tokens(&mut t); - } - if self.omitted_variants { - quote!(_ => {}).to_tokens(&mut t); - } - t - } - - /// Filter the bindings created by this `Structure` object. This has 2 effects: - /// - /// * The bindings will no longer appear in match arms generated by methods - /// on this `Structure` or its subobjects. - /// - /// * Impl blocks created with the `bound_impl` or `unsafe_bound_impl` - /// method only consider type parameters referenced in the types of - /// non-filtered fields. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # extern crate proc_macro2; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B{ a: i32, b: i32 }, - /// C{ a: u32 }, - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter(|bi| { - /// bi.ast().ident == Some(syn::Ident::new("a", proc_macro2::Span::call_site())) - /// }); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B{ a: ref __binding_0, .. } => { - /// { println!("{:?}", __binding_0) } - /// } - /// A::C{ a: ref __binding_0, } => { - /// { println!("{:?}", __binding_0) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn filter(&mut self, mut f: F) -> &mut Self - where - F: FnMut(&BindingInfo) -> bool, - { - for variant in &mut self.variants { - variant.filter(&mut f); - } - self - } - - /// Specify which bounds should be generated by impl-generating functions - /// such as `gen_impl`, `bound_impl`, and `unsafe_bound_impl`. - /// - /// The default behaviour is to generate both field and generic bounds from - /// type parameters. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// // Limit bounds to only generics. - /// s.add_bounds(AddBounds::Generics); - /// - /// assert_eq!( - /// s.bound_impl(quote!(krate::Trait), quote!{ - /// fn a() {} - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_FOR_A: () = { - /// extern crate krate; - /// impl krate::Trait for A - /// where T: krate::Trait, - /// U: krate::Trait - /// { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn add_bounds(&mut self, mode: AddBounds) -> &mut Self { - self.add_bounds = mode; - self - } - - /// Filter the variants matched by this `Structure` object. This has 2 effects: - /// - /// * Match arms destructuring these variants will no longer be generated by - /// methods on this `Structure` - /// - /// * Impl blocks created with the `bound_impl` or `unsafe_bound_impl` - /// method only consider type parameters referenced in the types of - /// fields in non-fitered variants. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "B"); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::C(ref __binding_0,) => { - /// { println!("{:?}", __binding_0) } - /// } - /// _ => {} - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn filter_variants(&mut self, f: F) -> &mut Self - where - F: FnMut(&VariantInfo) -> bool, - { - let before_len = self.variants.len(); - self.variants.retain(f); - if self.variants.len() != before_len { - self.omitted_variants = true; - } - self - } - - /// Remove the variant at the given index. - /// - /// # Panics - /// - /// Panics if the index is out of range. - pub fn remove_variant(&mut self, idx: usize) -> &mut Self { - self.variants.remove(idx); - self.omitted_variants = true; - self - } - - /// Updates the `BindStyle` for each of the passed-in fields by calling the - /// passed-in function for each `BindingInfo`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(i32, i32), - /// C(u32), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.bind_with(|bi| BindStyle::RefMut); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B(ref mut __binding_0, ref mut __binding_1,) => { - /// { println!("{:?}", __binding_0) } - /// { println!("{:?}", __binding_1) } - /// } - /// A::C(ref mut __binding_0,) => { - /// { println!("{:?}", __binding_0) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn bind_with(&mut self, mut f: F) -> &mut Self - where - F: FnMut(&BindingInfo) -> BindStyle, - { - for variant in &mut self.variants { - variant.bind_with(&mut f); - } - self - } - - /// Updates the binding name for each fo the passed-in fields by calling the - /// passed-in function for each `BindingInfo`. - /// - /// The function will be called with the `BindingInfo` and its index in the - /// enclosing variant. - /// - /// The default name is `__binding_{}` where `{}` is replaced with an - /// increasing number. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B{ a: i32, b: i32 }, - /// C{ a: u32 }, - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.binding_name(|bi, i| bi.ident.clone().unwrap()); - /// - /// assert_eq!( - /// s.each(|bi| quote!(println!("{:?}", #bi))).to_string(), - /// - /// quote!{ - /// A::B{ a: ref a, b: ref b, } => { - /// { println!("{:?}", a) } - /// { println!("{:?}", b) } - /// } - /// A::C{ a: ref a, } => { - /// { println!("{:?}", a) } - /// } - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn binding_name(&mut self, mut f: F) -> &mut Self - where - F: FnMut(&Field, usize) -> Ident, - { - for variant in &mut self.variants { - variant.binding_name(&mut f); - } - self - } - - /// Returns a list of the type parameters which are refrenced in the types - /// of non-filtered fields / variants. - /// - /// # Caveat - /// - /// If the struct contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # extern crate proc_macro2; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T, i32), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "C"); - /// - /// assert_eq!( - /// s.referenced_ty_params(), - /// &[&(syn::Ident::new("T", proc_macro2::Span::call_site()))] - /// ); - /// # } - /// ``` - pub fn referenced_ty_params(&self) -> Vec<&'a Ident> { - let mut flags = Vec::new(); - for variant in &self.variants { - for binding in &variant.bindings { - generics_fuse(&mut flags, &binding.seen_generics); - } - } - fetch_generics(&flags, &self.ast.generics) - } - - /// Adds an `impl<>` generic parameter. - /// This can be used when the trait to be derived needs some extra generic parameters. - /// - /// # Example - /// ``` - /// # #![recursion_limit="128"] - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// let generic: syn::GenericParam = parse_quote!(X: krate::AnotherTrait); - /// - /// assert_eq!( - /// s.add_impl_generic(generic) - /// .bound_impl(quote!(krate::Trait), - /// quote!{ - /// fn a() {} - /// } - /// ).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_X_FOR_A: () = { - /// extern crate krate; - /// impl krate::Trait for A - /// where T : krate :: Trait < X >, - /// Option: krate::Trait, - /// U: krate::Trait - /// { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn add_impl_generic(&mut self, param: GenericParam) -> &mut Self { - self.extra_impl.push(param); - self - } - - /// Add trait bounds for a trait with the given path for each type parmaeter - /// referenced in the types of non-filtered fields. - /// - /// # Caveat - /// - /// If the method contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - pub fn add_trait_bounds( - &self, - bound: &TraitBound, - where_clause: &mut Option, - mode: AddBounds, - ) { - let mut seen = HashSet::new(); - let mut pred = |ty: Type| if !seen.contains(&ty) { - seen.insert(ty.clone()); - - // Ensure we have a where clause, because we need to use it. We - // can't use `get_or_insert_with`, because it isn't supported on all - // rustc versions we support (this is a Rust 1.20+ feature). - if where_clause.is_none() { - *where_clause = Some(WhereClause { - where_token: Default::default(), - predicates: punctuated::Punctuated::new(), - }); - } - let clause = where_clause.as_mut().unwrap(); - - // Add a predicate. - clause.predicates.push(WherePredicate::Type(PredicateType { - lifetimes: None, - bounded_ty: ty, - colon_token: Default::default(), - bounds: Some(punctuated::Pair::End(TypeParamBound::Trait(bound.clone()))) - .into_iter() - .collect(), - })); - }; - - for variant in &self.variants { - for binding in &variant.bindings { - match mode { - AddBounds::Both | AddBounds::Fields => { - for &seen in &binding.seen_generics { - if seen { - pred(binding.ast().ty.clone()); - break; - } - } - } - _ => {} - } - - match mode { - AddBounds::Both | AddBounds::Generics => { - for param in binding.referenced_ty_params() { - pred(Type::Path(TypePath { - qself: None, - path: (*param).clone().into(), - })); - } - } - _ => {} - } - } - } - } - - /// > NOTE: This methods' features are superceded by `Structure::gen_impl`. - /// - /// Creates an `impl` block with the required generic type fields filled in - /// to implement the trait `path`. - /// - /// This method also adds where clauses to the impl requiring that all - /// referenced type parmaeters implement the trait `path`. - /// - /// # Hygiene and Paths - /// - /// This method wraps the impl block inside of a `const` (see the example - /// below). In this scope, the first segment of the passed-in path is - /// `extern crate`-ed in. If you don't want to generate that `extern crate` - /// item, use a global path. - /// - /// This means that if you are implementing `my_crate::Trait`, you simply - /// write `s.bound_impl(quote!(my_crate::Trait), quote!(...))`, and for the - /// entirety of the definition, you can refer to your crate as `my_crate`. - /// - /// # Caveat - /// - /// If the method contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - /// - /// # Panics - /// - /// Panics if the path string parameter is not a valid `TraitBound`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "B"); - /// - /// assert_eq!( - /// s.bound_impl(quote!(krate::Trait), quote!{ - /// fn a() {} - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_FOR_A: () = { - /// extern crate krate; - /// impl krate::Trait for A - /// where Option: krate::Trait, - /// U: krate::Trait - /// { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn bound_impl(&self, path: P, body: B) -> TokenStream { - self.impl_internal( - path.into_token_stream(), - body.into_token_stream(), - quote!(), - None, - ) - } - - /// > NOTE: This methods' features are superceded by `Structure::gen_impl`. - /// - /// Creates an `impl` block with the required generic type fields filled in - /// to implement the unsafe trait `path`. - /// - /// This method also adds where clauses to the impl requiring that all - /// referenced type parmaeters implement the trait `path`. - /// - /// # Hygiene and Paths - /// - /// This method wraps the impl block inside of a `const` (see the example - /// below). In this scope, the first segment of the passed-in path is - /// `extern crate`-ed in. If you don't want to generate that `extern crate` - /// item, use a global path. - /// - /// This means that if you are implementing `my_crate::Trait`, you simply - /// write `s.bound_impl(quote!(my_crate::Trait), quote!(...))`, and for the - /// entirety of the definition, you can refer to your crate as `my_crate`. - /// - /// # Caveat - /// - /// If the method contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - /// - /// # Panics - /// - /// Panics if the path string parameter is not a valid `TraitBound`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "B"); - /// - /// assert_eq!( - /// s.unsafe_bound_impl(quote!(krate::Trait), quote!{ - /// fn a() {} - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_FOR_A: () = { - /// extern crate krate; - /// unsafe impl krate::Trait for A - /// where Option: krate::Trait, - /// U: krate::Trait - /// { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn unsafe_bound_impl(&self, path: P, body: B) -> TokenStream { - self.impl_internal( - path.into_token_stream(), - body.into_token_stream(), - quote!(unsafe), - None, - ) - } - - /// > NOTE: This methods' features are superceded by `Structure::gen_impl`. - /// - /// Creates an `impl` block with the required generic type fields filled in - /// to implement the trait `path`. - /// - /// This method will not add any where clauses to the impl. - /// - /// # Hygiene and Paths - /// - /// This method wraps the impl block inside of a `const` (see the example - /// below). In this scope, the first segment of the passed-in path is - /// `extern crate`-ed in. If you don't want to generate that `extern crate` - /// item, use a global path. - /// - /// This means that if you are implementing `my_crate::Trait`, you simply - /// write `s.bound_impl(quote!(my_crate::Trait), quote!(...))`, and for the - /// entirety of the definition, you can refer to your crate as `my_crate`. - /// - /// # Panics - /// - /// Panics if the path string parameter is not a valid `TraitBound`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "B"); - /// - /// assert_eq!( - /// s.unbound_impl(quote!(krate::Trait), quote!{ - /// fn a() {} - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_FOR_A: () = { - /// extern crate krate; - /// impl krate::Trait for A { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - pub fn unbound_impl(&self, path: P, body: B) -> TokenStream { - self.impl_internal( - path.into_token_stream(), - body.into_token_stream(), - quote!(), - Some(AddBounds::None), - ) - } - - /// > NOTE: This methods' features are superceded by `Structure::gen_impl`. - /// - /// Creates an `impl` block with the required generic type fields filled in - /// to implement the unsafe trait `path`. - /// - /// This method will not add any where clauses to the impl. - /// - /// # Hygiene and Paths - /// - /// This method wraps the impl block inside of a `const` (see the example - /// below). In this scope, the first segment of the passed-in path is - /// `extern crate`-ed in. If you don't want to generate that `extern crate` - /// item, use a global path. - /// - /// This means that if you are implementing `my_crate::Trait`, you simply - /// write `s.bound_impl(quote!(my_crate::Trait), quote!(...))`, and for the - /// entirety of the definition, you can refer to your crate as `my_crate`. - /// - /// # Panics - /// - /// Panics if the path string parameter is not a valid `TraitBound`. - /// - /// # Example - /// ``` - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "B"); - /// - /// assert_eq!( - /// s.unsafe_unbound_impl(quote!(krate::Trait), quote!{ - /// fn a() {} - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_FOR_A: () = { - /// extern crate krate; - /// unsafe impl krate::Trait for A { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - #[deprecated] - pub fn unsafe_unbound_impl(&self, path: P, body: B) -> TokenStream { - self.impl_internal( - path.into_token_stream(), - body.into_token_stream(), - quote!(unsafe), - Some(AddBounds::None), - ) - } - - fn impl_internal( - &self, - path: TokenStream, - body: TokenStream, - safety: TokenStream, - mode: Option, - ) -> TokenStream { - let mode = mode.unwrap_or(self.add_bounds); - let name = &self.ast.ident; - let mut gen_clone = self.ast.generics.clone(); - gen_clone.params.extend(self.extra_impl.clone().into_iter()); - let (impl_generics, _, _) = gen_clone.split_for_impl(); - let (_, ty_generics, where_clause) = self.ast.generics.split_for_impl(); - - let bound = syn::parse2::(path.into()) - .expect("`path` argument must be a valid rust trait bound"); - - let mut where_clause = where_clause.cloned(); - self.add_trait_bounds(&bound, &mut where_clause, mode); - - let dummy_const: Ident = sanitize_ident(&format!( - "_DERIVE_{}_FOR_{}", - (&bound).into_token_stream(), - name.into_token_stream(), - )); - - // This function is smart. If a global path is passed, no extern crate - // statement will be generated, however, a relative path will cause the - // crate which it is relative to to be imported within the current - // scope. - let mut extern_crate = quote!(); - if bound.path.leading_colon.is_none() { - if let Some(ref seg) = bound.path.segments.first() { - let seg = seg.value(); - extern_crate = quote! { extern crate #seg; }; - } - } - - quote! { - #[allow(non_upper_case_globals)] - const #dummy_const: () = { - #extern_crate - #safety impl #impl_generics #bound for #name #ty_generics #where_clause { - #body - } - }; - } - } - - /// Generate an impl block for the given struct. This impl block will - /// automatically use hygiene tricks to avoid polluting the caller's - /// namespace, and will automatically add trait bounds for generic type - /// parameters. - /// - /// # Syntax - /// - /// This function accepts its arguments as a `TokenStream`. The recommended way - /// to call this function is passing the result of invoking the `quote!` - /// macro to it. - /// - /// ```ignore - /// s.gen_impl(quote! { - /// // You can write any items which you want to import into scope here. - /// // For example, you may want to include an `extern crate` for the - /// // crate which implements your trait. These items will only be - /// // visible to the code you generate, and won't be exposed to the - /// // consuming crate - /// extern crate krate; - /// - /// // You can also add `use` statements here to bring types or traits - /// // into scope. - /// // - /// // WARNING: Try not to use common names here, because the stable - /// // version of syn does not support hygiene and you could accidentally - /// // shadow types from the caller crate. - /// use krate::Trait as MyTrait; - /// - /// // The actual impl block is a `gen impl` or `gen unsafe impl` block. - /// // You can use `@Self` to refer to the structure's type. - /// gen impl MyTrait for @Self { - /// fn f(&self) { ... } - /// } - /// }) - /// ``` - /// - /// The most common usage of this trait involves loading the crate the - /// target trait comes from with `extern crate`, and then invoking a `gen - /// impl` block. - /// - /// # Hygiene - /// - /// This method tries to handle hygiene intelligenly for both stable and - /// unstable proc-macro implementations, however there are visible - /// differences. - /// - /// The output of every `gen_impl` function is wrapped in a dummy `const` - /// value, to ensure that it is given its own scope, and any values brought - /// into scope are not leaked to the calling crate. For example, the above - /// invocation may generate an output like the following: - /// - /// ```ignore - /// const _DERIVE_krate_Trait_FOR_Struct: () = { - /// extern crate krate; - /// use krate::Trait as MyTrait; - /// impl MyTrait for Struct where T: MyTrait { - /// fn f(&self) { ... } - /// } - /// }; - /// ``` - /// - /// ### Using the `std` crate - /// - /// If you are using `quote!()` to implement your trait, with the - /// `proc-macro2/nightly` feature, `std` isn't considered to be in scope for - /// your macro. This means that if you use types from `std` in your - /// procedural macro, you'll want to explicitly load it with an `extern - /// crate std;`. - /// - /// ### Absolute paths - /// - /// You should generally avoid using absolute paths in your generated code, - /// as they will resolve very differently when using the stable and nightly - /// versions of `proc-macro2`. Instead, load the crates you need to use - /// explictly with `extern crate` and - /// - /// # Trait Bounds - /// - /// This method will automatically add trait bounds for any type parameters - /// which are referenced within the types of non-ignored fields. - /// - /// Additional type parameters may be added with the generics syntax after - /// the `impl` keyword. - /// - /// ### Type Macro Caveat - /// - /// If the method contains any macros in type position, all parameters will - /// be considered bound. This is because we cannot determine which type - /// parameters are bound by type macros. - /// - /// # Panics - /// - /// This function will panic if the input `TokenStream` is not well-formed, or - /// if additional type parameters added by `impl<..>` conflict with generic - /// type parameters on the original struct. - /// - /// # Example Usage - /// - /// ``` - /// # #![recursion_limit="128"] - /// # #[macro_use] extern crate quote; - /// # extern crate synstructure; - /// # #[macro_use] extern crate syn; - /// # use synstructure::*; - /// # fn main() { - /// let di: syn::DeriveInput = parse_quote! { - /// enum A { - /// B(T), - /// C(Option), - /// } - /// }; - /// let mut s = Structure::new(&di); - /// - /// s.filter_variants(|v| v.ast().ident != "B"); - /// - /// assert_eq!( - /// s.gen_impl(quote! { - /// extern crate krate; - /// gen impl krate::Trait for @Self { - /// fn a() {} - /// } - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_FOR_A: () = { - /// extern crate krate; - /// impl krate::Trait for A - /// where - /// Option: krate::Trait, - /// U: krate::Trait - /// { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// - /// // NOTE: You can also add extra generics after the impl - /// assert_eq!( - /// s.gen_impl(quote! { - /// extern crate krate; - /// gen impl krate::Trait for @Self - /// where - /// X: Send + Sync, - /// { - /// fn a() {} - /// } - /// }).to_string(), - /// quote!{ - /// #[allow(non_upper_case_globals)] - /// const _DERIVE_krate_Trait_X_FOR_A: () = { - /// extern crate krate; - /// impl krate::Trait for A - /// where - /// X: Send + Sync, - /// Option: krate::Trait, - /// U: krate::Trait - /// { - /// fn a() {} - /// } - /// }; - /// }.to_string() - /// ); - /// # } - /// ``` - /// - /// Use `add_bounds` to change which bounds are generated. - pub fn gen_impl(&self, cfg: TokenStream) -> TokenStream { - use syn::parse::{Parser, ParseStream, Result}; - - // Syn requires parsers to be methods conforming to a strict signature - let do_parse = |input: ParseStream| -> Result { - // Helper lambda to parse the prefix of a gen block. - let parse_prefix = |input: ParseStream| -> Result<_> { - if input.parse::()? != "gen" { - return Err(input.error("")); - } - let safety = input.parse::>()?; - let _ = input.parse::()?; - Ok(safety) - }; - - let mut before = vec![]; - loop { - if let Ok(_) = parse_prefix(&input.fork()) { - break; - } - before.push(input.parse::()?); - } - - // Parse the prefix "for real" - let safety = parse_prefix(input)?; - - // optional `<>` - let mut generics = input.parse::()?; - - // @bound - let bound = input.parse::()?; - - // `for @Self` - let _ = input.parse::()?; - let _ = input.parse::()?; - let _ = input.parse::()?; - - // optional `where ...` - generics.where_clause = input.parse()?; - - // Body of the impl - let body; - braced!(body in input); - let body = body.parse::()?; - - // Tokens following impl - let after = input.parse::()?; - - /* Codegen Logic */ - let name = &self.ast.ident; - - // Add the generics from the original struct in, and then add any - // additional trait bounds which we need on the type. - merge_generics(&mut generics, &self.ast.generics); - self.add_trait_bounds(&bound, &mut generics.where_clause, self.add_bounds); - let (impl_generics, _, where_clause) = generics.split_for_impl(); - let (_, ty_generics, _) = self.ast.generics.split_for_impl(); - - let dummy_const: Ident = sanitize_ident(&format!( - "_DERIVE_{}_FOR_{}", - (&bound).into_token_stream(), - name.into_token_stream(), - )); - - Ok(quote! { - #[allow(non_upper_case_globals)] - const #dummy_const: () = { - #(#before)* - #safety impl #impl_generics #bound for #name #ty_generics #where_clause { - #body - } - #after - }; - }) - }; - Parser::parse2(do_parse, cfg).expect("Failed to parse gen_impl") - } -} - -/// Dumps an unpretty version of a tokenstream. Takes any type which implements -/// `Display`. -/// -/// This is mostly useful for visualizing the output of a procedural macro, as -/// it makes it marginally more readable. It is used in the implementation of -/// `test_derive!` to unprettily print the output. -/// -/// # Stability -/// -/// The stability of the output of this function is not guaranteed. Do not -/// assert that the output of this function does not change between minor -/// versions. -/// -/// # Example -/// -/// ``` -/// # extern crate synstructure; -/// # #[macro_use] extern crate quote; -/// # fn main() { -/// assert_eq!( -/// synstructure::unpretty_print(quote! { -/// #[allow(non_upper_case_globals)] -/// const _DERIVE_krate_Trait_FOR_A: () = { -/// extern crate krate; -/// impl krate::Trait for A -/// where -/// Option: krate::Trait, -/// U: krate::Trait -/// { -/// fn a() {} -/// } -/// }; -/// }), -/// "# [ -/// allow ( -/// non_upper_case_globals ) -/// ] -/// const _DERIVE_krate_Trait_FOR_A : ( -/// ) -/// = { -/// extern crate krate ; -/// impl < T , U > krate :: Trait for A < T , U > where Option < U > : krate :: Trait , U : krate :: Trait { -/// fn a ( -/// ) -/// { -/// } -/// } -/// } -/// ; -/// " -/// ) -/// # } -/// ``` -pub fn unpretty_print(ts: T) -> String { - let mut res = String::new(); - - let raw_s = ts.to_string(); - let mut s = &raw_s[..]; - let mut indent = 0; - while let Some(i) = s.find(&['(', '{', '[', ')', '}', ']', ';'][..]) { - match &s[i..i + 1] { - "(" | "{" | "[" => indent += 1, - ")" | "}" | "]" => indent -= 1, - _ => {} - } - res.push_str(&s[..i + 1]); - res.push('\n'); - for _ in 0..indent { - res.push_str(" "); - } - s = s[i + 1..].trim_left_matches(' '); - } - res.push_str(s); - res -} diff --git a/third_party/rust/synstructure-0.10.1/src/macros.rs b/third_party/rust/synstructure-0.10.1/src/macros.rs deleted file mode 100644 index 6661ee745d86..000000000000 --- a/third_party/rust/synstructure-0.10.1/src/macros.rs +++ /dev/null @@ -1,415 +0,0 @@ -//! This module provides two utility macros for testing custom derives. They can -//! be used together to eliminate some of the boilerplate required in order to -//! declare and test custom derive implementations. - -// Re-exports used by the decl_derive! and test_derive! -pub use syn::{parse_str, parse, DeriveInput}; -pub use proc_macro::TokenStream as TokenStream; -pub use proc_macro2::TokenStream as TokenStream2; - -/// The `decl_derive!` macro declares a custom derive wrapper. It will parse the -/// incoming `TokenStream` into a `synstructure::Structure` object, and pass it -/// into the inner function. -/// -/// Your inner function should have the following type: -/// -/// ``` -/// # extern crate quote; -/// # extern crate proc_macro2; -/// # extern crate synstructure; -/// fn derive(input: synstructure::Structure) -> proc_macro2::TokenStream { -/// unimplemented!() -/// } -/// ``` -/// -/// # Usage -/// -/// ### Without Attributes -/// ``` -/// # #[macro_use] extern crate quote; -/// # extern crate proc_macro2; -/// # extern crate synstructure; -/// # fn main() {} -/// fn derive_interesting(_input: synstructure::Structure) -> proc_macro2::TokenStream { -/// quote! { ... } -/// } -/// -/// # const _IGNORE: &'static str = stringify! { -/// decl_derive!([Interesting] => derive_interesting); -/// # }; -/// ``` -/// -/// ### With Attributes -/// ``` -/// # #[macro_use] extern crate quote; -/// # extern crate proc_macro2; -/// # extern crate synstructure; -/// # fn main() {} -/// fn derive_interesting(_input: synstructure::Structure) -> proc_macro2::TokenStream { -/// quote! { ... } -/// } -/// -/// # const _IGNORE: &'static str = stringify! { -/// decl_derive!([Interesting, attributes(interesting_ignore)] => derive_interesting); -/// # }; -/// ``` -#[macro_export] -macro_rules! decl_derive { - // XXX: Switch to using this variant everywhere? - ([$derives:ident $($derive_t:tt)*] => $inner:path) => { - #[proc_macro_derive($derives $($derive_t)*)] - #[allow(non_snake_case)] - pub fn $derives( - i: $crate::macros::TokenStream - ) -> $crate::macros::TokenStream - { - let parsed = $crate::macros::parse::<$crate::macros::DeriveInput>(i) - .expect(concat!("Failed to parse input to `#[derive(", - stringify!($derives), - ")]`")); - $inner($crate::Structure::new(&parsed)).into() - } - }; -} - -/// Run a test on a custom derive. This macro expands both the original struct -/// and the expansion to ensure that they compile correctly, and confirms that -/// feeding the original struct into the named derive will produce the written -/// output. -/// -/// You can add `no_build` to the end of the macro invocation to disable -/// checking that the written code compiles. This is useful in contexts where -/// the procedural macro cannot depend on the crate where it is used during -/// tests. -/// -/// # Usage -/// -/// ``` -/// # #[macro_use] extern crate quote; -/// # extern crate proc_macro2; -/// # #[macro_use] extern crate synstructure; -/// fn test_derive_example(_s: synstructure::Structure) -> proc_macro2::TokenStream { -/// quote! { const YOUR_OUTPUT: &'static str = "here"; } -/// } -/// -/// fn main() { -/// test_derive!{ -/// test_derive_example { -/// struct A; -/// } -/// expands to { -/// const YOUR_OUTPUT: &'static str = "here"; -/// } -/// } -/// } -/// ``` -#[macro_export] -macro_rules! test_derive { - ($name:path { $($i:tt)* } expands to { $($o:tt)* }) => { - { - #[allow(dead_code)] - fn ensure_compiles() { - $($i)* - $($o)* - } - - test_derive!($name { $($i)* } expands to { $($o)* } no_build); - } - }; - - ($name:path { $($i:tt)* } expands to { $($o:tt)* } no_build) => { - { - let i = stringify!( $($i)* ); - let parsed = $crate::macros::parse_str::<$crate::macros::DeriveInput>(i) - .expect(concat!("Failed to parse input to `#[derive(", - stringify!($name), - ")]`")); - - let res = $name($crate::Structure::new(&parsed)); - let expected = stringify!( $($o)* ) - .parse::<$crate::macros::TokenStream2>() - .expect("output should be a valid TokenStream"); - let mut expected_toks = $crate::macros::TokenStream2::from(expected); - if res.to_string() != expected_toks.to_string() { - panic!("\ -test_derive failed: -expected: -``` -{} -``` - -got: -``` -{} -```\n", - $crate::unpretty_print(&expected_toks), - $crate::unpretty_print(&res), - ); - } - // assert_eq!(res, expected_toks) - } - }; -} - -/// A helper macro for declaring relatively straightforward derive -/// implementations. It provides mechanisms for operating over structures -/// performing modifications on each field etc. -/// -/// This macro doesn't define the actual derive, but rather the implementation -/// method. Use `decl_derive!` to generate the implementation wrapper. -/// -/// # Stability Warning -/// -/// This is an unstable experimental macro API, which may be changed or removed -/// in a future version. I'm not yet confident enough that this API is useful -/// enough to warrant its complexity and inclusion in `synstructure`. -/// -/// # Caveat -/// -/// The `quote!` macro from `quote` must be imported in the calling crate, as -/// this macro depends on it. -/// -/// # Note -/// -/// This feature is implemented behind the `simple-derive` feature, and is only -/// available when that feature is enabled. -/// -/// # Example -/// -/// ``` -/// extern crate syn; -/// #[macro_use] -/// extern crate quote; -/// #[macro_use] -/// extern crate synstructure; -/// extern crate proc_macro2; -/// # const _IGNORE: &'static str = stringify! { -/// decl_derive!([Interest] => derive_interest); -/// # }; -/// -/// simple_derive! { -/// // This macro implements the `Interesting` method exported by the `aa` -/// // crate. It will explicitly add an `extern crate` invocation to import the -/// // crate into the expanded context. -/// derive_interest impl synstructure_test_traits::Interest { -/// // A "filter" block can be added. It evaluates its body with the (s) -/// // variable bound to a mutable reference to the input `Structure` -/// // object. -/// // -/// // This block can be used to perform general transformations, such as -/// // filtering out fields which should be ignored by all methods and for -/// // the purposes of binding type parameters. -/// filter(s) { -/// s.filter(|bi| bi.ast().ident != Some(syn::Ident::new("a", -/// proc_macro2::Span::call_site()))); -/// } -/// -/// // This is an implementation of a method in the implemented crate. The -/// // return value should be the series of match patterns to destructure -/// // the `self` argument with. -/// fn interesting(&self as s) -> bool { -/// s.fold(false, |acc, bi| { -/// quote!(#acc || synstructure_test_traits::Interest::interesting(#bi)) -/// }) -/// } -/// } -/// } -/// -/// fn main() { -/// test_derive!{ -/// derive_interest { -/// struct A { -/// x: i32, -/// a: bool, // Will be ignored by filter -/// c: T, -/// } -/// } -/// expands to { -/// #[allow(non_upper_case_globals)] -/// const _DERIVE_synstructure_test_traits_Interest_FOR_A: () = { -/// extern crate synstructure_test_traits; -/// impl synstructure_test_traits::Interest for A -/// where T: synstructure_test_traits::Interest -/// { -/// fn interesting(&self) -> bool { -/// match *self { -/// A { -/// x: ref __binding_0, -/// c: ref __binding_2, -/// .. -/// } => { -/// false || -/// synstructure_test_traits::Interest::interesting(__binding_0) || -/// synstructure_test_traits::Interest::interesting(__binding_2) -/// } -/// } -/// } -/// } -/// }; -/// } -/// } -/// } -/// ``` -#[cfg(feature = "simple-derive")] -#[macro_export] -macro_rules! simple_derive { - // entry point - ( - $iname:ident impl $path:path { $($rest:tt)* } - ) => { - simple_derive!(__I [$iname, $path] { $($rest)* } [] []); - }; - - // Adding a filter block - ( - __I $opt:tt { - filter($s:ident) { - $($body:tt)* - } - $($rest:tt)* - } [$($done:tt)*] [$($filter:tt)*] - ) => { - simple_derive!( - __I $opt { $($rest)* } [$($done)*] [ - $($filter)* - [ - st_name = $s, - body = { - $($body)* - }, - ] - ] - ); - }; - - // &self bound method - ( - __I $opt:tt { - fn $fn_name:ident (&self as $s:ident $($params:tt)*) $(-> $t:ty)* { - $($body:tt)* - } - $($rest:tt)* - } [$($done:tt)*] [$($filter:tt)*] - ) => { - simple_derive!( - __I $opt { $($rest)* } [ - $($done)* - [ - st_name = $s, - bind_style = Ref, - body = { $($body)* }, - result = result, - expanded = { - fn $fn_name(&self $($params)*) $(-> $t)* { - match *self { #result } - } - }, - ] - ] [$($filter)*] - ); - }; - - // &mut self bound method - ( - __I $opt:tt { - fn $fn_name:ident (&mut self as $s:ident $($params:tt)*) $(-> $t:ty)* { - $($body:tt)* - } - $($rest:tt)* - } [$($done:tt)*] [$($filter:tt)*] - ) => { - simple_derive!( - __I $opt { $($rest)* } [ - $($done)* - [ - st_name = $s, - bind_style = RefMut, - body = { $($body)* }, - result = result, - expanded = { - fn $fn_name(&mut self $($params)*) $(-> $t)* { - match *self { #result } - } - }, - ] - ] [$($filter)*] - ); - }; - - // self bound method - ( - __I $opt:tt { - fn $fn_name:ident (self as $s:ident $($params:tt)*) $(-> $t:ty)* { - $($body:tt)* - } - $($rest:tt)* - } [$($done:tt)*] [$($filter:tt)*] - ) => { - simple_derive!( - __I $opt { $($rest)* } [ - $($done)* - [ - st_name = $s, - bind_style = Move, - body = { $($body)* }, - result = result, - expanded = { - fn $fn_name(self $($params)*) $(-> $t)* { - match self { #result } - } - }, - ] - ] [$($filter)*] - ); - }; - - // XXX: Static methods? - - // codegen after data collection - ( - __I [$iname:ident, $path:path] {} [$( - [ - st_name = $st_name:ident, - bind_style = $bind_style:ident, - body = $body:tt, - result = $result:ident, - expanded = { $($expanded:tt)* }, - ] - )*] [$( - [ - st_name = $filter_st_name:ident, - body = $filter_body:tt, - ] - )*] - ) => { - fn $iname(mut st: $crate::Structure) -> $crate::macros::TokenStream2 { - let _ = &mut st; // Silence the unused mut warning - - // Filter/transform the `Structure` object before cloning it for - // individual methods. - $( - { - let $filter_st_name = &mut st; - $filter_body - } - )* - - // Clone the `Structure` object and set the correct binding style, - // then perform method specific expansion. - $( - let $result = { - let mut $st_name = st.clone(); - $st_name.bind_with(|_| ::synstructure::BindStyle::$bind_style); - let $result = { - $body - }; - quote!{ $($expanded)* } - }; - )* - - st.bound_impl(quote!($path), quote!{ - $(#$result)* - }) - } - } -}