From 7cd3ab4b34836c6f3b64000fb26465b2e99674fc Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 26 Aug 2024 03:10:12 +0200 Subject: [PATCH] style: fix clippy warnings --- Cargo.lock | 383 ++++++++++-------- Cargo.toml | 7 +- bindings/jsonnet/src/native.rs | 1 + cmds/jrsonnet-fmt/src/comments.rs | 2 +- cmds/jrsonnet-fmt/src/tests.rs | 2 +- .../src/function/arglike.rs | 57 ++- crates/jrsonnet-evaluator/src/function/mod.rs | 17 +- .../jrsonnet-evaluator/src/stdlib/format.rs | 11 +- crates/jrsonnet-rowan-parser/src/ast.rs | 6 +- crates/jrsonnet-rowan-parser/src/event.rs | 21 +- crates/jrsonnet-stdlib/src/manifest/mod.rs | 1 + crates/jrsonnet-stdlib/src/manifest/yaml.rs | 2 +- crates/jrsonnet-stdlib/src/strings.rs | 9 +- crates/jrsonnet-types/src/lib.rs | 171 -------- flake.lock | 58 +-- rust-toolchain.toml | 2 +- tests/tests/builtin.rs | 16 +- tests/tests/common.rs | 1 + tests/tests/golden.rs | 71 ++-- 19 files changed, 350 insertions(+), 488 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5afcc81..154af6cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,9 +41,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -56,36 +56,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.3" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -114,9 +114,9 @@ checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "block-buffer" @@ -133,11 +133,20 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "cc" -version = "1.0.97" +version = "1.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "50d2eb3cd3d1bf4529e31c215ee6f93ec5a3d536d9f578f93d9d33ee19562932" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -147,9 +156,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.4" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -157,9 +166,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -169,36 +178,36 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.2" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +checksum = "531d7959c5bbb6e266cecdd0f20213639c3a5c3e4d615f97db87661745f781ff" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.76", ] [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "console" @@ -209,7 +218,7 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -220,9 +229,9 @@ checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" dependencies = [ "libc", ] @@ -272,7 +281,7 @@ checksum = "b569f4e3085ae957ecc37588e6b2227791b72745434eae966db29e122ba27f0d" dependencies = [ "anyhow", "bumpalo", - "indexmap 2.2.6", + "indexmap 2.4.0", "rustc-hash", "serde", "unicode-width", @@ -286,9 +295,9 @@ checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1" [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "encode_unicode" @@ -309,14 +318,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "fastrand" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fnv" @@ -392,9 +401,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -421,9 +430,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" @@ -524,7 +533,7 @@ checksum = "4782d1d76731f5e5bb4bdeff26ed3350f21d662f178ce6dee7b4da810e7a8f72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.76", ] [[package]] @@ -542,7 +551,8 @@ version = "0.5.0-pre96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.76", + "syn-dissect-closure", ] [[package]] @@ -620,15 +630,15 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libjsonnet" @@ -665,18 +675,18 @@ dependencies = [ [[package]] name = "logos" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161971eb88a0da7ae0c333e1063467c5b5727e7fb6b710b8db4814eade3a42e8" +checksum = "ff1ceb190eb9bdeecdd8f1ad6a71d6d632a50905948771718741b5461fb01e13" dependencies = [ "logos-derive", ] [[package]] name = "logos-codegen" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e31badd9de5131fdf4921f6473d457e3dd85b11b7f091ceb50e4df7c3eeb12a" +checksum = "90be66cb7bd40cb5cc2e9cfaf2d1133b04a3d93b72344267715010a466e0915a" dependencies = [ "beef", "fnv", @@ -684,23 +694,23 @@ dependencies = [ "proc-macro2", "quote", "regex-syntax", - "syn 2.0.64", + "syn 2.0.76", ] [[package]] name = "logos-derive" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c2a69b3eb68d5bd595107c9ee58d7e07fe2bb5e360cc85b0f084dedac80de0a" +checksum = "45154231e8e96586b39494029e58f12f8ffcb5ecf80333a603a13aa205ea8cbd" dependencies = [ "logos-codegen", ] [[package]] name = "lru" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" +checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" dependencies = [ "hashbrown 0.14.5", ] @@ -713,18 +723,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mimalloc-sys" @@ -747,9 +748,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", @@ -811,9 +812,9 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "peg" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a625d12ad770914cbf7eff6f9314c3ef803bfe364a1b20bc36ddf56673e71e5" +checksum = "295283b02df346d1ef66052a757869b2876ac29a6bb0ac3f5f7cd44aebe40e8f" dependencies = [ "peg-macros", "peg-runtime", @@ -821,9 +822,9 @@ dependencies = [ [[package]] name = "peg-macros" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f241d42067ed3ab6a4fece1db720838e1418f36d868585a27931f95d6bc03582" +checksum = "bdad6a1d9cf116a059582ce415d5f5566aabcd4008646779dab7fdc2a9a9d426" dependencies = [ "peg-runtime", "proc-macro2", @@ -838,15 +839,18 @@ checksum = "e3aeb8f54c078314c2065ee649a7241f46b9d8e418e1a9581ba0546657d7aa3a" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -862,9 +866,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -919,18 +923,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -940,9 +944,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -951,19 +955,18 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rowan" -version = "0.15.15" +version = "0.15.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a58fa8a7ccff2aec4f39cc45bf5f985cec7125ab271cf681c279fd00192b49" +checksum = "0a542b0253fa46e632d27a1dc5cf7b930de4df8659dc6e720b647fc72147ae3d" dependencies = [ "countme", "hashbrown 0.14.5", - "memoffset", "rustc-hash", "text-size", ] @@ -984,7 +987,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1001,31 +1004,32 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.202" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.202" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.76", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1074,11 +1078,17 @@ dependencies = [ "keccak", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "similar" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" [[package]] name = "smallvec" @@ -1088,15 +1098,15 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "stacker" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" +checksum = "95a5daa25ea337c85ed954c0496e3bdd2c7308cc3b24cf7b50d04876654c579f" dependencies = [ "cc", "cfg-if", "libc", "psm", - "winapi", + "windows-sys 0.36.1", ] [[package]] @@ -1124,25 +1134,37 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.64" +version = "2.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "syn-dissect-closure" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343bae741672e4b94421cbe93f9794ba9a061434272f7e3a29ff43be26be3ac9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand", + "once_cell", "rustix", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1165,22 +1187,22 @@ checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.76", ] [[package]] @@ -1203,21 +1225,21 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -1226,99 +1248,129 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] [[package]] name = "windows-sys" -version = "0.52.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_x86_64_msvc 0.52.6", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xshell" @@ -1341,7 +1393,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", - "indexmap 2.2.6", + "indexmap 2.4.0", "itertools", "proc-macro2", "quote", @@ -1360,20 +1412,21 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.76", ] diff --git a/Cargo.toml b/Cargo.toml index de0f47d3..0970a378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,7 @@ regex = "1.10" lru = "0.12.3" json-structural-diff = "0.1.0" +syn-dissect-closure = "0.1.0" [workspace.lints.rust] unsafe_op_in_unsafe_fn = "deny" @@ -107,9 +108,9 @@ macro_expanded_macro_exports_accessed_by_absolute_paths = "allow" all = "warn" [workspace.lints.clippy] -all = "warn" -nursery = "warn" -pedantic = "warn" +all = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +pedantic = { level = "warn", priority = -1 } ptr_arg = "allow" # Too verbose diff --git a/bindings/jsonnet/src/native.rs b/bindings/jsonnet/src/native.rs index 17804911..3f56df87 100644 --- a/bindings/jsonnet/src/native.rs +++ b/bindings/jsonnet/src/native.rs @@ -20,6 +20,7 @@ use crate::VM; /// - `ctx` User pointer, given in `jsonnet_native_callback`. /// - `argv` Array of arguments from Jsonnet code. /// - `param` success Set this byref param to 1 to indicate success and 0 for failure. +/// /// Returns the content of the imported file, or an error message. type JsonnetNativeCallback = unsafe extern "C" fn( ctx: *const c_void, diff --git a/cmds/jrsonnet-fmt/src/comments.rs b/cmds/jrsonnet-fmt/src/comments.rs index 576f44ec..dba094ea 100644 --- a/cmds/jrsonnet-fmt/src/comments.rs +++ b/cmds/jrsonnet-fmt/src/comments.rs @@ -20,7 +20,7 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P let Ok(c) = c else { let mut text = c.as_ref().unwrap_err() as &str; while !text.is_empty() { - let pos = text.find(|c| c == '\n' || c == '\t').unwrap_or(text.len()); + let pos = text.find(['\n', '\t']).unwrap_or(text.len()); let sliced = &text[..pos]; p!(out, string(sliced.to_string())); text = &text[pos..]; diff --git a/cmds/jrsonnet-fmt/src/tests.rs b/cmds/jrsonnet-fmt/src/tests.rs index e774fb03..eb19a3f0 100644 --- a/cmds/jrsonnet-fmt/src/tests.rs +++ b/cmds/jrsonnet-fmt/src/tests.rs @@ -75,5 +75,5 @@ fn complex_comments_snapshot() { b: '', }, }" - ))) + ))); } diff --git a/crates/jrsonnet-evaluator/src/function/arglike.rs b/crates/jrsonnet-evaluator/src/function/arglike.rs index ec8490d8..abeaa22a 100644 --- a/crates/jrsonnet-evaluator/src/function/arglike.rs +++ b/crates/jrsonnet-evaluator/src/function/arglike.rs @@ -91,6 +91,7 @@ pub trait ArgsLike { handler: &mut dyn FnMut(&IStr, Thunk) -> Result<()>, ) -> Result<()>; fn named_names(&self, handler: &mut dyn FnMut(&IStr)); + fn is_empty(&self) -> bool; } impl ArgsLike for Vec { @@ -117,6 +118,9 @@ impl ArgsLike for Vec { Ok(()) } fn named_names(&self, _handler: &mut dyn FnMut(&IStr)) {} + fn is_empty(&self) -> bool { + self.is_empty() + } } impl ArgsLike for ArgsDesc { @@ -173,6 +177,10 @@ impl ArgsLike for ArgsDesc { handler(name); } } + + fn is_empty(&self) -> bool { + self.unnamed.is_empty() && self.named.is_empty() + } } impl ArgsLike for HashMap { @@ -206,6 +214,10 @@ impl ArgsLike for HashMap { handler(name); } } + + fn is_empty(&self) -> bool { + self.is_empty() + } } impl OptionalContext for HashMap where V: ArgLike + OptionalContext {} @@ -235,6 +247,10 @@ impl ArgsLike for GcHashMap { fn named_names(&self, handler: &mut dyn FnMut(&IStr)) { self.0.named_names(handler); } + + fn is_empty(&self) -> bool { + self.0.is_empty() + } } macro_rules! impl_args_like { @@ -267,43 +283,13 @@ macro_rules! impl_args_like { Ok(()) } fn named_names(&self, _handler: &mut dyn FnMut(&IStr)) {} - } - impl<$($gen: ArgLike,)*> OptionalContext for ($($gen,)*) where $($gen: OptionalContext),* {} - impl<$($gen: ArgLike,)*> ArgsLike for ($((IStr, $gen),)*) { - fn unnamed_len(&self) -> usize { - 0 - } - fn unnamed_iter( - &self, - _ctx: Context, - _tailstrict: bool, - _handler: &mut dyn FnMut(usize, Thunk) -> Result<()>, - ) -> Result<()> { - Ok(()) - } - #[allow(non_snake_case)] - fn named_iter( - &self, - ctx: Context, - tailstrict: bool, - handler: &mut dyn FnMut(&IStr, Thunk) -> Result<()>, - ) -> Result<()> { - let ($($gen,)*) = self; - $( - handler(&$gen.0, $gen.1.evaluate_arg(ctx.clone(), tailstrict)?)?; - )* - Ok(()) - } - #[allow(non_snake_case)] - fn named_names(&self, handler: &mut dyn FnMut(&IStr)) { - let ($($gen,)*) = self; - $( - handler(&$gen.0); - )* + fn is_empty(&self) -> bool { + // impl_args_like only implements non-empty tuples. + false } } - impl<$($gen: ArgLike,)*> OptionalContext for ($((IStr, $gen),)*) where $($gen: OptionalContext),* {} + impl<$($gen: ArgLike,)*> OptionalContext for ($($gen,)*) where $($gen: OptionalContext),* {} }; ($count:expr; $($cur:ident)* @ $c:ident $($rest:ident)*) => { impl_args_like!($count; $($cur)*); @@ -342,5 +328,8 @@ impl ArgsLike for () { } fn named_names(&self, _handler: &mut dyn FnMut(&IStr)) {} + fn is_empty(&self) -> bool { + true + } } impl OptionalContext for () {} diff --git a/crates/jrsonnet-evaluator/src/function/mod.rs b/crates/jrsonnet-evaluator/src/function/mod.rs index b3ac9e89..b533695a 100644 --- a/crates/jrsonnet-evaluator/src/function/mod.rs +++ b/crates/jrsonnet-evaluator/src/function/mod.rs @@ -12,7 +12,10 @@ use self::{ native::NativeDesc, parse::{parse_default_function_call, parse_function_call}, }; -use crate::{evaluate, evaluate_trivial, gc::TraceBox, tb, Context, ContextBuilder, Result, Val}; +use crate::{ + bail, error::ErrorKind::*, evaluate, evaluate_trivial, gc::TraceBox, tb, Context, + ContextBuilder, Result, Thunk, Val, +}; pub mod arglike; pub mod builtin; @@ -94,6 +97,8 @@ pub enum FuncVal { Id, /// Plain function implemented in jsonnet. Normal(Cc), + /// Function without arguments works just as a fancy thunk value. + Thunk(Thunk), /// Standard library function. StaticBuiltin(#[trace(skip)] &'static dyn StaticBuiltin), /// User-provided function. @@ -104,6 +109,7 @@ impl Debug for FuncVal { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Id => f.debug_tuple("Id").finish(), + Self::Thunk(arg0) => f.debug_tuple("Thunk").field(arg0).finish(), Self::Normal(arg0) => f.debug_tuple("Normal").field(arg0).finish(), Self::StaticBuiltin(arg0) => { f.debug_tuple("StaticBuiltin").field(&arg0.name()).finish() @@ -146,6 +152,7 @@ impl FuncVal { ) }) .collect(), + Self::Thunk(_) => vec![], } } /// Amount of non-default required arguments @@ -155,6 +162,7 @@ impl FuncVal { Self::Normal(n) => n.params.iter().filter(|p| p.1.is_none()).count(), Self::StaticBuiltin(i) => i.params().iter().filter(|p| !p.has_default()).count(), Self::Builtin(i) => i.params().iter().filter(|p| !p.has_default()).count(), + Self::Thunk(_) => 0, } } /// Function name, as defined in code. @@ -164,6 +172,7 @@ impl FuncVal { Self::Normal(normal) => normal.name.clone(), Self::StaticBuiltin(builtin) => builtin.name().into(), Self::Builtin(builtin) => builtin.name().into(), + Self::Thunk(_) => "thunk".into(), } } /// Call function using arguments evaluated in specified `call_ctx` [`Context`]. @@ -182,6 +191,12 @@ impl FuncVal { let body_ctx = func.call_body_context(call_ctx, args, tailstrict)?; evaluate(body_ctx, &func.body) } + Self::Thunk(thunk) => { + if args.is_empty() { + bail!(TooManyArgsFunctionHas(0, vec![],)) + } + thunk.evaluate() + } Self::StaticBuiltin(b) => b.call(call_ctx, loc, args), Self::Builtin(b) => b.call(call_ctx, loc, args), } diff --git a/crates/jrsonnet-evaluator/src/stdlib/format.rs b/crates/jrsonnet-evaluator/src/stdlib/format.rs index fb50fa1c..934a8f65 100644 --- a/crates/jrsonnet-evaluator/src/stdlib/format.rs +++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs @@ -308,22 +308,21 @@ pub fn render_integer( prefix: &str, caps: bool, ) { - let radix = radix as f64; - let iv = iv.floor(); + let iv = iv.floor() as i64; // Digit char indexes in reverse order, i.e // for radix = 16 and n = 12f: [15, 2, 1] - let digits = if iv == 0.0 { + let digits = if iv == 0 { vec![0u8] } else { let mut v = iv.abs(); let mut nums = Vec::with_capacity(1); - while v != 0.0 { + while v != 0 { nums.push((v % radix) as u8); - v = (v / radix).floor(); + v /= radix; } nums }; - let neg = iv < 0.0; + let neg = iv < 0; #[allow(clippy::bool_to_int_with_if)] let zp = padding.saturating_sub(if neg || blank || sign { 1 } else { 0 }); let zp2 = zp diff --git a/crates/jrsonnet-rowan-parser/src/ast.rs b/crates/jrsonnet-rowan-parser/src/ast.rs index 3c33da52..5fe8c37a 100644 --- a/crates/jrsonnet-rowan-parser/src/ast.rs +++ b/crates/jrsonnet-rowan-parser/src/ast.rs @@ -16,12 +16,14 @@ pub trait AstNode { Self: Sized; fn syntax(&self) -> &SyntaxNode; + #[must_use] fn clone_for_update(&self) -> Self where Self: Sized, { Self::cast(self.syntax().clone_for_update()).unwrap() } + #[must_use] fn clone_subtree(&self) -> Self where Self: Sized, @@ -70,6 +72,8 @@ impl Iterator for AstChildren { } pub mod support { + use rowan::NodeOrToken; + use super::{AstChildren, AstNode, AstToken, SyntaxKind, SyntaxNode, SyntaxToken}; pub fn child(parent: &SyntaxNode) -> Option { @@ -89,7 +93,7 @@ pub mod support { pub fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option { parent .children_with_tokens() - .filter_map(|it| it.into_token()) + .filter_map(NodeOrToken::into_token) .find(|it| it.kind() == kind) } } diff --git a/crates/jrsonnet-rowan-parser/src/event.rs b/crates/jrsonnet-rowan-parser/src/event.rs index a1c8d8d0..c3a6d03e 100644 --- a/crates/jrsonnet-rowan-parser/src/event.rs +++ b/crates/jrsonnet-rowan-parser/src/event.rs @@ -26,7 +26,7 @@ pub enum Event { // VirtualToken { kind: SyntaxKind }, /// Position of finished node Finish { - /// Same as forward_parent of Start, but for wrapping + /// Same as `forward_parent` of Start, but for wrapping wrapper: Option, error: Option>, }, @@ -57,13 +57,14 @@ impl<'i> Sink<'i> { if self.offset == 0 { return 0.into(); }; - if let Some(lex) = self.lexemes.get(self.offset) { - lex.range.start() - } else if let Some(lex) = self.lexemes.get(self.offset - 1) { - lex.range.end() - } else { - panic!("hard oob") - } + self.lexemes.get(self.offset).map_or_else( + || { + self.lexemes + .get(self.offset - 1) + .map_or_else(|| panic!("hard oob"), |lex| lex.range.end()) + }, + |lex| lex.range.start(), + ) } pub(super) fn finish(mut self) -> Parse { @@ -139,7 +140,7 @@ impl<'i> Sink<'i> { self.errors.push(LocatedSyntaxError { error: *error, range: TextRange::new(range.0, range.1), - }) + }); } self.builder.finish_node(); depth -= 1; @@ -158,7 +159,7 @@ impl<'i> Sink<'i> { self.errors.push(LocatedSyntaxError { error: *error, range: TextRange::new(range.0, range.1), - }) + }); } if depth == 1 { diff --git a/crates/jrsonnet-stdlib/src/manifest/mod.rs b/crates/jrsonnet-stdlib/src/manifest/mod.rs index e0fd37f1..be7cca3f 100644 --- a/crates/jrsonnet-stdlib/src/manifest/mod.rs +++ b/crates/jrsonnet-stdlib/src/manifest/mod.rs @@ -98,6 +98,7 @@ pub fn builtin_manifest_yaml_doc( } #[builtin] +#[allow(clippy::fn_params_excessive_bools)] pub fn builtin_manifest_yaml_stream( value: Val, #[default(false)] indent_array_in_object: bool, diff --git a/crates/jrsonnet-stdlib/src/manifest/yaml.rs b/crates/jrsonnet-stdlib/src/manifest/yaml.rs index fe683d49..cb844c43 100644 --- a/crates/jrsonnet-stdlib/src/manifest/yaml.rs +++ b/crates/jrsonnet-stdlib/src/manifest/yaml.rs @@ -76,7 +76,7 @@ fn yaml_needs_quotes(string: &str) -> bool { string.is_empty() || need_quotes_spaces(string) - || string.starts_with(|c| matches!(c, '&' | '*' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@')) + || string.starts_with(['&' , '*' , '?' , '|' , '-' , '<' , '>' , '=' , '!' , '%' , '@']) || string.contains(|c| matches!(c, ':' | '{' | '}' | '[' | ']' | ',' | '#' | '`' | '\"' | '\'' | '\\' | '\0'..='\x06' | '\t' | '\n' | '\r' | '\x0e'..='\x1a' | '\x1c'..='\x1f')) || [ // http://yaml.org/type/bool.html diff --git a/crates/jrsonnet-stdlib/src/strings.rs b/crates/jrsonnet-stdlib/src/strings.rs index b214b957..e47e3992 100644 --- a/crates/jrsonnet-stdlib/src/strings.rs +++ b/crates/jrsonnet-stdlib/src/strings.rs @@ -267,6 +267,7 @@ fn new_trim_pattern(chars: IndexableVal) -> Result bool> { } #[cfg(test)] +#[allow(clippy::float_cmp)] mod tests { use super::*; @@ -274,8 +275,8 @@ mod tests { fn parse_nat_base_8() { assert_eq!(parse_nat::<8>("0").unwrap(), 0.); assert_eq!(parse_nat::<8>("5").unwrap(), 5.); - assert_eq!(parse_nat::<8>("32").unwrap(), 0o32 as f64); - assert_eq!(parse_nat::<8>("761").unwrap(), 0o761 as f64); + assert_eq!(parse_nat::<8>("32").unwrap(), f64::from(0o32)); + assert_eq!(parse_nat::<8>("761").unwrap(), f64::from(0o761)); } #[test] @@ -290,7 +291,7 @@ mod tests { fn parse_nat_base_16() { assert_eq!(parse_nat::<16>("0").unwrap(), 0.); assert_eq!(parse_nat::<16>("A").unwrap(), 10.); - assert_eq!(parse_nat::<16>("a9").unwrap(), 0xA9 as f64); - assert_eq!(parse_nat::<16>("BbC").unwrap(), 0xBBC as f64); + assert_eq!(parse_nat::<16>("a9").unwrap(), f64::from(0xA9)); + assert_eq!(parse_nat::<16>("BbC").unwrap(), f64::from(0xBBC)); } } diff --git a/crates/jrsonnet-types/src/lib.rs b/crates/jrsonnet-types/src/lib.rs index 08dc821b..26bce22f 100644 --- a/crates/jrsonnet-types/src/lib.rs +++ b/crates/jrsonnet-types/src/lib.rs @@ -4,84 +4,6 @@ use std::fmt::Display; use jrsonnet_gcmodule::Trace; -#[macro_export] -macro_rules! ty { - ((Array)) => {{ - $crate::ComplexValType::ArrayRef(&$crate::ComplexValType::Simple($crate::ValType::Num)) - }}; - ((Array)) => {{ - $crate::ComplexValType::ArrayRef(&$crate::ComplexValType::BoundedNumber(Some(0.0), Some(255.0))) - }}; - (array) => { - $crate::ComplexValType::Simple($crate::ValType::Arr) - }; - (boolean) => { - $crate::ComplexValType::Simple($crate::ValType::Bool) - }; - (null) => { - $crate::ComplexValType::Simple($crate::ValType::Null) - }; - (string) => { - $crate::ComplexValType::Simple($crate::ValType::Str) - }; - (char) => { - $crate::ComplexValType::Char - }; - (number) => { - $crate::ComplexValType::Simple($crate::ValType::Num) - }; - (BoundedNumber<($min:expr), ($max:expr)>) => {{ - $crate::ComplexValType::BoundedNumber($min, $max) - }}; - (object) => { - $crate::ComplexValType::Simple($crate::ValType::Obj) - }; - (any) => { - $crate::ComplexValType::Any - }; - (function) => { - $crate::ComplexValType::Simple($crate::ValType::Func) - }; - (($($a:tt) |+)) => {{ - static CONTENTS: &'static [&'static $crate::ComplexValType] = &[ - $(&ty!($a)),+ - ]; - $crate::ComplexValType::UnionRef(CONTENTS) - }}; - (($($a:tt) &+)) => {{ - static CONTENTS: &'static [&'static $crate::ComplexValType] = &[ - $(&ty!($a)),+ - ]; - $crate::ComplexValType::SumRef(CONTENTS) - }}; -} - -#[test] -fn test() { - assert_eq!( - ty!((Array)), - ComplexValType::ArrayRef(&ComplexValType::Simple(ValType::Num)) - ); - assert_eq!(ty!(array), ComplexValType::Simple(ValType::Arr)); - assert_eq!(ty!(any), ComplexValType::Any); - assert_eq!( - ty!((string | number)), - ComplexValType::UnionRef(&[ - &ComplexValType::Simple(ValType::Str), - &ComplexValType::Simple(ValType::Num) - ]) - ); - assert_eq!( - format!("{}", ty!(((string & number) | (object & null)))), - "string & number | object & null" - ); - assert_eq!(format!("{}", ty!((string | array))), "string | array"); - assert_eq!( - format!("{}", ty!(((string & number) | array))), - "string & number | array" - ); -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)] pub enum ValType { Bool, @@ -215,96 +137,3 @@ impl Display for ComplexValType { Ok(()) } } - -peg::parser! { -pub grammar parser() for str { - rule number() -> f64 - = n:$(['0'..='9']+) { n.parse().unwrap() } - - rule any_ty() -> ComplexValType = "any" { ComplexValType::Any } - rule char_ty() -> ComplexValType = "character" { ComplexValType::Char } - rule bool_ty() -> ComplexValType = "boolean" { ComplexValType::Simple(ValType::Bool) } - rule null_ty() -> ComplexValType = "null" { ComplexValType::Simple(ValType::Null) } - rule str_ty() -> ComplexValType = "string" { ComplexValType::Simple(ValType::Str) } - rule num_ty() -> ComplexValType = "number" { ComplexValType::Simple(ValType::Num) } - rule simple_array_ty() -> ComplexValType = "array" { ComplexValType::Simple(ValType::Arr) } - rule simple_object_ty() -> ComplexValType = "object" { ComplexValType::Simple(ValType::Obj) } - rule simple_function_ty() -> ComplexValType = "function" { ComplexValType::Simple(ValType::Func) } - - rule array_ty() -> ComplexValType - = "Array<" t:ty() ">" { ComplexValType::Array(Box::new(t)) } - - rule bounded_number_ty() -> ComplexValType - = "BoundedNumber<" a:number() ", " b:number() ">" { ComplexValType::BoundedNumber(Some(a), Some(b)) } - - rule ty_basic() -> ComplexValType - = any_ty() - / char_ty() - / bool_ty() - / null_ty() - / str_ty() - / num_ty() - / simple_array_ty() - / simple_object_ty() - / simple_function_ty() - / array_ty() - / bounded_number_ty() - - pub rule ty() -> ComplexValType - = precedence! { - a:(@) " | " b:@ { - match a { - ComplexValType::Union(mut a) => { - a.push(b); - ComplexValType::Union(a) - } - _ => ComplexValType::Union(vec![a, b]), - } - } - -- - a:(@) " & " b:@ { - match a { - ComplexValType::Sum(mut a) => { - a.push(b); - ComplexValType::Sum(a) - } - _ => ComplexValType::Sum(vec![a, b]), - } - } - -- - "(" t:ty() ")" { t } - t:ty_basic() { t } - } -} -} - -#[cfg(test)] -pub mod tests { - use super::parser; - - #[test] - fn precedence() { - assert_eq!( - parser::ty("(any & any) | (any | any) & any") - .unwrap() - .to_string(), - "any & any | (any | any) & any" - ); - } - - #[test] - fn array() { - assert_eq!(parser::ty("Array").unwrap().to_string(), "array"); - assert_eq!( - parser::ty("Array").unwrap().to_string(), - "Array" - ); - } - #[test] - fn bounded_number() { - assert_eq!( - parser::ty("BoundedNumber<1, 2>").unwrap().to_string(), - "BoundedNumber<1, 2>" - ); - } -} diff --git a/flake.lock b/flake.lock index 5592dc93..0fb847d8 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1715274763, - "narHash": "sha256-3Iv1PGHJn9sV3HO4FlOVaaztOxa9uGLfOmUWrH7v7+A=", + "lastModified": 1724377159, + "narHash": "sha256-ixjje1JO8ucKT41hs6n2NCde1Vc0+Zc2p2gUbJpCsMw=", "owner": "ipetkov", "repo": "crane", - "rev": "27025ab71bdca30e7ed0a16c88fd74c5970fc7f5", + "rev": "3e47b7a86c19142bd3675da49d6acef488b4dac1", "type": "github" }, "original": { @@ -27,11 +27,11 @@ ] }, "locked": { - "lastModified": 1717285511, - "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", + "lastModified": 1722555600, + "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", + "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", "type": "github" }, "original": { @@ -40,31 +40,13 @@ "type": "github" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1715551360, - "narHash": "sha256-fGYt2XnTYUS4Q0eH8tVu3ki1+m9YTgZ+NjlfkMKzko0=", + "lastModified": 1724519568, + "narHash": "sha256-CmfrenY4cEi/mIslKy8XOGdqxUUVgT6/qMzNcAN/7z8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "836306cd7bbb9e0f89c557b2ae14df09e573ee89", + "rev": "eb0e6df0cdd2641ec0651cd9802ff4cff3b3e915", "type": "github" }, "original": { @@ -84,17 +66,16 @@ }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1715480255, - "narHash": "sha256-gEZl8nYidQwqJhOigJ91JDjoBFoPEWVsd82AKnaE7Go=", + "lastModified": 1724466314, + "narHash": "sha256-ltKuK6shQ64uej1mYNtBsDYxttUNFiv9AcHqk0+0NQM=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "d690205a4f01ec0930303c4204e5063958e51255", + "rev": "2b5b3edd96ef336b00622dcabc13788fdef9e3ca", "type": "github" }, "original": { @@ -125,21 +106,6 @@ "repo": "shelly", "type": "github" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a0080e68..e30595ef 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-05-10" +channel = "nightly-2024-08-20" components = ["rustfmt", "clippy", "rust-analyzer", "rust-src"] diff --git a/tests/tests/builtin.rs b/tests/tests/builtin.rs index 8f806578..014311a9 100644 --- a/tests/tests/builtin.rs +++ b/tests/tests/builtin.rs @@ -11,8 +11,8 @@ use jrsonnet_gcmodule::Trace; use jrsonnet_stdlib::ContextInitializer as StdContextInitializer; #[builtin] -fn a() -> Result { - Ok(1) +fn a() -> u32 { + 1 } #[test] @@ -29,8 +29,8 @@ fn basic_function() -> Result<()> { } #[builtin] -fn native_add(a: u32, b: u32) -> Result { - Ok(a + b) +fn native_add(a: u32, b: u32) -> u32 { + a + b } #[derive(Trace)] struct NativeAddContextInitializer; @@ -72,13 +72,13 @@ fn call_from_code() -> Result<()> { #[builtin(fields( a: u32 ))] -fn curried_add(this: &curried_add, b: u32) -> Result { - Ok(this.a + b) +fn curried_add(this: &curried_add, b: u32) -> u32 { + this.a + b } #[builtin] -fn curry_add(a: u32) -> Result { - Ok(FuncVal::builtin(curried_add { a })) +fn curry_add(a: u32) -> FuncVal { + FuncVal::builtin(curried_add { a }) } #[derive(Trace)] struct CurryAddContextInitializer; diff --git a/tests/tests/common.rs b/tests/tests/common.rs index 481883f5..baa3d73e 100644 --- a/tests/tests/common.rs +++ b/tests/tests/common.rs @@ -73,6 +73,7 @@ fn param_names(fun: FuncVal) -> Vec { .iter() .map(|p| p.name().as_str().unwrap_or("").to_string()) .collect(), + FuncVal::Thunk(_) => vec![], } } diff --git a/tests/tests/golden.rs b/tests/tests/golden.rs index c9e10f99..664d995e 100644 --- a/tests/tests/golden.rs +++ b/tests/tests/golden.rs @@ -32,7 +32,7 @@ fn run(file: &Path) -> String { Err(e) => return trace_format.format(&e).unwrap(), }; match v.manifest(JsonFormat::default()) { - Ok(v) => v.to_string(), + Ok(v) => v, Err(e) => trace_format.format(&e).unwrap(), } } @@ -57,45 +57,46 @@ fn test() -> io::Result<()> { if !golden_path.exists() { fs::write(golden_path, &result)?; - } else { - let golden = fs::read_to_string(golden_path)?; + continue; + } - match (serde_json::from_str(&result), serde_json::from_str(&golden)) { - (Err(_), Ok(_)) => assert_eq!( - result, - golden, - "unexpected error for golden {}", - entry.path().display() - ), - (Ok(_), Err(_)) => assert_eq!( - result, - golden, - "expected error for golden {}", - entry.path().display() - ), - (Ok(result), Ok(golden)) => { - // Show diff relative to golden`. - let diff = JsonDiff::diff_string(&golden, &result, false); - if let Some(diff) = diff { - panic!( - "Result \n{result:#}\n\ - and golden \n{golden:#}\n\ - did not match structurally:\n{diff:#}\n\ - for golden {}", - entry.path().display() - ); - } - } - (Err(_), Err(_)) => {} - }; + let golden = fs::read_to_string(golden_path)?; - assert_eq!( + match (serde_json::from_str(&result), serde_json::from_str(&golden)) { + (Err(_), Ok(_)) => assert_eq!( result, golden, - "golden didn't match for {}", + "unexpected error for golden {}", entry.path().display() - ) - } + ), + (Ok(_), Err(_)) => assert_eq!( + result, + golden, + "expected error for golden {}", + entry.path().display() + ), + (Ok(result), Ok(golden)) => { + // Show diff relative to golden`. + let diff = JsonDiff::diff_string(&golden, &result, false); + if let Some(diff) = diff { + panic!( + "Result \n{result:#}\n\ + and golden \n{golden:#}\n\ + did not match structurally:\n{diff:#}\n\ + for golden {}", + entry.path().display() + ); + } + } + (Err(_), Err(_)) => {} + }; + + assert_eq!( + result, + golden, + "golden didn't match for {}", + entry.path().display() + ); } Ok(())