From 5066e27c5a54d6d01c57f42e96353c268af247d2 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Tue, 11 Jul 2023 13:46:08 -0700 Subject: [PATCH] update to syn 2 and release (#452) * upgrade syn to v2 * bump version * changelog * cargo update --- Cargo.lock | 205 +++++++++++++++++-------------- Changelog.md | 21 +++- README.md | 2 + rust/candid/Cargo.toml | 5 +- rust/candid_derive/Cargo.toml | 4 +- rust/candid_derive/src/derive.rs | 39 +++--- rust/candid_derive/src/func.rs | 20 ++- rust/candid_derive/src/lib.rs | 16 ++- 8 files changed, 184 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49476793..001aeee7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,6 +33,15 @@ dependencies = [ "pretty 0.11.3", ] +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + [[package]] name = "anes" version = "0.1.6" @@ -174,7 +183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" dependencies = [ "either", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", "syn 1.0.109", ] @@ -232,7 +241,7 @@ checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -249,7 +258,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "candid" -version = "0.9.0" +version = "0.9.1" dependencies = [ "anyhow", "arbitrary", @@ -289,12 +298,12 @@ dependencies = [ [[package]] name = "candid_derive" -version = "0.6.1" +version = "0.6.2" dependencies = [ "lazy_static", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 1.0.109", + "syn 2.0.25", ] [[package]] @@ -356,9 +365,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.10" +version = "4.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384e169cc618c613d5e3ca6404dda77a8685a63e08660dcc64abaf7da7cb0c7a" +checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" dependencies = [ "clap_builder", "clap_derive", @@ -367,9 +376,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.10" +version = "4.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef137bbe35aab78bdb468ccfba75a5f4d8321ae011d34063770780545176af2d" +checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" dependencies = [ "anstream", "anstyle", @@ -384,9 +393,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" dependencies = [ "heck", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -434,9 +443,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -582,7 +591,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df7c81d16870879ef530b07cef32bc6088f98937ab4168106cc8e382a05146bf" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", "syn 1.0.109", ] @@ -593,7 +602,7 @@ version = "0.3.2" dependencies = [ "anyhow", "candid", - "clap 4.3.10", + "clap 4.3.11", "hex", "pretty-hex", "rand", @@ -683,9 +692,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "equivalent" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" @@ -820,9 +829,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -890,19 +899,19 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "windows-sys 0.48.0", ] [[package]] name = "is-terminal" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.1", - "rustix 0.38.1", + "hermit-abi 0.3.2", + "rustix 0.38.4", "windows-sys 0.48.0", ] @@ -926,9 +935,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" [[package]] name = "js-sys" @@ -955,7 +964,7 @@ dependencies = [ "petgraph", "pico-args", "regex", - "regex-syntax 0.7.2", + "regex-syntax 0.7.4", "string_cache", "term", "tiny-keccak", @@ -1034,10 +1043,10 @@ checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" dependencies = [ "beef", "fnv", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", "regex-syntax 0.6.29", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1123,7 +1132,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", ] @@ -1143,9 +1152,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1197,9 +1206,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "b4b27ab7be369122c218afc2079489cdcb4b517c0a3fc386ff11e1fedfcc2b35" [[package]] name = "percent-encoding" @@ -1234,7 +1243,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d8630a7a899cb344ec1c16ba0a6b24240029af34bdc0a21f84e411d7f793f29" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", "syn 1.0.109", ] @@ -1257,9 +1266,9 @@ checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" dependencies = [ "pest", "pest_meta", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1388,9 +1397,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -1419,7 +1428,7 @@ version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", ] [[package]] @@ -1505,11 +1514,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ - "regex-syntax 0.7.2", + "aho-corasick", + "memchr", + "regex-automata 0.3.2", + "regex-syntax 0.7.4", ] [[package]] @@ -1518,6 +1530,17 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +[[package]] +name = "regex-automata" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.4", +] + [[package]] name = "regex-syntax" version = "0.6.29" @@ -1526,15 +1549,15 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "rustix" -version = "0.37.21" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25693a73057a1b4cb56179dd3c7ea21a7c6c5ee7d85781f5749b46f34b79c" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ "bitflags 1.3.2", "errno", @@ -1546,9 +1569,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.1" +version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc6396159432b5c8490d4e301d8c705f61860b8b6c863bf79942ce5401968f3" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" dependencies = [ "bitflags 2.3.3", "errno", @@ -1559,15 +1582,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "dc31bd9b61a32c31f9650d18add92aa83a49ba979c143eefd27fe7177b05bd5f" [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" [[package]] name = "same-file" @@ -1586,18 +1609,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.164" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.9" +version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "5a16be4fe5320ade08736447e3198294a5ea9a6d44dde6f35f0a5e06859c427a" dependencies = [ "serde", ] @@ -1614,13 +1637,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1638,9 +1661,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" dependencies = [ "itoa", "ryu", @@ -1649,9 +1672,9 @@ dependencies = [ [[package]] name = "serde_test" -version = "1.0.164" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797c38160e2546a56e1e3439496439597e938669673ffd8af02a12f070da648f" +checksum = "b6480a2f4e1449ec9757ea143362ad5cea79bc7f1cb7711c06e1c5d03b6b5a3a" dependencies = [ "serde", ] @@ -1708,9 +1731,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "stable_deref_trait" @@ -1767,18 +1790,18 @@ version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.22" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", "unicode-ident", ] @@ -1793,7 +1816,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.21", + "rustix 0.37.23", "windows-sys 0.48.0", ] @@ -1837,22 +1860,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1897,9 +1920,9 @@ checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.19.11" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" +checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78" dependencies = [ "indexmap 2.0.0", "toml_datetime", @@ -1920,9 +1943,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ucd-trie" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicode-bidi" @@ -1932,9 +1955,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" [[package]] name = "unicode-normalization" @@ -2033,9 +2056,9 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", "wasm-bindgen-shared", ] @@ -2055,9 +2078,9 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ - "proc-macro2 1.0.63", + "proc-macro2 1.0.64", "quote 1.0.29", - "syn 2.0.22", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2243,9 +2266,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529" dependencies = [ "memchr", ] diff --git a/Changelog.md b/Changelog.md index c722718e..0284b185 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,26 @@ # Changelog -## 2022-06-30 (Rust 0.9.0) +## 2023-07-11 + +### Rust (0.9.1) + +* `utils::service_equal` to check if two service are structurally equal under variable renaming. +* `utils::instantiate_candid` to generate metadata from did file: separate init args, flatten imports. For now, comments in the original did file is not preserved. +* `impl From` trait for `define_function/define_service` macros. +* Make `bindings::candid::pp_args` a public method. +* Bump dependencies, notably `pretty`, `logos` and `syn`. + +### Candid UI + +* Bump agent-js to fix the new response code change +* Bump candid to 0.9 + +### didc + +* Add a strict mode for `didc check` which checks for structural equality instead of backward compatibility. + +## 2023-06-30 (Rust 0.9.0) ### Breaking changes: diff --git a/README.md b/README.md index e9408db0..00c4a8a7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ the data they exchange, with type safety and extensibility. * The [spec](spec/) directory contains Candid specifications, including the [Candid language specification](spec/Candid.md) and a soundness proof. * The [official manual](https://internetcomputer.org/docs/current/developer-docs/build/candid/candid-intro/) is hosted by dfinity; see [./docs](docs/) for the source code. +* Roman Kashitsyn's [Candid for engineers](https://mmapped.blog/posts/20-candid-for-engineers.html) blog post. +* Joachim Breitner's [Candid explainer](https://www.joachim-breitner.de/blog/782-A_Candid_explainer__The_rough_idea) blog post. ## Implementations diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index c362f1ae..336ab051 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "candid" -version = "0.9.0" +version = "0.9.1" edition = "2021" authors = ["DFINITY Team"] description = "Candid is an interface description language (IDL) for interacting with canisters running on the Internet Computer." @@ -20,7 +20,7 @@ lalrpop = { version = "0.20.0", optional = true } [dependencies] byteorder = "1.4.3" -candid_derive = { path = "../candid_derive", version = "=0.6.1" } +candid_derive = { path = "../candid_derive", version = "=0.6.2" } codespan-reporting = "0.11" crc32fast = "1.3.0" data-encoding = "2.4.0" @@ -55,7 +55,6 @@ goldenfile = "1.1.0" test-generator = "0.3.0" rand = "0.8" criterion = "0.4" -serde = { version = "1.0.133", features = ["derive"] } serde_cbor = "0.11.2" serde_json = "1.0.74" serde_test = "1.0.137" diff --git a/rust/candid_derive/Cargo.toml b/rust/candid_derive/Cargo.toml index 018df697..d4cf81a3 100644 --- a/rust/candid_derive/Cargo.toml +++ b/rust/candid_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "candid_derive" -version = "0.6.1" +version = "0.6.2" edition = "2021" authors = ["DFINITY Team"] description = "Macros implementation of #[derive(CandidType)] for the Candid." @@ -20,6 +20,6 @@ proc-macro = true [dependencies] quote = "1.0.7" -syn = { version = "1.0.38", features = ["visit", "full"] } +syn = { version = "2.0", features = ["visit", "full"] } proc-macro2 = "1.0.19" lazy_static = "1.4.0" diff --git a/rust/candid_derive/src/derive.rs b/rust/candid_derive/src/derive.rs index 11aa2357..a83cf3f5 100644 --- a/rust/candid_derive/src/derive.rs +++ b/rust/candid_derive/src/derive.rs @@ -1,4 +1,4 @@ -use super::{candid_path, idl_hash}; +use super::{candid_path, get_lit_str, idl_hash}; use proc_macro2::TokenStream; use quote::quote; use std::collections::BTreeSet; @@ -265,12 +265,13 @@ struct Field { with_bytes: bool, } -fn get_serde_meta_items(attr: &syn::Attribute) -> Result, ()> { - if !attr.path.is_ident("serde") { +fn get_serde_meta_items(attr: &syn::Attribute) -> Result, ()> { + if !attr.path().is_ident("serde") { return Ok(Vec::new()); } - match attr.parse_meta() { - Ok(syn::Meta::List(meta)) => Ok(meta.nested.into_iter().collect()), + let nested = attr.parse_args_with(Punctuated::::parse_terminated); + match nested { + Ok(nested) => Ok(nested.into_iter().collect()), _ => Err(()), } } @@ -281,8 +282,7 @@ struct Attributes { } fn get_attrs(attrs: &[syn::Attribute]) -> Attributes { - use syn::Meta::{List, NameValue}; - use syn::NestedMeta::Meta; + use syn::Meta; let mut res = Attributes { rename: None, with_bytes: false, @@ -290,27 +290,30 @@ fn get_attrs(attrs: &[syn::Attribute]) -> Attributes { for item in attrs.iter().flat_map(get_serde_meta_items).flatten() { match &item { // #[serde(rename = "foo")] - Meta(NameValue(m)) if m.path.is_ident("rename") => { - if let syn::Lit::Str(lit) = &m.lit { + Meta::NameValue(m) if m.path.is_ident("rename") => { + if let Ok(lit) = get_lit_str(&m.value) { res.rename = Some(lit.value()); } } // #[serde(rename(serialize = "foo"))] - Meta(List(metas)) if metas.path.is_ident("rename") => { - for item in metas.nested.iter() { - match item { - Meta(NameValue(m)) if m.path.is_ident("serialize") => { - if let syn::Lit::Str(lit) = &m.lit { - res.rename = Some(lit.value()); + Meta::List(metas) if metas.path.is_ident("rename") => { + let nested = metas.parse_args_with(Punctuated::::parse_terminated); + if let Ok(nested) = nested { + for item in nested { + match item { + Meta::NameValue(m) if m.path.is_ident("serialize") => { + if let Ok(lit) = get_lit_str(&m.value) { + res.rename = Some(lit.value()); + } } + _ => continue, } - _ => continue, } } } // #[serde(with = "serde_bytes")] - Meta(NameValue(m)) if m.path.is_ident("with") => { - if let syn::Lit::Str(lit) = &m.lit { + Meta::NameValue(m) if m.path.is_ident("with") => { + if let Ok(lit) = get_lit_str(&m.value) { if lit.value() == "serde_bytes" { res.with_bytes = true; } diff --git a/rust/candid_derive/src/func.rs b/rust/candid_derive/src/func.rs index 94826304..b88afb22 100644 --- a/rust/candid_derive/src/func.rs +++ b/rust/candid_derive/src/func.rs @@ -1,10 +1,10 @@ -use super::candid_path; +use super::{candid_path, get_lit_str}; use lazy_static::lazy_static; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use std::collections::BTreeMap; use std::sync::Mutex; -use syn::{AttributeArgs, Error, ItemFn, Result, ReturnType, Signature, Type}; +use syn::{Error, ItemFn, Meta, Result, ReturnType, Signature, Type}; struct Method { args: Vec, @@ -22,8 +22,8 @@ lazy_static! { static ref INIT: Mutex>>> = Mutex::new(Some(Default::default())); } -pub(crate) fn candid_method(attrs: AttributeArgs, fun: ItemFn) -> Result { - let attrs = get_candid_attribute(&attrs)?; +pub(crate) fn candid_method(attrs: Vec, fun: ItemFn) -> Result { + let attrs = get_candid_attribute(attrs)?; let sig = &fun.sig; if !sig.generics.params.is_empty() { return Err(Error::new_spanned( @@ -193,22 +193,20 @@ struct CandidAttribute { is_init: bool, } -fn get_candid_attribute(attrs: &[syn::NestedMeta]) -> Result { - use syn::Meta::{NameValue, Path}; - use syn::NestedMeta::Meta; +fn get_candid_attribute(attrs: Vec) -> Result { let mut res = CandidAttribute { rename: None, method_type: None, is_init: false, }; - for attr in attrs.iter() { + for attr in attrs { match &attr { - Meta(NameValue(m)) if m.path.is_ident("rename") && res.rename.is_none() => { - if let syn::Lit::Str(lit) = &m.lit { + Meta::NameValue(m) if m.path.is_ident("rename") && res.rename.is_none() => { + if let Ok(lit) = get_lit_str(&m.value) { res.rename = Some(lit.value()); } } - Meta(Path(p)) if res.method_type.is_none() => { + Meta::Path(p) if res.method_type.is_none() => { let mode = p.get_ident().unwrap().to_string(); match mode.as_ref() { "query" | "composite_query" | "update" | "oneway" => { diff --git a/rust/candid_derive/src/lib.rs b/rust/candid_derive/src/lib.rs index 834f6cbc..9c9ee8a7 100644 --- a/rust/candid_derive/src/lib.rs +++ b/rust/candid_derive/src/lib.rs @@ -17,7 +17,11 @@ pub fn derive_idl_type(input: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn candid_method(attr: TokenStream, item: TokenStream) -> TokenStream { - let attrs = parse_macro_input!(attr as syn::AttributeArgs); + use syn::{parse::Parser, punctuated::Punctuated, Meta, Token}; + let attrs = match Punctuated::::parse_terminated.parse(attr) { + Ok(attrs) => attrs.into_iter().collect(), + Err(e) => return e.to_compile_error().into(), + }; let fun = parse_macro_input!(item as syn::ItemFn); func::candid_method(attrs, fun).map_or_else(|e| e.to_compile_error().into(), Into::into) } @@ -48,12 +52,20 @@ pub(crate) fn candid_path( None => quote::quote! { ::candid }, } } +pub(crate) fn get_lit_str(expr: &syn::Expr) -> std::result::Result { + if let syn::Expr::Lit(expr) = expr { + if let syn::Lit::Str(lit) = &expr.lit { + return Ok(lit.clone()); + } + } + Err(()) +} fn get_custom_candid_path(input: &syn::DeriveInput) -> Result> { let candid_path_helper_attribute_option = input .attrs .iter() - .find(|attr| attr.path.is_ident("candid_path")); + .find(|attr| attr.path().is_ident("candid_path")); match candid_path_helper_attribute_option { Some(candid_path_helper_attribute) => {