summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_json
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/rust/serde_json
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/serde_json')
-rw-r--r--third_party/rust/serde_json/.cargo-checksum.json2
-rw-r--r--third_party/rust/serde_json/Cargo.toml33
-rw-r--r--third_party/rust/serde_json/README.md2
-rw-r--r--third_party/rust/serde_json/build.rs39
-rw-r--r--third_party/rust/serde_json/src/de.rs295
-rw-r--r--third_party/rust/serde_json/src/error.rs128
-rw-r--r--third_party/rust/serde_json/src/features_check/error.rs1
-rw-r--r--third_party/rust/serde_json/src/features_check/mod.rs13
-rw-r--r--third_party/rust/serde_json/src/io/core.rs2
-rw-r--r--third_party/rust/serde_json/src/lexical/algorithm.rs5
-rw-r--r--third_party/rust/serde_json/src/lexical/bignum.rs1
-rw-r--r--third_party/rust/serde_json/src/lexical/digit.rs5
-rw-r--r--third_party/rust/serde_json/src/lexical/errors.rs3
-rw-r--r--third_party/rust/serde_json/src/lexical/exponent.rs4
-rw-r--r--third_party/rust/serde_json/src/lexical/large_powers32.rs2
-rw-r--r--third_party/rust/serde_json/src/lexical/large_powers64.rs2
-rw-r--r--third_party/rust/serde_json/src/lexical/math.rs4
-rw-r--r--third_party/rust/serde_json/src/lexical/num.rs13
-rw-r--r--third_party/rust/serde_json/src/lexical/rounding.rs2
-rw-r--r--third_party/rust/serde_json/src/lib.rs35
-rw-r--r--third_party/rust/serde_json/src/macros.rs3
-rw-r--r--third_party/rust/serde_json/src/map.rs131
-rw-r--r--third_party/rust/serde_json/src/number.rs76
-rw-r--r--third_party/rust/serde_json/src/raw.rs270
-rw-r--r--third_party/rust/serde_json/src/read.rs6
-rw-r--r--third_party/rust/serde_json/src/ser.rs122
-rw-r--r--third_party/rust/serde_json/src/value/de.rs94
-rw-r--r--third_party/rust/serde_json/src/value/from.rs37
-rw-r--r--third_party/rust/serde_json/src/value/index.rs2
-rw-r--r--third_party/rust/serde_json/src/value/mod.rs30
-rw-r--r--third_party/rust/serde_json/src/value/partial_eq.rs14
-rw-r--r--third_party/rust/serde_json/src/value/ser.rs41
-rw-r--r--third_party/rust/serde_json/tests/lexical.rs6
-rw-r--r--third_party/rust/serde_json/tests/lexical/exponent.rs34
-rw-r--r--third_party/rust/serde_json/tests/lexical/parse.rs2
-rw-r--r--third_party/rust/serde_json/tests/map.rs1
-rw-r--r--third_party/rust/serde_json/tests/regression/issue1004.rs12
-rw-r--r--third_party/rust/serde_json/tests/regression/issue520.rs2
-rw-r--r--third_party/rust/serde_json/tests/regression/issue795.rs5
-rw-r--r--third_party/rust/serde_json/tests/regression/issue845.rs2
-rw-r--r--third_party/rust/serde_json/tests/test.rs245
-rw-r--r--third_party/rust/serde_json/tests/ui/parse_key.stderr2
42 files changed, 1223 insertions, 505 deletions
diff --git a/third_party/rust/serde_json/.cargo-checksum.json b/third_party/rust/serde_json/.cargo-checksum.json
index 369b6fe170..1f61b06b5f 100644
--- a/third_party/rust/serde_json/.cargo-checksum.json
+++ b/third_party/rust/serde_json/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CONTRIBUTING.md":"f5270cafba66223a7b51ffc0d286075a17bb7cd88762fc80d333d3102629f4d8","Cargo.toml":"547ec897b43d41db797423629543e838ee4e08c6a4196a0756b5be0ef178adc1","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"1e5a86e6b5e79f92f9e7226d9a8ba16d4ec70567d153c9cacebcb582770378a1","build.rs":"0dd97b63a07aa2d4bbb4c7d0e73b521da130769da9f49f28a7b63332781eb3de","src/de.rs":"5dba95fc6a564917289bf1e404d59c74f95772f22ec92cb91d55053b65e93032","src/error.rs":"abb92a9bf62cb7f47141a733a9fd66ec8c369615d7e6f633d3536fd2a5ac74a2","src/features_check/error.rs":"d7359f864afbfe105a38abea9f563dc423036ebc4c956a5695a4beef144dc7ec","src/features_check/mod.rs":"2209f8d5c46b50c8a3b8dc22338dcaf0135d192e8b05d2f456cbe6a73104e958","src/io/core.rs":"9a4146802391fd202a36bebbf3b14b715ae09d8828cbe8e06a01214c470ebf5c","src/io/mod.rs":"fd1ed5080495cab21117f6f7d3c2c9e3687cad0c69a0cd087b08a145a9e672da","src/iter.rs":"f832c469cd7999d26ba9b76baa69b257a212a7edb3dfdf9b1d1bb35e8da85fa9","src/lexical/algorithm.rs":"4fbeb1994049348d1fc388dd1a29e481f8abb8fe1e28bfebf50f3bbce5fa5fbe","src/lexical/bhcomp.rs":"b7c68d74c0055eb67ec2c1bcf27bbc28bef8f1bbc43db8eb94ba69892230add6","src/lexical/bignum.rs":"4230cde10dc8eae456a713cf90ec4e48dff4b1d0c542621ce7f00f39ade2645e","src/lexical/cached.rs":"0e127398691f8042c19cde209e7f4b0161f0f3150342430145929f711e6fdac8","src/lexical/cached_float80.rs":"0f8f74a22cb7d871322a9893bffd0255ca10bf9dffd13afb2462dd3d7f51805f","src/lexical/digit.rs":"a265b9072194a62a67dfc4df3c86d4213097cf3f82280d025e0012a5a262fd9d","src/lexical/errors.rs":"6bc993febceb7dd96ac1c8c5c53b5f5a30297016c0f813ed8ff8d7938d01534d","src/lexical/exponent.rs":"387e945b97dc7ba48a7091c50d228a0dde3a1c4145703d4ab9c31191a91693b0","src/lexical/float.rs":"fe356213c92a049f4bef2f58bc0e3a26866ca06b8c1d74d0f961c5b883852cad","src/lexical/large_powers.rs":"34537f5c701afce1ec2a1fd3c14950381b2e27c9ad74f002c91f3708e8da9ca5","src/lexical/large_powers32.rs":"d533037c6141e6671102aee490c9cdeaba81e667ddca781b2b99db2c455e4a1a","src/lexical/large_powers64.rs":"745dd7c0cbe499eec027ef586248881011d9df20c7efab7929c1807b59886ba1","src/lexical/math.rs":"27e22b724cdf990cdacd0ccfc3749e6e2eb7529d43ebf6e95b1999560b9e199a","src/lexical/mod.rs":"4b4c5228779c0f135a4cb018700e3bcd495da48b74421a86f6b8b304acdef924","src/lexical/num.rs":"cf705c62612e31d704f43d94a633ea1243c6befad7ef5792e2e881a7fd21e809","src/lexical/parse.rs":"c2bfac4c70a19938ced61e991f4ec606764887cf12bac1a0978b5b5318a56aac","src/lexical/rounding.rs":"697207248ba17b7f4965aedb11d276261ada5b06d9c6265d8fd6246664ff6e3c","src/lexical/shift.rs":"bc1ed053dd63d45ac9c35302f18de9f00d94027f28af4ab749c9248439de832a","src/lexical/small_powers.rs":"4608dd218b8002435db7e1ec79d2d0fef5f47ae257b93353326d52ecc80cccda","src/lib.rs":"f055ef570d978397cfae0d814ddbbf2372b8839ab4ffe8fc4c3308c9b2a332de","src/macros.rs":"c9f23156faec8d5216d72b6a97eebd768efb3f75870a6e2beed824308587b998","src/map.rs":"14fa16650b462ef138bebe1d18cb296b0e1ff404f12f2c212f72ed7c969b3a12","src/number.rs":"425f528c5ec2fcb4dd3c87a633d0b2cd505f7a305a40dffa1f022a643eda938b","src/raw.rs":"6d46836486b8d1c58f2aff563285400b1b0ec163eee34e7be78e0fa7a99aa0e8","src/read.rs":"49b4b1d067b6485cbded28fb961666ab5df82c36661af722dbae756efb6b2891","src/ser.rs":"566ae0b1860861ad70efd17fb0f6ae326e76d60453b6538c783a40d4ce616851","src/value/de.rs":"78f938d960e285f671f3b86ed173d598a815690a14512d6daa94dee43d3ce4cf","src/value/from.rs":"2dcfed837b040447a61eae50bd3938106b090f8a292206aea686022767006625","src/value/index.rs":"8a99d8d50f5674181ced22f6e81dc529eaecb01e543e30346e51fe42cb4b8a5f","src/value/mod.rs":"81c62fcb50e92b2f424e361328df5b02621756781bf80b8e26fd3d13473b57cd","src/value/partial_eq.rs":"95de799d57f7f4310b64a9488c0a7286dee76dba4329cb69a96298a887e58586","src/value/ser.rs":"5ea04bdf30c1c79baeab66b922908b47f1910b07d2f4ed0927a9a2c1ef3fbf60","tests/compiletest.rs":"022a8e400ef813d7ea1875b944549cee5125f6a995dc33e93b48cba3e1b57bd1","tests/debug.rs":"a8451217c1e127ad6e653ef11e0513525ee350e1e37dd575758a8ee9301b28fb","tests/lexical.rs":"383e06283e15e1db7c6b818da3c84a3afa0059f6e9fc994b069919d81346ab91","tests/lexical/algorithm.rs":"da378df9ee24bfa033968d5c94e91b58e52c39bf6c825dec51c3eb7250cc5874","tests/lexical/exponent.rs":"26ea92abc654a6a88a8281552bca2f76ea1fa4c17d66a1dd6defe14f7d89b666","tests/lexical/float.rs":"0440f2d85c993bcccd925096d7f4136bf624ffd66b3c7ee565d158390685eb11","tests/lexical/math.rs":"4874be2103be5fbe8b8015354414df271ffa00fd815546fc077f15fb4d7a5a37","tests/lexical/num.rs":"6e650c40de85ed72ac06b6bf1487ba161f3824e26d827df6cfdf2bbdb8d05a05","tests/lexical/parse.rs":"17c73e0a59d462716d974b8dd23a291eb6efdc3a933248874e5eab7e7209d67f","tests/lexical/rounding.rs":"6c56e39ba534616c1b2146e8efa6eb57aed322e683bf23183cd32a61fae6447e","tests/macros/mod.rs":"93aa1d54af20bc2c55b6ae8db73c1414cda2626eb9fa7bd57b9d613a3c6e6a19","tests/map.rs":"dcc5212242e4e93703c4335d54f5603b0211b33d6fb5ab410bb630cda6d46b09","tests/regression.rs":"86731134bfb9bb693d9a4fc62393027de80a8bf031109ea6c7ea475b1ebdde8d","tests/regression/issue520.rs":"d146be3472db902b48127d65fe83aa9f698143aca9074c83cd1a9d5dd28e3ec3","tests/regression/issue795.rs":"582e2e7c68113f05a4b1d2cb556a2df7cc77f2ce8164a32c5cc58ae68abb60ec","tests/regression/issue845.rs":"8bd64588fc344e119d0e9e5e7604236e7c168c574b0692033f15278e216a6b9c","tests/regression/issue953.rs":"b2cddc761f5ca6639900c173765a8a5868528a896924e5e925db2696469208f7","tests/stream.rs":"c7d91014538ecd8f495b196d40e999ab2745f2e69fa2ff9e52521605dc6ce856","tests/test.rs":"b9154ff63261cecd6f04443ce3580d285af16f77cdc2c87239408cb8e06009dc","tests/ui/missing_colon.rs":"d07e0c34d98eb43465f0a0310f2c0b5d5b0d26d243b352a1c6bbe6ad3b27eda9","tests/ui/missing_colon.stderr":"3732fd8f4e57b84efc07170cda5f9c5b2b17c707e23c1659222b5a46f652a8d8","tests/ui/missing_comma.rs":"b8a9662f99c3e6dd2b6417892c37640578ce91d3a8365bf10c1f686a3227aa87","tests/ui/missing_comma.stderr":"eae626cf93c97abd105066e624ca4e8cb096784413b9d2564cf9414a8492bc4d","tests/ui/missing_value.rs":"bca25d67127fb88e7c191c7b03af5a4ce8a9abb630f3d2e6a6c1e77e213dc9a4","tests/ui/missing_value.stderr":"b0df8add5cf74e5df30eedd3ca347e4862c04a01c54d802ff45392f2032065b1","tests/ui/not_found.rs":"d0a7adb309879ff65aee115b52cc33d36f4bad353cf97c4effc34a6128c2bee3","tests/ui/not_found.stderr":"359b751c0c21fab6d460daef4d5f73a265f7769c9b578f98ea3cb6cbf2387643","tests/ui/parse_expr.rs":"32e6d51f528db3d1ab0ed1e24765b865be393565c26f77413c5aa39d601ac563","tests/ui/parse_expr.stderr":"4fcd0a014fbce31c9266bab8527d6e6b6806a0e21d9e0275ce713137856073ce","tests/ui/parse_key.rs":"18829b2af320d5cf8a0a5cd3aaf84c7e92cc874651c30e45a3acafb76c2d8b93","tests/ui/parse_key.stderr":"fcb44e060b804a4762b7291e128c41d7010ffa8ab820b8828fd13fbe6d405ca6","tests/ui/unexpected_after_array_element.rs":"a343fc3104431720bdfcf330bcc3cfcd98c8dec3e951133b495242478b0b7eb3","tests/ui/unexpected_after_array_element.stderr":"8df615998fa3057bb9ed865981a35cdbb771625337048f0ad3fba7734e607adf","tests/ui/unexpected_after_map_entry.rs":"6e3bd2def435ca610e346bbc75cdbaf61963eb2ef1885bb5f76781ba1fac37ef","tests/ui/unexpected_after_map_entry.stderr":"b1985c89075ab48b2158bd1705ed766d37854b3d4620ab257cc8bc319d224f17","tests/ui/unexpected_colon.rs":"a313cff3fed4be4c33f1eda5d0c5c98147fb835a56d36470d9f367352c1d61ef","tests/ui/unexpected_colon.stderr":"b2288742fa6a4a7eb65d2ae899bcfed8795b57bd04958da227d60928a8df26c5","tests/ui/unexpected_comma.rs":"55a8b684bde1ce905837cce719fd457d8898b61cebc27e5b420d05cb6be97256","tests/ui/unexpected_comma.stderr":"4c103ca63ff15e2ca659242cc0eae0612bf050e7580da62f1cf50de8082aa7dc"},"package":"cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"} \ No newline at end of file
+{"files":{"CONTRIBUTING.md":"f5270cafba66223a7b51ffc0d286075a17bb7cd88762fc80d333d3102629f4d8","Cargo.toml":"f8b789a2b436af04913166cb07fcd87927fb4a89c84332f82fd58f84cc3a4e0b","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"f223b99630bae262eb2b88bb95d0f496db8f1ff4e94e43dbfc8d95d3a6c98d8f","build.rs":"9fa36e0b1bb7026b449a20986ae2f60b3046bcbcf3bf22b5c0e372eb892eaf57","src/de.rs":"c423a0534203713b89c3db544d7ea0988b4a913a0501d0d9cb170f6a66d23dd6","src/error.rs":"a9b5de0a82f95608b51b8e8875c7c49f94fb60b9f976fc6277aec0213926dec9","src/io/core.rs":"60ba28f67a9acaecf8964b611efba416b13f9f2bae4befc329fdf0e037293802","src/io/mod.rs":"fd1ed5080495cab21117f6f7d3c2c9e3687cad0c69a0cd087b08a145a9e672da","src/iter.rs":"f832c469cd7999d26ba9b76baa69b257a212a7edb3dfdf9b1d1bb35e8da85fa9","src/lexical/algorithm.rs":"bd6106e5d8875c9ff1c1d57256b459a4f0992d14a0df1a5fffcd3d3cbdccee8c","src/lexical/bhcomp.rs":"b7c68d74c0055eb67ec2c1bcf27bbc28bef8f1bbc43db8eb94ba69892230add6","src/lexical/bignum.rs":"db688e8112389998d0f91906f6857e28f9b510a8b4065ad476c8e8be2f77becf","src/lexical/cached.rs":"0e127398691f8042c19cde209e7f4b0161f0f3150342430145929f711e6fdac8","src/lexical/cached_float80.rs":"0f8f74a22cb7d871322a9893bffd0255ca10bf9dffd13afb2462dd3d7f51805f","src/lexical/digit.rs":"9502805adbc3da059131d1fac0a802e17065b36cd7472606b3af24e3241d5cb8","src/lexical/errors.rs":"3d9f6de6245533bcb101dfd718cfed61d59dc293f6768cedae28aa13ace164f5","src/lexical/exponent.rs":"51f19443008e8884b15c7d5d4b1f1cfbd5673a9d1da02f1af39fcf20e315f01f","src/lexical/float.rs":"fe356213c92a049f4bef2f58bc0e3a26866ca06b8c1d74d0f961c5b883852cad","src/lexical/large_powers.rs":"34537f5c701afce1ec2a1fd3c14950381b2e27c9ad74f002c91f3708e8da9ca5","src/lexical/large_powers32.rs":"c70b57a727960beec258758a4d4a1050f8eaf3b4e60027c663a2bfb0246e0153","src/lexical/large_powers64.rs":"e7af83ce3159b5fc4669fc5a231e767d8af21bacaece52a0a48951198965b197","src/lexical/math.rs":"240804aa030849495fa03a83a0ee8539d5a5c8639b825f2d69d27b7567b06fb3","src/lexical/mod.rs":"4b4c5228779c0f135a4cb018700e3bcd495da48b74421a86f6b8b304acdef924","src/lexical/num.rs":"dd9f4357b8d5bead413844d4015176d484e907e1a393cf7f583de5c5ccafb2e3","src/lexical/parse.rs":"c2bfac4c70a19938ced61e991f4ec606764887cf12bac1a0978b5b5318a56aac","src/lexical/rounding.rs":"4762af3612880b17468ff2a1bb800c8e99f08330ae439699dd53d8dc5463ad13","src/lexical/shift.rs":"bc1ed053dd63d45ac9c35302f18de9f00d94027f28af4ab749c9248439de832a","src/lexical/small_powers.rs":"4608dd218b8002435db7e1ec79d2d0fef5f47ae257b93353326d52ecc80cccda","src/lib.rs":"161e03a3d34254716ed88d6d3b7c7536f646e674263ca71b5930b99c1c06a4ca","src/macros.rs":"516f69976f433bcc5e48c32b3e29c2e0ab7b549810827d7a9c59171cdf11c1e2","src/map.rs":"aeb07107ba949330e72f4d669d46b215990f83aa4055e06d1da69f2a32ddf642","src/number.rs":"537be73fe2f1f4c654a41e0b6461493ca7e3c20265163b3fb3405d047c163c1a","src/raw.rs":"74f5937706324c9325acc42597ff0a226faeaae38d270ab61ba6283e37616c86","src/read.rs":"7e5928c7f71cfa3848966ab6cc0e6596fd0a3e15cf9f2c59675bf920340ab79f","src/ser.rs":"ee5b6cb04c2ff7058b52cb5d0383218f484505ce0896e5c7fd5076bd9d90952e","src/value/de.rs":"890d88303ce0036a5efd1c57378dab7f8c45dabd798cece2248c2d9db52fa011","src/value/from.rs":"add9687e35db3962729d986c8aa54785cadeb07b8b7121cd4075e3a37ecc73a1","src/value/index.rs":"1a0d59629ae16d6553686de8d7152abd470153f67f9a1b69741e480ba491cd67","src/value/mod.rs":"c1b08509df5ae1ffb5c5e148ac29791923c92eb9957935683739a95bef0007e9","src/value/partial_eq.rs":"655fd0bf3ab1d6669444a55ab849f43bb333032de8ca8f1ee95e1068da43ee22","src/value/ser.rs":"d59f959448de1f4115ed62359e7444081741215e7005bcf97f7584b5e31e3b15","tests/compiletest.rs":"022a8e400ef813d7ea1875b944549cee5125f6a995dc33e93b48cba3e1b57bd1","tests/debug.rs":"a8451217c1e127ad6e653ef11e0513525ee350e1e37dd575758a8ee9301b28fb","tests/lexical.rs":"8ee6e617ef62a090de49ac2a930130a6913ab5316100781543c7788f89ef99c2","tests/lexical/algorithm.rs":"da378df9ee24bfa033968d5c94e91b58e52c39bf6c825dec51c3eb7250cc5874","tests/lexical/exponent.rs":"dc8fa8d05e561ff256f8b09385291768c7f45e5ad6cb878ef9194757aa014386","tests/lexical/float.rs":"0440f2d85c993bcccd925096d7f4136bf624ffd66b3c7ee565d158390685eb11","tests/lexical/math.rs":"4874be2103be5fbe8b8015354414df271ffa00fd815546fc077f15fb4d7a5a37","tests/lexical/num.rs":"6e650c40de85ed72ac06b6bf1487ba161f3824e26d827df6cfdf2bbdb8d05a05","tests/lexical/parse.rs":"a11f09bb003a3a024548008cf78bf76526ed71b00077d1989f45eb8cebc93b9c","tests/lexical/rounding.rs":"6c56e39ba534616c1b2146e8efa6eb57aed322e683bf23183cd32a61fae6447e","tests/macros/mod.rs":"93aa1d54af20bc2c55b6ae8db73c1414cda2626eb9fa7bd57b9d613a3c6e6a19","tests/map.rs":"89f604c5788bcb8dc82c82e252dc0da47257986e353c09d14e4ef3e58c455f2d","tests/regression.rs":"86731134bfb9bb693d9a4fc62393027de80a8bf031109ea6c7ea475b1ebdde8d","tests/regression/issue1004.rs":"38d7e3b6c515b881078ebd21ca8063d2ca105cd319695d29538f879e37f091b5","tests/regression/issue520.rs":"f95b362e45c57b431720c48eb47f7ddddf4078195d6859df523dc32950ce980a","tests/regression/issue795.rs":"37ff26744b1f950dd212565c6e3f276268882f7724cc589ac8b21ca8bd608413","tests/regression/issue845.rs":"10d2895cd1412cb6630f0a59db367f79ee672edb501151c7581e9921b5a84b92","tests/regression/issue953.rs":"b2cddc761f5ca6639900c173765a8a5868528a896924e5e925db2696469208f7","tests/stream.rs":"c7d91014538ecd8f495b196d40e999ab2745f2e69fa2ff9e52521605dc6ce856","tests/test.rs":"43cd75d02297758365ce6175a62843fa84fb60f4cdb3c9ed3cbfb752db6fcc68","tests/ui/missing_colon.rs":"d07e0c34d98eb43465f0a0310f2c0b5d5b0d26d243b352a1c6bbe6ad3b27eda9","tests/ui/missing_colon.stderr":"3732fd8f4e57b84efc07170cda5f9c5b2b17c707e23c1659222b5a46f652a8d8","tests/ui/missing_comma.rs":"b8a9662f99c3e6dd2b6417892c37640578ce91d3a8365bf10c1f686a3227aa87","tests/ui/missing_comma.stderr":"eae626cf93c97abd105066e624ca4e8cb096784413b9d2564cf9414a8492bc4d","tests/ui/missing_value.rs":"bca25d67127fb88e7c191c7b03af5a4ce8a9abb630f3d2e6a6c1e77e213dc9a4","tests/ui/missing_value.stderr":"b0df8add5cf74e5df30eedd3ca347e4862c04a01c54d802ff45392f2032065b1","tests/ui/not_found.rs":"d0a7adb309879ff65aee115b52cc33d36f4bad353cf97c4effc34a6128c2bee3","tests/ui/not_found.stderr":"359b751c0c21fab6d460daef4d5f73a265f7769c9b578f98ea3cb6cbf2387643","tests/ui/parse_expr.rs":"32e6d51f528db3d1ab0ed1e24765b865be393565c26f77413c5aa39d601ac563","tests/ui/parse_expr.stderr":"4fcd0a014fbce31c9266bab8527d6e6b6806a0e21d9e0275ce713137856073ce","tests/ui/parse_key.rs":"18829b2af320d5cf8a0a5cd3aaf84c7e92cc874651c30e45a3acafb76c2d8b93","tests/ui/parse_key.stderr":"20cf0d2898749f3c36780fc065f5049ee809e74cb6f0ef776f43f45e01596ee3","tests/ui/unexpected_after_array_element.rs":"a343fc3104431720bdfcf330bcc3cfcd98c8dec3e951133b495242478b0b7eb3","tests/ui/unexpected_after_array_element.stderr":"8df615998fa3057bb9ed865981a35cdbb771625337048f0ad3fba7734e607adf","tests/ui/unexpected_after_map_entry.rs":"6e3bd2def435ca610e346bbc75cdbaf61963eb2ef1885bb5f76781ba1fac37ef","tests/ui/unexpected_after_map_entry.stderr":"b1985c89075ab48b2158bd1705ed766d37854b3d4620ab257cc8bc319d224f17","tests/ui/unexpected_colon.rs":"a313cff3fed4be4c33f1eda5d0c5c98147fb835a56d36470d9f367352c1d61ef","tests/ui/unexpected_colon.stderr":"b2288742fa6a4a7eb65d2ae899bcfed8795b57bd04958da227d60928a8df26c5","tests/ui/unexpected_comma.rs":"55a8b684bde1ce905837cce719fd457d8898b61cebc27e5b420d05cb6be97256","tests/ui/unexpected_comma.stderr":"4c103ca63ff15e2ca659242cc0eae0612bf050e7580da62f1cf50de8082aa7dc"},"package":"3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"} \ No newline at end of file
diff --git a/third_party/rust/serde_json/Cargo.toml b/third_party/rust/serde_json/Cargo.toml
index cff28cd7b2..9941fdd86b 100644
--- a/third_party/rust/serde_json/Cargo.toml
+++ b/third_party/rust/serde_json/Cargo.toml
@@ -10,10 +10,10 @@
# See Cargo.toml.orig for the original contents.
[package]
-edition = "2018"
-rust-version = "1.36"
+edition = "2021"
+rust-version = "1.56"
name = "serde_json"
-version = "1.0.93"
+version = "1.0.116"
authors = [
"Erick Tryzelaar <erick.tryzelaar@gmail.com>",
"David Tolnay <dtolnay@gmail.com>",
@@ -36,14 +36,16 @@ repository = "https://github.com/serde-rs/json"
[package.metadata.docs.rs]
features = [
+ "preserve_order",
"raw_value",
"unbounded_depth",
]
-targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = [
"--cfg",
"docsrs",
+ "--generate-link-to-definition",
]
+targets = ["x86_64-unknown-linux-gnu"]
[package.metadata.playground]
features = ["raw_value"]
@@ -52,8 +54,7 @@ features = ["raw_value"]
doc-scrape-examples = false
[dependencies.indexmap]
-version = "1.5.2"
-features = ["std"]
+version = "2.2.1"
optional = true
[dependencies.itoa]
@@ -63,36 +64,36 @@ version = "1.0"
version = "1.0"
[dependencies.serde]
-version = "1.0.100"
+version = "1.0.194"
default-features = false
[dev-dependencies.automod]
-version = "1.0"
+version = "1.0.11"
[dev-dependencies.indoc]
-version = "2.0"
+version = "2.0.2"
[dev-dependencies.ref-cast]
-version = "1.0"
+version = "1.0.18"
[dev-dependencies.rustversion]
-version = "1.0"
+version = "1.0.13"
[dev-dependencies.serde]
-version = "1.0.100"
+version = "1.0.194"
features = ["derive"]
[dev-dependencies.serde_bytes]
-version = "0.11"
+version = "0.11.10"
[dev-dependencies.serde_derive]
-version = "1.0"
+version = "1.0.166"
[dev-dependencies.serde_stacker]
-version = "0.1"
+version = "0.1.8"
[dev-dependencies.trybuild]
-version = "1.0.49"
+version = "1.0.81"
features = ["diff"]
[features]
diff --git a/third_party/rust/serde_json/README.md b/third_party/rust/serde_json/README.md
index d704979247..be70b7b06d 100644
--- a/third_party/rust/serde_json/README.md
+++ b/third_party/rust/serde_json/README.md
@@ -76,7 +76,7 @@ enum Value {
A string of JSON data can be parsed into a `serde_json::Value` by the
[`serde_json::from_str`][from_str] function. There is also
-[`from_slice`][from_slice] for parsing from a byte slice &[u8] and
+[`from_slice`][from_slice] for parsing from a byte slice `&[u8]` and
[`from_reader`][from_reader] for parsing from any `io::Read` like a File or a
TCP stream.
diff --git a/third_party/rust/serde_json/build.rs b/third_party/rust/serde_json/build.rs
index 0e12602e46..dd09e62a3e 100644
--- a/third_party/rust/serde_json/build.rs
+++ b/third_party/rust/serde_json/build.rs
@@ -1,6 +1,4 @@
use std::env;
-use std::process::Command;
-use std::str::{self, FromStr};
fn main() {
println!("cargo:rerun-if-changed=build.rs");
@@ -9,46 +7,11 @@ fn main() {
// src/lexical/math.rs for where this has an effect.
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
match target_arch.as_str() {
- "aarch64" | "mips64" | "powerpc64" | "x86_64" => {
+ "aarch64" | "mips64" | "powerpc64" | "x86_64" | "loongarch64" => {
println!("cargo:rustc-cfg=limb_width_64");
}
_ => {
println!("cargo:rustc-cfg=limb_width_32");
}
}
-
- let minor = match rustc_minor_version() {
- Some(minor) => minor,
- None => return,
- };
-
- // BTreeMap::get_key_value
- // https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
- if minor < 40 {
- println!("cargo:rustc-cfg=no_btreemap_get_key_value");
- }
-
- // BTreeMap::remove_entry
- // https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
- if minor < 45 {
- println!("cargo:rustc-cfg=no_btreemap_remove_entry");
- }
-
- // BTreeMap::retain
- // https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
- if minor < 53 {
- println!("cargo:rustc-cfg=no_btreemap_retain");
- }
-}
-
-fn rustc_minor_version() -> Option<u32> {
- let rustc = env::var_os("RUSTC")?;
- let output = Command::new(rustc).arg("--version").output().ok()?;
- let version = str::from_utf8(&output.stdout).ok()?;
- let mut pieces = version.split('.');
- if pieces.next() != Some("rustc 1") {
- return None;
- }
- let next = pieces.next()?;
- u32::from_str(next).ok()
}
diff --git a/third_party/rust/serde_json/src/de.rs b/third_party/rust/serde_json/src/de.rs
index 88d0f2624d..c7774f6873 100644
--- a/third_party/rust/serde_json/src/de.rs
+++ b/third_party/rust/serde_json/src/de.rs
@@ -22,6 +22,7 @@ use crate::number::NumberDeserializer;
pub use crate::read::{Read, SliceRead, StrRead};
#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub use crate::read::IoRead;
//////////////////////////////////////////////////////////////////////////////
@@ -209,7 +210,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.disable_recursion_limit = true;
}
- fn peek(&mut self) -> Result<Option<u8>> {
+ pub(crate) fn peek(&mut self) -> Result<Option<u8>> {
self.read.peek()
}
@@ -248,7 +249,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
fn parse_whitespace(&mut self) -> Result<Option<u8>> {
loop {
match tri!(self.peek()) {
- Some(b' ') | Some(b'\n') | Some(b'\t') | Some(b'\r') => {
+ Some(b' ' | b'\n' | b'\t' | b'\r') => {
self.eat_char();
}
other => {
@@ -309,9 +310,9 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.fix_position(err)
}
- fn deserialize_number<V>(&mut self, visitor: V) -> Result<V::Value>
+ pub(crate) fn deserialize_number<'any, V>(&mut self, visitor: V) -> Result<V::Value>
where
- V: de::Visitor<'de>,
+ V: de::Visitor<'any>,
{
let peek = match tri!(self.parse_whitespace()) {
Some(b) => b,
@@ -335,6 +336,79 @@ impl<'de, R: Read<'de>> Deserializer<R> {
}
}
+ #[cfg(feature = "float_roundtrip")]
+ pub(crate) fn do_deserialize_f32<'any, V>(&mut self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'any>,
+ {
+ self.single_precision = true;
+ let val = self.deserialize_number(visitor);
+ self.single_precision = false;
+ val
+ }
+
+ pub(crate) fn do_deserialize_i128<'any, V>(&mut self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'any>,
+ {
+ let mut buf = String::new();
+
+ match tri!(self.parse_whitespace()) {
+ Some(b'-') => {
+ self.eat_char();
+ buf.push('-');
+ }
+ Some(_) => {}
+ None => {
+ return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
+ }
+ };
+
+ tri!(self.scan_integer128(&mut buf));
+
+ let value = match buf.parse() {
+ Ok(int) => visitor.visit_i128(int),
+ Err(_) => {
+ return Err(self.error(ErrorCode::NumberOutOfRange));
+ }
+ };
+
+ match value {
+ Ok(value) => Ok(value),
+ Err(err) => Err(self.fix_position(err)),
+ }
+ }
+
+ pub(crate) fn do_deserialize_u128<'any, V>(&mut self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'any>,
+ {
+ match tri!(self.parse_whitespace()) {
+ Some(b'-') => {
+ return Err(self.peek_error(ErrorCode::NumberOutOfRange));
+ }
+ Some(_) => {}
+ None => {
+ return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
+ }
+ }
+
+ let mut buf = String::new();
+ tri!(self.scan_integer128(&mut buf));
+
+ let value = match buf.parse() {
+ Ok(int) => visitor.visit_u128(int),
+ Err(_) => {
+ return Err(self.error(ErrorCode::NumberOutOfRange));
+ }
+ };
+
+ match value {
+ Ok(value) => Ok(value),
+ Err(err) => Err(self.fix_position(err)),
+ }
+ }
+
fn scan_integer128(&mut self, buf: &mut String) -> Result<()> {
match tri!(self.next_char_or_null()) {
b'0' => {
@@ -407,7 +481,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
// try to keep the number as a `u64` until we grow
// too large. At that point, switch to parsing the
// value as a `f64`.
- if overflow!(significand * 10 + digit, u64::max_value()) {
+ if overflow!(significand * 10 + digit, u64::MAX) {
return Ok(ParserNumber::F64(tri!(
self.parse_long_integer(positive, significand),
)));
@@ -459,7 +533,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
let digit = (c - b'0') as u64;
- if overflow!(significand * 10 + digit, u64::max_value()) {
+ if overflow!(significand * 10 + digit, u64::MAX) {
let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
return self.parse_decimal_overflow(positive, significand, exponent);
}
@@ -523,7 +597,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
let digit = (c - b'0') as i32;
- if overflow!(exp * 10 + digit, i32::max_value()) {
+ if overflow!(exp * 10 + digit, i32::MAX) {
let zero_significand = significand == 0;
return self.parse_exponent_overflow(positive, zero_significand, positive_exp);
}
@@ -715,7 +789,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
let digit = (c - b'0') as i32;
- if overflow!(exp * 10 + digit, i32::max_value()) {
+ if overflow!(exp * 10 + digit, i32::MAX) {
let zero_significand = self.scratch.iter().all(|&digit| digit == b'0');
return self.parse_exponent_overflow(positive, zero_significand, positive_exp);
}
@@ -860,7 +934,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
if !positive {
buf.push('-');
}
- self.scan_integer(&mut buf)?;
+ tri!(self.scan_integer(&mut buf));
if positive {
if let Ok(unsigned) = buf.parse() {
return Ok(ParserNumber::U64(unsigned));
@@ -913,7 +987,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
fn scan_number(&mut self, buf: &mut String) -> Result<()> {
match tri!(self.peek_or_null()) {
b'.' => self.scan_decimal(buf),
- e @ b'e' | e @ b'E' => self.scan_exponent(e as char, buf),
+ e @ (b'e' | b'E') => self.scan_exponent(e as char, buf),
_ => Ok(()),
}
}
@@ -938,7 +1012,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
}
match tri!(self.peek_or_null()) {
- e @ b'e' | e @ b'E' => self.scan_exponent(e as char, buf),
+ e @ (b'e' | b'E') => self.scan_exponent(e as char, buf),
_ => Ok(()),
}
}
@@ -1059,7 +1133,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
tri!(self.read.ignore_str());
None
}
- frame @ b'[' | frame @ b'{' => {
+ frame @ (b'[' | b'{') => {
self.scratch.extend(enclosing.take());
self.eat_char();
Some(frame)
@@ -1204,9 +1278,9 @@ impl<'de, R: Read<'de>> Deserializer<R> {
where
V: de::Visitor<'de>,
{
- self.parse_whitespace()?;
+ tri!(self.parse_whitespace());
self.read.begin_raw_buffering();
- self.ignore_value()?;
+ tri!(self.ignore_value());
self.read.end_raw_buffering(visitor)
}
}
@@ -1258,11 +1332,15 @@ static POW10: [f64; 309] = [
macro_rules! deserialize_number {
($method:ident) => {
+ deserialize_number!($method, deserialize_number);
+ };
+
+ ($method:ident, $using:ident) => {
fn $method<V>(self, visitor: V) -> Result<V::Value>
where
V: de::Visitor<'de>,
{
- self.deserialize_number(visitor)
+ self.$using(visitor)
}
};
}
@@ -1424,77 +1502,9 @@ impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
deserialize_number!(deserialize_f64);
#[cfg(feature = "float_roundtrip")]
- fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>
- where
- V: de::Visitor<'de>,
- {
- self.single_precision = true;
- let val = self.deserialize_number(visitor);
- self.single_precision = false;
- val
- }
-
- fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value>
- where
- V: de::Visitor<'de>,
- {
- let mut buf = String::new();
-
- match tri!(self.parse_whitespace()) {
- Some(b'-') => {
- self.eat_char();
- buf.push('-');
- }
- Some(_) => {}
- None => {
- return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
- }
- };
-
- tri!(self.scan_integer128(&mut buf));
-
- let value = match buf.parse() {
- Ok(int) => visitor.visit_i128(int),
- Err(_) => {
- return Err(self.error(ErrorCode::NumberOutOfRange));
- }
- };
-
- match value {
- Ok(value) => Ok(value),
- Err(err) => Err(self.fix_position(err)),
- }
- }
-
- fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value>
- where
- V: de::Visitor<'de>,
- {
- match tri!(self.parse_whitespace()) {
- Some(b'-') => {
- return Err(self.peek_error(ErrorCode::NumberOutOfRange));
- }
- Some(_) => {}
- None => {
- return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
- }
- }
-
- let mut buf = String::new();
- tri!(self.scan_integer128(&mut buf));
-
- let value = match buf.parse() {
- Ok(int) => visitor.visit_u128(int),
- Err(_) => {
- return Err(self.error(ErrorCode::NumberOutOfRange));
- }
- };
-
- match value {
- Ok(value) => Ok(value),
- Err(err) => Err(self.fix_position(err)),
- }
- }
+ deserialize_number!(deserialize_f32, do_deserialize_f32);
+ deserialize_number!(deserialize_i128, do_deserialize_i128);
+ deserialize_number!(deserialize_u128, do_deserialize_u128);
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value>
where
@@ -2118,24 +2128,47 @@ struct MapKey<'a, R: 'a> {
de: &'a mut Deserializer<R>,
}
-macro_rules! deserialize_integer_key {
- ($method:ident => $visit:ident) => {
+macro_rules! deserialize_numeric_key {
+ ($method:ident) => {
+ fn $method<V>(self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'de>,
+ {
+ self.deserialize_number(visitor)
+ }
+ };
+
+ ($method:ident, $delegate:ident) => {
fn $method<V>(self, visitor: V) -> Result<V::Value>
where
V: de::Visitor<'de>,
{
self.de.eat_char();
- self.de.scratch.clear();
- let string = tri!(self.de.read.parse_str(&mut self.de.scratch));
- match (string.parse(), string) {
- (Ok(integer), _) => visitor.$visit(integer),
- (Err(_), Reference::Borrowed(s)) => visitor.visit_borrowed_str(s),
- (Err(_), Reference::Copied(s)) => visitor.visit_str(s),
+
+ match tri!(self.de.peek()) {
+ Some(b'0'..=b'9' | b'-') => {}
+ _ => return Err(self.de.error(ErrorCode::ExpectedNumericKey)),
+ }
+
+ let value = tri!(self.de.$delegate(visitor));
+
+ match tri!(self.de.peek()) {
+ Some(b'"') => self.de.eat_char(),
+ _ => return Err(self.de.peek_error(ErrorCode::ExpectedDoubleQuote)),
}
+
+ Ok(value)
}
};
}
+impl<'de, 'a, R> MapKey<'a, R>
+where
+ R: Read<'de>,
+{
+ deserialize_numeric_key!(deserialize_number, deserialize_number);
+}
+
impl<'de, 'a, R> de::Deserializer<'de> for MapKey<'a, R>
where
R: Read<'de>,
@@ -2155,16 +2188,56 @@ where
}
}
- deserialize_integer_key!(deserialize_i8 => visit_i8);
- deserialize_integer_key!(deserialize_i16 => visit_i16);
- deserialize_integer_key!(deserialize_i32 => visit_i32);
- deserialize_integer_key!(deserialize_i64 => visit_i64);
- deserialize_integer_key!(deserialize_i128 => visit_i128);
- deserialize_integer_key!(deserialize_u8 => visit_u8);
- deserialize_integer_key!(deserialize_u16 => visit_u16);
- deserialize_integer_key!(deserialize_u32 => visit_u32);
- deserialize_integer_key!(deserialize_u64 => visit_u64);
- deserialize_integer_key!(deserialize_u128 => visit_u128);
+ deserialize_numeric_key!(deserialize_i8);
+ deserialize_numeric_key!(deserialize_i16);
+ deserialize_numeric_key!(deserialize_i32);
+ deserialize_numeric_key!(deserialize_i64);
+ deserialize_numeric_key!(deserialize_i128, deserialize_i128);
+ deserialize_numeric_key!(deserialize_u8);
+ deserialize_numeric_key!(deserialize_u16);
+ deserialize_numeric_key!(deserialize_u32);
+ deserialize_numeric_key!(deserialize_u64);
+ deserialize_numeric_key!(deserialize_u128, deserialize_u128);
+ #[cfg(not(feature = "float_roundtrip"))]
+ deserialize_numeric_key!(deserialize_f32);
+ #[cfg(feature = "float_roundtrip")]
+ deserialize_numeric_key!(deserialize_f32, deserialize_f32);
+ deserialize_numeric_key!(deserialize_f64);
+
+ fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'de>,
+ {
+ self.de.eat_char();
+
+ let peek = match tri!(self.de.next_char()) {
+ Some(b) => b,
+ None => {
+ return Err(self.de.peek_error(ErrorCode::EofWhileParsingValue));
+ }
+ };
+
+ let value = match peek {
+ b't' => {
+ tri!(self.de.parse_ident(b"rue\""));
+ visitor.visit_bool(true)
+ }
+ b'f' => {
+ tri!(self.de.parse_ident(b"alse\""));
+ visitor.visit_bool(false)
+ }
+ _ => {
+ self.de.scratch.clear();
+ let s = tri!(self.de.read.parse_str(&mut self.de.scratch));
+ Err(de::Error::invalid_type(Unexpected::Str(&s), &visitor))
+ }
+ };
+
+ match value {
+ Ok(value) => Ok(value),
+ Err(err) => Err(self.de.fix_position(err)),
+ }
+ }
#[inline]
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>
@@ -2221,8 +2294,8 @@ where
}
forward_to_deserialize_any! {
- bool f32 f64 char str string unit unit_struct seq tuple tuple_struct map
- struct identifier ignored_any
+ char str string unit unit_struct seq tuple tuple_struct map struct
+ identifier ignored_any
}
}
@@ -2318,8 +2391,8 @@ where
fn peek_end_of_value(&mut self) -> Result<()> {
match tri!(self.de.peek()) {
- Some(b' ') | Some(b'\n') | Some(b'\t') | Some(b'\r') | Some(b'"') | Some(b'[')
- | Some(b']') | Some(b'{') | Some(b'}') | Some(b',') | Some(b':') | None => Ok(()),
+ Some(b' ' | b'\n' | b'\t' | b'\r' | b'"' | b'[' | b']' | b'{' | b'}' | b',' | b':')
+ | None => Ok(()),
Some(_) => {
let position = self.de.read.peek_position();
Err(Error::syntax(
@@ -2369,7 +2442,7 @@ where
if self_delineated_value {
Ok(value)
} else {
- self.peek_end_of_value().map(|_| value)
+ self.peek_end_of_value().map(|()| value)
}
}
Err(e) => {
@@ -2408,9 +2481,9 @@ where
Ok(value)
}
-/// Deserialize an instance of type `T` from an IO stream of JSON.
+/// Deserialize an instance of type `T` from an I/O stream of JSON.
///
-/// The content of the IO stream is deserialized directly from the stream
+/// The content of the I/O stream is deserialized directly from the stream
/// without being buffered in memory by serde_json.
///
/// When reading from a source against which short reads are not efficient, such
diff --git a/third_party/rust/serde_json/src/error.rs b/third_party/rust/serde_json/src/error.rs
index 1875ef08b0..fbf9eb14e5 100644
--- a/third_party/rust/serde_json/src/error.rs
+++ b/third_party/rust/serde_json/src/error.rs
@@ -9,6 +9,8 @@ use core::str::FromStr;
use serde::{de, ser};
#[cfg(feature = "std")]
use std::error;
+#[cfg(feature = "std")]
+use std::io::ErrorKind;
/// This type represents all possible errors that can occur when serializing or
/// deserializing JSON data.
@@ -36,15 +38,16 @@ impl Error {
/// The first character in the input and any characters immediately
/// following a newline character are in column 1.
///
- /// Note that errors may occur in column 0, for example if a read from an IO
- /// stream fails immediately following a previously read newline character.
+ /// Note that errors may occur in column 0, for example if a read from an
+ /// I/O stream fails immediately following a previously read newline
+ /// character.
pub fn column(&self) -> usize {
self.err.column
}
/// Categorizes the cause of this error.
///
- /// - `Category::Io` - failure to read or write bytes on an IO stream
+ /// - `Category::Io` - failure to read or write bytes on an I/O stream
/// - `Category::Syntax` - input that is not syntactically valid JSON
/// - `Category::Data` - input data that is semantically incorrect
/// - `Category::Eof` - unexpected end of the input data
@@ -61,12 +64,15 @@ impl Error {
| ErrorCode::ExpectedObjectCommaOrEnd
| ErrorCode::ExpectedSomeIdent
| ErrorCode::ExpectedSomeValue
+ | ErrorCode::ExpectedDoubleQuote
| ErrorCode::InvalidEscape
| ErrorCode::InvalidNumber
| ErrorCode::NumberOutOfRange
| ErrorCode::InvalidUnicodeCodePoint
| ErrorCode::ControlCharacterWhileParsingString
| ErrorCode::KeyMustBeAString
+ | ErrorCode::ExpectedNumericKey
+ | ErrorCode::FloatKeyMustBeFinite
| ErrorCode::LoneLeadingSurrogateInHexEscape
| ErrorCode::TrailingComma
| ErrorCode::TrailingCharacters
@@ -76,7 +82,7 @@ impl Error {
}
/// Returns true if this error was caused by a failure to read or write
- /// bytes on an IO stream.
+ /// bytes on an I/O stream.
pub fn is_io(&self) -> bool {
self.classify() == Category::Io
}
@@ -104,12 +110,61 @@ impl Error {
pub fn is_eof(&self) -> bool {
self.classify() == Category::Eof
}
+
+ /// The kind reported by the underlying standard library I/O error, if this
+ /// error was caused by a failure to read or write bytes on an I/O stream.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use serde_json::Value;
+ /// use std::io::{self, ErrorKind, Read};
+ /// use std::process;
+ ///
+ /// struct ReaderThatWillTimeOut<'a>(&'a [u8]);
+ ///
+ /// impl<'a> Read for ReaderThatWillTimeOut<'a> {
+ /// fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ /// if self.0.is_empty() {
+ /// Err(io::Error::new(ErrorKind::TimedOut, "timed out"))
+ /// } else {
+ /// self.0.read(buf)
+ /// }
+ /// }
+ /// }
+ ///
+ /// fn main() {
+ /// let reader = ReaderThatWillTimeOut(br#" {"k": "#);
+ ///
+ /// let _: Value = match serde_json::from_reader(reader) {
+ /// Ok(value) => value,
+ /// Err(error) => {
+ /// if error.io_error_kind() == Some(ErrorKind::TimedOut) {
+ /// // Maybe this application needs to retry certain kinds of errors.
+ ///
+ /// # return;
+ /// } else {
+ /// eprintln!("error: {}", error);
+ /// process::exit(1);
+ /// }
+ /// }
+ /// };
+ /// }
+ /// ```
+ #[cfg(feature = "std")]
+ pub fn io_error_kind(&self) -> Option<ErrorKind> {
+ if let ErrorCode::Io(io_error) = &self.err.code {
+ Some(io_error.kind())
+ } else {
+ None
+ }
+ }
}
/// Categorizes the cause of a `serde_json::Error`.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Category {
- /// The error was caused by a failure to read or write bytes on an IO
+ /// The error was caused by a failure to read or write bytes on an I/O
/// stream.
Io,
@@ -134,8 +189,8 @@ pub enum Category {
impl From<Error> for io::Error {
/// Convert a `serde_json::Error` into an `io::Error`.
///
- /// JSON syntax and data errors are turned into `InvalidData` IO errors.
- /// EOF errors are turned into `UnexpectedEof` IO errors.
+ /// JSON syntax and data errors are turned into `InvalidData` I/O errors.
+ /// EOF errors are turned into `UnexpectedEof` I/O errors.
///
/// ```
/// use std::io;
@@ -165,8 +220,8 @@ impl From<Error> for io::Error {
} else {
match j.classify() {
Category::Io => unreachable!(),
- Category::Syntax | Category::Data => io::Error::new(io::ErrorKind::InvalidData, j),
- Category::Eof => io::Error::new(io::ErrorKind::UnexpectedEof, j),
+ Category::Syntax | Category::Data => io::Error::new(ErrorKind::InvalidData, j),
+ Category::Eof => io::Error::new(ErrorKind::UnexpectedEof, j),
}
}
}
@@ -182,7 +237,7 @@ pub(crate) enum ErrorCode {
/// Catchall for syntax error messages
Message(Box<str>),
- /// Some IO error occurred while serializing or deserializing.
+ /// Some I/O error occurred while serializing or deserializing.
Io(io::Error),
/// EOF while parsing a list.
@@ -212,6 +267,9 @@ pub(crate) enum ErrorCode {
/// Expected this character to start a JSON value.
ExpectedSomeValue,
+ /// Expected this character to be a `"`.
+ ExpectedDoubleQuote,
+
/// Invalid hex escape code.
InvalidEscape,
@@ -230,6 +288,12 @@ pub(crate) enum ErrorCode {
/// Object key is not a string.
KeyMustBeAString,
+ /// Contents of key were supposed to be a number.
+ ExpectedNumericKey,
+
+ /// Object key is a non-finite float value.
+ FloatKeyMustBeFinite,
+
/// Lone leading surrogate in hex escape.
LoneLeadingSurrogateInHexEscape,
@@ -296,6 +360,7 @@ impl Display for ErrorCode {
ErrorCode::ExpectedObjectCommaOrEnd => f.write_str("expected `,` or `}`"),
ErrorCode::ExpectedSomeIdent => f.write_str("expected ident"),
ErrorCode::ExpectedSomeValue => f.write_str("expected value"),
+ ErrorCode::ExpectedDoubleQuote => f.write_str("expected `\"`"),
ErrorCode::InvalidEscape => f.write_str("invalid escape"),
ErrorCode::InvalidNumber => f.write_str("invalid number"),
ErrorCode::NumberOutOfRange => f.write_str("number out of range"),
@@ -304,6 +369,12 @@ impl Display for ErrorCode {
f.write_str("control character (\\u0000-\\u001F) found while parsing a string")
}
ErrorCode::KeyMustBeAString => f.write_str("key must be a string"),
+ ErrorCode::ExpectedNumericKey => {
+ f.write_str("invalid value: expected key to be a number in quotes")
+ }
+ ErrorCode::FloatKeyMustBeFinite => {
+ f.write_str("float key must be finite (got NaN or +/-inf)")
+ }
ErrorCode::LoneLeadingSurrogateInHexEscape => {
f.write_str("lone leading surrogate in hex escape")
}
@@ -319,7 +390,7 @@ impl serde::de::StdError for Error {
#[cfg(feature = "std")]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match &self.err.code {
- ErrorCode::Io(err) => Some(err),
+ ErrorCode::Io(err) => err.source(),
_ => None,
}
}
@@ -367,11 +438,20 @@ impl de::Error for Error {
#[cold]
fn invalid_type(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self {
- if let de::Unexpected::Unit = unexp {
- Error::custom(format_args!("invalid type: null, expected {}", exp))
- } else {
- Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
- }
+ Error::custom(format_args!(
+ "invalid type: {}, expected {}",
+ JsonUnexpected(unexp),
+ exp,
+ ))
+ }
+
+ #[cold]
+ fn invalid_value(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self {
+ Error::custom(format_args!(
+ "invalid value: {}, expected {}",
+ JsonUnexpected(unexp),
+ exp,
+ ))
}
}
@@ -382,6 +462,22 @@ impl ser::Error for Error {
}
}
+struct JsonUnexpected<'a>(de::Unexpected<'a>);
+
+impl<'a> Display for JsonUnexpected<'a> {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ match self.0 {
+ de::Unexpected::Unit => formatter.write_str("null"),
+ de::Unexpected::Float(value) => write!(
+ formatter,
+ "floating point `{}`",
+ ryu::Buffer::new().format(value),
+ ),
+ unexp => Display::fmt(&unexp, formatter),
+ }
+ }
+}
+
// Parse our own error message that looks like "{} at line {} column {}" to work
// around erased-serde round-tripping the error through de::Error::custom.
fn make_error(mut msg: String) -> Error {
diff --git a/third_party/rust/serde_json/src/features_check/error.rs b/third_party/rust/serde_json/src/features_check/error.rs
deleted file mode 100644
index 22e58235c7..0000000000
--- a/third_party/rust/serde_json/src/features_check/error.rs
+++ /dev/null
@@ -1 +0,0 @@
-"serde_json requires that either `std` (default) or `alloc` feature is enabled"
diff --git a/third_party/rust/serde_json/src/features_check/mod.rs b/third_party/rust/serde_json/src/features_check/mod.rs
deleted file mode 100644
index d12032cef8..0000000000
--- a/third_party/rust/serde_json/src/features_check/mod.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//! Shows a user-friendly compiler error on incompatible selected features.
-
-#[allow(unused_macros)]
-macro_rules! hide_from_rustfmt {
- ($mod:item) => {
- $mod
- };
-}
-
-#[cfg(not(any(feature = "std", feature = "alloc")))]
-hide_from_rustfmt! {
- mod error;
-}
diff --git a/third_party/rust/serde_json/src/io/core.rs b/third_party/rust/serde_json/src/io/core.rs
index 465ab8b249..54c8ddfda4 100644
--- a/third_party/rust/serde_json/src/io/core.rs
+++ b/third_party/rust/serde_json/src/io/core.rs
@@ -9,7 +9,7 @@ pub enum ErrorKind {
Other,
}
-// IO errors can never occur in no-std mode. All our no-std IO implementations
+// I/O errors can never occur in no-std mode. All our no-std I/O implementations
// are infallible.
pub struct Error;
diff --git a/third_party/rust/serde_json/src/lexical/algorithm.rs b/third_party/rust/serde_json/src/lexical/algorithm.rs
index a2cbf18aff..eaa5e7ebc2 100644
--- a/third_party/rust/serde_json/src/lexical/algorithm.rs
+++ b/third_party/rust/serde_json/src/lexical/algorithm.rs
@@ -51,7 +51,10 @@ where
// Compute the product of the power, if it overflows,
// prematurely return early, otherwise, if we didn't overshoot,
// we can get an exact value.
- let value = mantissa.checked_mul(power)?;
+ let value = match mantissa.checked_mul(power) {
+ None => return None,
+ Some(value) => value,
+ };
if value >> mantissa_size != 0 {
None
} else {
diff --git a/third_party/rust/serde_json/src/lexical/bignum.rs b/third_party/rust/serde_json/src/lexical/bignum.rs
index f9551f534f..4fa7eed6dd 100644
--- a/third_party/rust/serde_json/src/lexical/bignum.rs
+++ b/third_party/rust/serde_json/src/lexical/bignum.rs
@@ -3,6 +3,7 @@
//! Big integer type definition.
use super::math::*;
+#[allow(unused_imports)]
use alloc::vec::Vec;
/// Storage for a big integer type.
diff --git a/third_party/rust/serde_json/src/lexical/digit.rs b/third_party/rust/serde_json/src/lexical/digit.rs
index 882aa9eef2..3d150a1afe 100644
--- a/third_party/rust/serde_json/src/lexical/digit.rs
+++ b/third_party/rust/serde_json/src/lexical/digit.rs
@@ -11,5 +11,8 @@ pub(crate) fn to_digit(c: u8) -> Option<u32> {
// Add digit to mantissa.
#[inline]
pub(crate) fn add_digit(value: u64, digit: u32) -> Option<u64> {
- value.checked_mul(10)?.checked_add(digit as u64)
+ match value.checked_mul(10) {
+ None => None,
+ Some(n) => n.checked_add(digit as u64),
+ }
}
diff --git a/third_party/rust/serde_json/src/lexical/errors.rs b/third_party/rust/serde_json/src/lexical/errors.rs
index cad4bd3d58..f4f41cdc5a 100644
--- a/third_party/rust/serde_json/src/lexical/errors.rs
+++ b/third_party/rust/serde_json/src/lexical/errors.rs
@@ -5,8 +5,7 @@
//! This estimates the error in a floating-point representation.
//!
//! This implementation is loosely based off the Golang implementation,
-//! found here:
-//! https://golang.org/src/strconv/atof.go
+//! found here: <https://golang.org/src/strconv/atof.go>
use super::float::*;
use super::num::*;
diff --git a/third_party/rust/serde_json/src/lexical/exponent.rs b/third_party/rust/serde_json/src/lexical/exponent.rs
index 6fc51977ed..5e27de893f 100644
--- a/third_party/rust/serde_json/src/lexical/exponent.rs
+++ b/third_party/rust/serde_json/src/lexical/exponent.rs
@@ -8,8 +8,8 @@
/// the mantissa we do not overflow for comically-long exponents.
#[inline]
fn into_i32(value: usize) -> i32 {
- if value > i32::max_value() as usize {
- i32::max_value()
+ if value > i32::MAX as usize {
+ i32::MAX
} else {
value as i32
}
diff --git a/third_party/rust/serde_json/src/lexical/large_powers32.rs b/third_party/rust/serde_json/src/lexical/large_powers32.rs
index 7991197262..eb8582f5f0 100644
--- a/third_party/rust/serde_json/src/lexical/large_powers32.rs
+++ b/third_party/rust/serde_json/src/lexical/large_powers32.rs
@@ -2,7 +2,7 @@
//! Precalculated large powers for 32-bit limbs.
-/// Large powers (&[u32]) for base5 operations.
+/// Large powers (`&[u32]`) for base5 operations.
const POW5_1: [u32; 1] = [5];
const POW5_2: [u32; 1] = [25];
const POW5_3: [u32; 1] = [625];
diff --git a/third_party/rust/serde_json/src/lexical/large_powers64.rs b/third_party/rust/serde_json/src/lexical/large_powers64.rs
index ee36561088..96554eac1c 100644
--- a/third_party/rust/serde_json/src/lexical/large_powers64.rs
+++ b/third_party/rust/serde_json/src/lexical/large_powers64.rs
@@ -2,7 +2,7 @@
//! Precalculated large powers for 64-bit limbs.
-/// Large powers (&[u64]) for base5 operations.
+/// Large powers (`&[u64]`) for base5 operations.
const POW5_1: [u64; 1] = [5];
const POW5_2: [u64; 1] = [25];
const POW5_3: [u64; 1] = [625];
diff --git a/third_party/rust/serde_json/src/lexical/math.rs b/third_party/rust/serde_json/src/lexical/math.rs
index 37cc1d24ad..d7122bffaf 100644
--- a/third_party/rust/serde_json/src/lexical/math.rs
+++ b/third_party/rust/serde_json/src/lexical/math.rs
@@ -336,7 +336,7 @@ mod small {
pub fn imul(x: &mut Vec<Limb>, y: Limb) {
// Multiply iteratively over all elements, adding the carry each time.
let mut carry: Limb = 0;
- for xi in x.iter_mut() {
+ for xi in &mut *x {
carry = scalar::imul(xi, y, carry);
}
@@ -482,7 +482,7 @@ mod small {
let rshift = bits - n;
let lshift = n;
let mut prev: Limb = 0;
- for xi in x.iter_mut() {
+ for xi in &mut *x {
let tmp = *xi;
*xi <<= lshift;
*xi |= prev >> rshift;
diff --git a/third_party/rust/serde_json/src/lexical/num.rs b/third_party/rust/serde_json/src/lexical/num.rs
index e47e003419..75eee01b81 100644
--- a/third_party/rust/serde_json/src/lexical/num.rs
+++ b/third_party/rust/serde_json/src/lexical/num.rs
@@ -223,7 +223,7 @@ pub trait Float: Number {
const NEGATIVE_INFINITY_BITS: Self::Unsigned;
/// Size of the significand (mantissa) without hidden bit.
const MANTISSA_SIZE: i32;
- /// Bias of the exponet
+ /// Bias of the exponent
const EXPONENT_BIAS: i32;
/// Exponent portion of a denormal float.
const DENORMAL_EXPONENT: i32;
@@ -248,7 +248,6 @@ pub trait Float: Number {
fn from_bits(u: Self::Unsigned) -> Self;
fn to_bits(self) -> Self::Unsigned;
fn is_sign_positive(self) -> bool;
- fn is_sign_negative(self) -> bool;
/// Returns true if the float is a denormal.
#[inline]
@@ -368,11 +367,6 @@ impl Float for f32 {
fn is_sign_positive(self) -> bool {
f32::is_sign_positive(self)
}
-
- #[inline]
- fn is_sign_negative(self) -> bool {
- f32::is_sign_negative(self)
- }
}
impl Float for f64 {
@@ -432,9 +426,4 @@ impl Float for f64 {
fn is_sign_positive(self) -> bool {
f64::is_sign_positive(self)
}
-
- #[inline]
- fn is_sign_negative(self) -> bool {
- f64::is_sign_negative(self)
- }
}
diff --git a/third_party/rust/serde_json/src/lexical/rounding.rs b/third_party/rust/serde_json/src/lexical/rounding.rs
index 6ec1292aa5..6344875227 100644
--- a/third_party/rust/serde_json/src/lexical/rounding.rs
+++ b/third_party/rust/serde_json/src/lexical/rounding.rs
@@ -25,7 +25,7 @@ pub(crate) fn lower_n_mask(n: u64) -> u64 {
debug_assert!(n <= bits, "lower_n_mask() overflow in shl.");
if n == bits {
- u64::max_value()
+ u64::MAX
} else {
(1 << n) - 1
}
diff --git a/third_party/rust/serde_json/src/lib.rs b/third_party/rust/serde_json/src/lib.rs
index 48d0fe2191..eabd169f53 100644
--- a/third_party/rust/serde_json/src/lib.rs
+++ b/third_party/rust/serde_json/src/lib.rs
@@ -55,10 +55,9 @@
//! ```
//!
//! A string of JSON data can be parsed into a `serde_json::Value` by the
-//! [`serde_json::from_str`][from_str] function. There is also
-//! [`from_slice`][from_slice] for parsing from a byte slice &[u8] and
-//! [`from_reader`][from_reader] for parsing from any `io::Read` like a File or
-//! a TCP stream.
+//! [`serde_json::from_str`][from_str] function. There is also [`from_slice`]
+//! for parsing from a byte slice `&[u8]` and [`from_reader`] for parsing from
+//! any `io::Read` like a File or a TCP stream.
//!
//! ```
//! use serde_json::{Result, Value};
@@ -300,7 +299,7 @@
//! [macro]: crate::json
//! [`serde-json-core`]: https://github.com/rust-embedded-community/serde-json-core
-#![doc(html_root_url = "https://docs.rs/serde_json/1.0.93")]
+#![doc(html_root_url = "https://docs.rs/serde_json/1.0.116")]
// Ignored clippy lints
#![allow(
clippy::collapsible_else_if,
@@ -315,18 +314,13 @@
clippy::match_single_binding,
clippy::needless_doctest_main,
clippy::needless_late_init,
- // clippy bug: https://github.com/rust-lang/rust-clippy/issues/8366
- clippy::ptr_arg,
clippy::return_self_not_must_use,
clippy::transmute_ptr_to_ptr,
- clippy::unnecessary_wraps,
- // clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
- clippy::unnested_or_patterns,
+ clippy::unconditional_recursion, // https://github.com/rust-lang/rust-clippy/issues/12133
+ clippy::unnecessary_wraps
)]
// Ignored clippy_pedantic lints
#![allow(
- // buggy
- clippy::iter_not_returning_iterator, // https://github.com/rust-lang/rust-clippy/issues/8285
// Deserializer::from_str, into_iter
clippy::should_implement_trait,
// integer and float ser/de requires these sorts of casts
@@ -338,6 +332,7 @@
clippy::enum_glob_use,
clippy::if_not_else,
clippy::integer_division,
+ clippy::let_underscore_untyped,
clippy::map_err_ignore,
clippy::match_same_arms,
clippy::similar_names,
@@ -361,14 +356,25 @@
clippy::missing_errors_doc,
clippy::must_use_candidate,
)]
+// Restrictions
+#![deny(clippy::question_mark_used)]
#![allow(non_upper_case_globals)]
#![deny(missing_docs)]
-#![cfg_attr(not(feature = "std"), no_std)]
+#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
+#[cfg(not(any(feature = "std", feature = "alloc")))]
+compile_error! {
+ "serde_json requires that either `std` (default) or `alloc` feature is enabled"
+}
+
extern crate alloc;
#[cfg(feature = "std")]
+extern crate std;
+
+#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[doc(inline)]
pub use crate::de::from_reader;
#[doc(inline)]
@@ -378,6 +384,7 @@ pub use crate::error::{Error, Result};
#[doc(inline)]
pub use crate::ser::{to_string, to_string_pretty, to_vec, to_vec_pretty};
#[cfg(feature = "std")]
+#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[doc(inline)]
pub use crate::ser::{to_writer, to_writer_pretty, Serializer};
#[doc(inline)]
@@ -407,8 +414,6 @@ pub mod ser;
mod ser;
pub mod value;
-mod features_check;
-
mod io;
#[cfg(feature = "std")]
mod iter;
diff --git a/third_party/rust/serde_json/src/macros.rs b/third_party/rust/serde_json/src/macros.rs
index 5287998b46..e8c6cd2ca4 100644
--- a/third_party/rust/serde_json/src/macros.rs
+++ b/third_party/rust/serde_json/src/macros.rs
@@ -10,7 +10,8 @@
/// "features": [
/// "serde",
/// "json"
-/// ]
+/// ],
+/// "homepage": null
/// }
/// });
/// ```
diff --git a/third_party/rust/serde_json/src/map.rs b/third_party/rust/serde_json/src/map.rs
index 3e8a3814c9..520cd6cf53 100644
--- a/third_party/rust/serde_json/src/map.rs
+++ b/third_party/rust/serde_json/src/map.rs
@@ -11,7 +11,7 @@ use alloc::string::String;
use core::borrow::Borrow;
use core::fmt::{self, Debug};
use core::hash::Hash;
-use core::iter::{FromIterator, FusedIterator};
+use core::iter::FusedIterator;
#[cfg(feature = "preserve_order")]
use core::mem;
use core::ops;
@@ -20,7 +20,7 @@ use serde::de;
#[cfg(not(feature = "preserve_order"))]
use alloc::collections::{btree_map, BTreeMap};
#[cfg(feature = "preserve_order")]
-use indexmap::{self, IndexMap};
+use indexmap::IndexMap;
/// Represents a JSON key/value type.
pub struct Map<K, V> {
@@ -106,7 +106,6 @@ impl Map<String, Value> {
/// The key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
#[inline]
- #[cfg(any(feature = "preserve_order", not(no_btreemap_get_key_value)))]
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
where
String: Borrow<Q>,
@@ -131,6 +130,12 @@ impl Map<String, Value> {
///
/// The key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
+ ///
+ /// If serde_json's "preserve_order" is enabled, `.remove(key)` is
+ /// equivalent to [`.swap_remove(key)`][Self::swap_remove], replacing this
+ /// entry's position with the last element. If you need to preserve the
+ /// relative order of the keys in the map, use
+ /// [`.shift_remove(key)`][Self::shift_remove] instead.
#[inline]
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
where
@@ -138,7 +143,7 @@ impl Map<String, Value> {
Q: ?Sized + Ord + Eq + Hash,
{
#[cfg(feature = "preserve_order")]
- return self.map.swap_remove(key);
+ return self.swap_remove(key);
#[cfg(not(feature = "preserve_order"))]
return self.map.remove(key);
}
@@ -148,49 +153,94 @@ impl Map<String, Value> {
///
/// The key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
+ ///
+ /// If serde_json's "preserve_order" is enabled, `.remove_entry(key)` is
+ /// equivalent to [`.swap_remove_entry(key)`][Self::swap_remove_entry],
+ /// replacing this entry's position with the last element. If you need to
+ /// preserve the relative order of the keys in the map, use
+ /// [`.shift_remove_entry(key)`][Self::shift_remove_entry] instead.
+ #[inline]
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
where
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
{
- #[cfg(any(feature = "preserve_order", not(no_btreemap_remove_entry)))]
+ #[cfg(feature = "preserve_order")]
+ return self.swap_remove_entry(key);
+ #[cfg(not(feature = "preserve_order"))]
return self.map.remove_entry(key);
- #[cfg(all(
- not(feature = "preserve_order"),
- no_btreemap_remove_entry,
- not(no_btreemap_get_key_value),
- ))]
- {
- let (key, _value) = self.map.get_key_value(key)?;
- let key = key.clone();
- let value = self.map.remove::<String>(&key)?;
- Some((key, value))
- }
- #[cfg(all(
- not(feature = "preserve_order"),
- no_btreemap_remove_entry,
- no_btreemap_get_key_value,
- ))]
- {
- use core::ops::{Bound, RangeBounds};
-
- struct Key<'a, Q: ?Sized>(&'a Q);
-
- impl<'a, Q: ?Sized> RangeBounds<Q> for Key<'a, Q> {
- fn start_bound(&self) -> Bound<&Q> {
- Bound::Included(self.0)
- }
- fn end_bound(&self) -> Bound<&Q> {
- Bound::Included(self.0)
- }
- }
+ }
- let mut range = self.map.range(Key(key));
- let (key, _value) = range.next()?;
- let key = key.clone();
- let value = self.map.remove::<String>(&key)?;
- Some((key, value))
- }
+ /// Removes and returns the value corresponding to the key from the map.
+ ///
+ /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
+ /// last element of the map and popping it off. This perturbs the position
+ /// of what used to be the last element!
+ ///
+ /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
+ #[cfg(feature = "preserve_order")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
+ #[inline]
+ pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<Value>
+ where
+ String: Borrow<Q>,
+ Q: ?Sized + Ord + Eq + Hash,
+ {
+ self.map.swap_remove(key)
+ }
+
+ /// Remove and return the key-value pair.
+ ///
+ /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
+ /// last element of the map and popping it off. This perturbs the position
+ /// of what used to be the last element!
+ ///
+ /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
+ #[cfg(feature = "preserve_order")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
+ #[inline]
+ pub fn swap_remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
+ where
+ String: Borrow<Q>,
+ Q: ?Sized + Ord + Eq + Hash,
+ {
+ self.map.swap_remove_entry(key)
+ }
+
+ /// Removes and returns the value corresponding to the key from the map.
+ ///
+ /// Like [`Vec::remove`], the entry is removed by shifting all of the
+ /// elements that follow it, preserving their relative order. This perturbs
+ /// the index of all of those elements!
+ ///
+ /// [`Vec::remove`]: std::vec::Vec::remove
+ #[cfg(feature = "preserve_order")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
+ #[inline]
+ pub fn shift_remove<Q>(&mut self, key: &Q) -> Option<Value>
+ where
+ String: Borrow<Q>,
+ Q: ?Sized + Ord + Eq + Hash,
+ {
+ self.map.shift_remove(key)
+ }
+
+ /// Remove and return the key-value pair.
+ ///
+ /// Like [`Vec::remove`], the entry is removed by shifting all of the
+ /// elements that follow it, preserving their relative order. This perturbs
+ /// the index of all of those elements!
+ ///
+ /// [`Vec::remove`]: std::vec::Vec::remove
+ #[cfg(feature = "preserve_order")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
+ #[inline]
+ pub fn shift_remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
+ where
+ String: Borrow<Q>,
+ Q: ?Sized + Ord + Eq + Hash,
+ {
+ self.map.shift_remove_entry(key)
}
/// Moves all elements from other into self, leaving other empty.
@@ -276,7 +326,6 @@ impl Map<String, Value> {
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
/// returns `false`.
- #[cfg(not(no_btreemap_retain))]
#[inline]
pub fn retain<F>(&mut self, f: F)
where
diff --git a/third_party/rust/serde_json/src/number.rs b/third_party/rust/serde_json/src/number.rs
index 21a76411cc..878a3dcb20 100644
--- a/third_party/rust/serde_json/src/number.rs
+++ b/third_party/rust/serde_json/src/number.rs
@@ -82,7 +82,7 @@ impl Number {
/// ```
/// # use serde_json::json;
/// #
- /// let big = i64::max_value() as u64 + 10;
+ /// let big = i64::MAX as u64 + 10;
/// let v = json!({ "a": 64, "b": big, "c": 256.0 });
///
/// assert!(v["a"].is_i64());
@@ -97,7 +97,7 @@ impl Number {
pub fn is_i64(&self) -> bool {
#[cfg(not(feature = "arbitrary_precision"))]
match self.n {
- N::PosInt(v) => v <= i64::max_value() as u64,
+ N::PosInt(v) => v <= i64::MAX as u64,
N::NegInt(_) => true,
N::Float(_) => false,
}
@@ -177,7 +177,7 @@ impl Number {
/// ```
/// # use serde_json::json;
/// #
- /// let big = i64::max_value() as u64 + 10;
+ /// let big = i64::MAX as u64 + 10;
/// let v = json!({ "a": 64, "b": big, "c": 256.0 });
///
/// assert_eq!(v["a"].as_i64(), Some(64));
@@ -189,7 +189,7 @@ impl Number {
#[cfg(not(feature = "arbitrary_precision"))]
match self.n {
N::PosInt(n) => {
- if n <= i64::max_value() as u64 {
+ if n <= i64::MAX as u64 {
Some(n as i64)
} else {
None
@@ -279,6 +279,62 @@ impl Number {
}
}
+ /// Returns the exact original JSON representation that this Number was
+ /// parsed from.
+ ///
+ /// For numbers constructed not via parsing, such as by `From<i32>`, returns
+ /// the JSON representation that serde\_json would serialize for this
+ /// number.
+ ///
+ /// ```
+ /// # use serde_json::Number;
+ /// for value in [
+ /// "7",
+ /// "12.34",
+ /// "34e-56789",
+ /// "0.0123456789000000012345678900000001234567890000123456789",
+ /// "343412345678910111213141516171819202122232425262728293034",
+ /// "-343412345678910111213141516171819202122232425262728293031",
+ /// ] {
+ /// let number: Number = serde_json::from_str(value).unwrap();
+ /// assert_eq!(number.as_str(), value);
+ /// }
+ /// ```
+ #[cfg(feature = "arbitrary_precision")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary_precision")))]
+ pub fn as_str(&self) -> &str {
+ &self.n
+ }
+
+ pub(crate) fn as_f32(&self) -> Option<f32> {
+ #[cfg(not(feature = "arbitrary_precision"))]
+ match self.n {
+ N::PosInt(n) => Some(n as f32),
+ N::NegInt(n) => Some(n as f32),
+ N::Float(n) => Some(n as f32),
+ }
+ #[cfg(feature = "arbitrary_precision")]
+ self.n.parse::<f32>().ok().filter(|float| float.is_finite())
+ }
+
+ pub(crate) fn from_f32(f: f32) -> Option<Number> {
+ if f.is_finite() {
+ let n = {
+ #[cfg(not(feature = "arbitrary_precision"))]
+ {
+ N::Float(f as f64)
+ }
+ #[cfg(feature = "arbitrary_precision")]
+ {
+ ryu::Buffer::new().format_finite(f).to_owned()
+ }
+ };
+ Some(Number { n })
+ } else {
+ None
+ }
+ }
+
#[cfg(feature = "arbitrary_precision")]
/// Not public API. Only tests use this.
#[doc(hidden)]
@@ -332,8 +388,8 @@ impl Serialize for Number {
{
use serde::ser::SerializeStruct;
- let mut s = serializer.serialize_struct(TOKEN, 1)?;
- s.serialize_field(TOKEN, &self.n)?;
+ let mut s = tri!(serializer.serialize_struct(TOKEN, 1));
+ tri!(s.serialize_field(TOKEN, &self.n));
s.end()
}
}
@@ -377,11 +433,11 @@ impl<'de> Deserialize<'de> for Number {
where
V: de::MapAccess<'de>,
{
- let value = visitor.next_key::<NumberKey>()?;
+ let value = tri!(visitor.next_key::<NumberKey>());
if value.is_none() {
return Err(de::Error::invalid_type(Unexpected::Map, &self));
}
- let v: NumberFromString = visitor.next_value()?;
+ let v: NumberFromString = tri!(visitor.next_value());
Ok(v.value)
}
}
@@ -420,7 +476,7 @@ impl<'de> de::Deserialize<'de> for NumberKey {
}
}
- deserializer.deserialize_identifier(FieldVisitor)?;
+ tri!(deserializer.deserialize_identifier(FieldVisitor));
Ok(NumberKey)
}
}
@@ -523,7 +579,7 @@ macro_rules! deserialize_number {
where
V: de::Visitor<'de>,
{
- visitor.$visit(self.n.parse().map_err(|_| invalid_number())?)
+ visitor.$visit(tri!(self.n.parse().map_err(|_| invalid_number())))
}
};
}
diff --git a/third_party/rust/serde_json/src/raw.rs b/third_party/rust/serde_json/src/raw.rs
index 6aa4ffcb61..22d14441ec 100644
--- a/third_party/rust/serde_json/src/raw.rs
+++ b/third_party/rust/serde_json/src/raw.rs
@@ -112,8 +112,8 @@ use serde::ser::{Serialize, SerializeStruct, Serializer};
/// raw_value: Box<RawValue>,
/// }
/// ```
-#[cfg_attr(not(doc), repr(transparent))]
#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
+#[repr(transparent)]
pub struct RawValue {
json: str,
}
@@ -177,11 +177,9 @@ impl RawValue {
/// - the input has no leading or trailing whitespace, and
/// - the input has capacity equal to its length.
pub fn from_string(json: String) -> Result<Box<Self>, Error> {
- {
- let borrowed = crate::from_str::<&Self>(&json)?;
- if borrowed.json.len() < json.len() {
- return Ok(borrowed.to_owned());
- }
+ let borrowed = tri!(crate::from_str::<&Self>(&json));
+ if borrowed.json.len() < json.len() {
+ return Ok(borrowed.to_owned());
}
Ok(Self::from_owned(json.into_boxed_str()))
}
@@ -287,7 +285,7 @@ pub fn to_raw_value<T>(value: &T) -> Result<Box<RawValue>, Error>
where
T: ?Sized + Serialize,
{
- let json_string = crate::to_string(value)?;
+ let json_string = tri!(crate::to_string(value));
Ok(RawValue::from_owned(json_string.into_boxed_str()))
}
@@ -298,8 +296,8 @@ impl Serialize for RawValue {
where
S: Serializer,
{
- let mut s = serializer.serialize_struct(TOKEN, 1)?;
- s.serialize_field(TOKEN, &self.json)?;
+ let mut s = tri!(serializer.serialize_struct(TOKEN, 1));
+ tri!(s.serialize_field(TOKEN, &self.json));
s.end()
}
}
@@ -322,7 +320,7 @@ impl<'de: 'a, 'a> Deserialize<'de> for &'a RawValue {
where
V: MapAccess<'de>,
{
- let value = visitor.next_key::<RawKey>()?;
+ let value = tri!(visitor.next_key::<RawKey>());
if value.is_none() {
return Err(de::Error::invalid_type(Unexpected::Map, &self));
}
@@ -352,7 +350,7 @@ impl<'de> Deserialize<'de> for Box<RawValue> {
where
V: MapAccess<'de>,
{
- let value = visitor.next_key::<RawKey>()?;
+ let value = tri!(visitor.next_key::<RawKey>());
if value.is_none() {
return Err(de::Error::invalid_type(Unexpected::Map, &self));
}
@@ -392,7 +390,7 @@ impl<'de> Deserialize<'de> for RawKey {
}
}
- deserializer.deserialize_identifier(FieldVisitor)?;
+ tri!(deserializer.deserialize_identifier(FieldVisitor));
Ok(RawKey)
}
}
@@ -529,3 +527,251 @@ impl<'de> MapAccess<'de> for BorrowedRawDeserializer<'de> {
seed.deserialize(BorrowedStrDeserializer::new(self.raw_value.take().unwrap()))
}
}
+
+impl<'de> IntoDeserializer<'de, Error> for &'de RawValue {
+ type Deserializer = &'de RawValue;
+
+ fn into_deserializer(self) -> Self::Deserializer {
+ self
+ }
+}
+
+impl<'de> Deserializer<'de> for &'de RawValue {
+ type Error = Error;
+
+ fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_any(visitor)
+ }
+
+ fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_bool(visitor)
+ }
+
+ fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_i8(visitor)
+ }
+
+ fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_i16(visitor)
+ }
+
+ fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_i32(visitor)
+ }
+
+ fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_i64(visitor)
+ }
+
+ fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_i128(visitor)
+ }
+
+ fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_u8(visitor)
+ }
+
+ fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_u16(visitor)
+ }
+
+ fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_u32(visitor)
+ }
+
+ fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_u64(visitor)
+ }
+
+ fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_u128(visitor)
+ }
+
+ fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_f32(visitor)
+ }
+
+ fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_f64(visitor)
+ }
+
+ fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_char(visitor)
+ }
+
+ fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_str(visitor)
+ }
+
+ fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_string(visitor)
+ }
+
+ fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_bytes(visitor)
+ }
+
+ fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_byte_buf(visitor)
+ }
+
+ fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_option(visitor)
+ }
+
+ fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_unit(visitor)
+ }
+
+ fn deserialize_unit_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_unit_struct(name, visitor)
+ }
+
+ fn deserialize_newtype_struct<V>(
+ self,
+ name: &'static str,
+ visitor: V,
+ ) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_newtype_struct(name, visitor)
+ }
+
+ fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_seq(visitor)
+ }
+
+ fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_tuple(len, visitor)
+ }
+
+ fn deserialize_tuple_struct<V>(
+ self,
+ name: &'static str,
+ len: usize,
+ visitor: V,
+ ) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_tuple_struct(name, len, visitor)
+ }
+
+ fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_map(visitor)
+ }
+
+ fn deserialize_struct<V>(
+ self,
+ name: &'static str,
+ fields: &'static [&'static str],
+ visitor: V,
+ ) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_struct(name, fields, visitor)
+ }
+
+ fn deserialize_enum<V>(
+ self,
+ name: &'static str,
+ variants: &'static [&'static str],
+ visitor: V,
+ ) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_enum(name, variants, visitor)
+ }
+
+ fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_identifier(visitor)
+ }
+
+ fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ crate::Deserializer::from_str(&self.json).deserialize_ignored_any(visitor)
+ }
+}
diff --git a/third_party/rust/serde_json/src/read.rs b/third_party/rust/serde_json/src/read.rs
index fc3a3ca748..a426911c7d 100644
--- a/third_party/rust/serde_json/src/read.rs
+++ b/third_party/rust/serde_json/src/read.rs
@@ -14,11 +14,13 @@ use crate::iter::LineColIterator;
use crate::raw::BorrowedRawDeserializer;
#[cfg(all(feature = "raw_value", feature = "std"))]
use crate::raw::OwnedRawDeserializer;
+#[cfg(all(feature = "raw_value", feature = "std"))]
+use alloc::string::String;
#[cfg(feature = "raw_value")]
use serde::de::Visitor;
/// Trait used by the deserializer for iterating over input. This is manually
-/// "specialized" for iterating over &[u8]. Once feature(specialization) is
+/// "specialized" for iterating over `&[u8]`. Once feature(specialization) is
/// stable we can use actual specialization.
///
/// This trait is sealed and cannot be implemented for types outside of
@@ -81,7 +83,7 @@ pub trait Read<'de>: private::Sealed {
#[doc(hidden)]
fn ignore_str(&mut self) -> Result<()>;
- /// Assumes the previous byte was a hex escape sequnce ('\u') in a string.
+ /// Assumes the previous byte was a hex escape sequence ('\u') in a string.
/// Parses next hexadecimal sequence.
#[doc(hidden)]
fn decode_hex_escape(&mut self) -> Result<u16>;
diff --git a/third_party/rust/serde_json/src/ser.rs b/third_party/rust/serde_json/src/ser.rs
index 80c2deb0c1..3742e0bef4 100644
--- a/third_party/rust/serde_json/src/ser.rs
+++ b/third_party/rust/serde_json/src/ser.rs
@@ -189,12 +189,9 @@ where
#[inline]
fn serialize_bytes(self, value: &[u8]) -> Result<()> {
- use serde::ser::SerializeSeq;
- let mut seq = tri!(self.serialize_seq(Some(value.len())));
- for byte in value {
- tri!(seq.serialize_element(byte));
- }
- seq.end()
+ self.formatter
+ .write_byte_array(&mut self.writer, value)
+ .map_err(Error::io)
}
#[inline]
@@ -439,17 +436,15 @@ where
.formatter
.begin_string(&mut self.writer)
.map_err(Error::io));
- {
- let mut adapter = Adapter {
- writer: &mut self.writer,
- formatter: &mut self.formatter,
- error: None,
- };
- match write!(adapter, "{}", value) {
- Ok(()) => debug_assert!(adapter.error.is_none()),
- Err(fmt::Error) => {
- return Err(Error::io(adapter.error.expect("there should be an error")));
- }
+ let mut adapter = Adapter {
+ writer: &mut self.writer,
+ formatter: &mut self.formatter,
+ error: None,
+ };
+ match write!(adapter, "{}", value) {
+ Ok(()) => debug_assert!(adapter.error.is_none()),
+ Err(fmt::Error) => {
+ return Err(Error::io(adapter.error.expect("there should be an error")));
}
}
self.formatter
@@ -789,6 +784,10 @@ fn key_must_be_a_string() -> Error {
Error::syntax(ErrorCode::KeyMustBeAString, 0, 0)
}
+fn float_key_must_be_finite() -> Error {
+ Error::syntax(ErrorCode::FloatKeyMustBeFinite, 0, 0)
+}
+
impl<'a, W, F> ser::Serializer for MapKeySerializer<'a, W, F>
where
W: io::Write,
@@ -828,8 +827,21 @@ where
type SerializeStruct = Impossible<(), Error>;
type SerializeStructVariant = Impossible<(), Error>;
- fn serialize_bool(self, _value: bool) -> Result<()> {
- Err(key_must_be_a_string())
+ fn serialize_bool(self, value: bool) -> Result<()> {
+ tri!(self
+ .ser
+ .formatter
+ .begin_string(&mut self.ser.writer)
+ .map_err(Error::io));
+ tri!(self
+ .ser
+ .formatter
+ .write_bool(&mut self.ser.writer, value)
+ .map_err(Error::io));
+ self.ser
+ .formatter
+ .end_string(&mut self.ser.writer)
+ .map_err(Error::io)
}
fn serialize_i8(self, value: i8) -> Result<()> {
@@ -1002,12 +1014,46 @@ where
.map_err(Error::io)
}
- fn serialize_f32(self, _value: f32) -> Result<()> {
- Err(key_must_be_a_string())
+ fn serialize_f32(self, value: f32) -> Result<()> {
+ if !value.is_finite() {
+ return Err(float_key_must_be_finite());
+ }
+
+ tri!(self
+ .ser
+ .formatter
+ .begin_string(&mut self.ser.writer)
+ .map_err(Error::io));
+ tri!(self
+ .ser
+ .formatter
+ .write_f32(&mut self.ser.writer, value)
+ .map_err(Error::io));
+ self.ser
+ .formatter
+ .end_string(&mut self.ser.writer)
+ .map_err(Error::io)
}
- fn serialize_f64(self, _value: f64) -> Result<()> {
- Err(key_must_be_a_string())
+ fn serialize_f64(self, value: f64) -> Result<()> {
+ if !value.is_finite() {
+ return Err(float_key_must_be_finite());
+ }
+
+ tri!(self
+ .ser
+ .formatter
+ .begin_string(&mut self.ser.writer)
+ .map_err(Error::io));
+ tri!(self
+ .ser
+ .formatter
+ .write_f64(&mut self.ser.writer, value)
+ .map_err(Error::io));
+ self.ser
+ .formatter
+ .end_string(&mut self.ser.writer)
+ .map_err(Error::io)
}
fn serialize_char(self, value: char) -> Result<()> {
@@ -1043,11 +1089,11 @@ where
Err(key_must_be_a_string())
}
- fn serialize_some<T>(self, _value: &T) -> Result<()>
+ fn serialize_some<T>(self, value: &T) -> Result<()>
where
T: ?Sized + Serialize,
{
- Err(key_must_be_a_string())
+ value.serialize(self)
}
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq> {
@@ -1734,6 +1780,24 @@ pub trait Formatter {
writer.write_all(s)
}
+ /// Writes the representation of a byte array. Formatters can choose whether
+ /// to represent bytes as a JSON array of integers (the default), or some
+ /// JSON string encoding like hex or base64.
+ fn write_byte_array<W>(&mut self, writer: &mut W, value: &[u8]) -> io::Result<()>
+ where
+ W: ?Sized + io::Write,
+ {
+ tri!(self.begin_array(writer));
+ let mut first = true;
+ for byte in value {
+ tri!(self.begin_array_value(writer, first));
+ tri!(self.write_u8(writer, *byte));
+ tri!(self.end_array_value(writer));
+ first = false;
+ }
+ self.end_array(writer)
+ }
+
/// Called before every array. Writes a `[` to the specified
/// writer.
#[inline]
@@ -2062,7 +2126,9 @@ static ESCAPE: [u8; 256] = [
__, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, // F
];
-/// Serialize the given data structure as JSON into the IO stream.
+/// Serialize the given data structure as JSON into the I/O stream.
+///
+/// Serialization guarantees it only feeds valid UTF-8 sequences to the writer.
///
/// # Errors
///
@@ -2079,9 +2145,11 @@ where
value.serialize(&mut ser)
}
-/// Serialize the given data structure as pretty-printed JSON into the IO
+/// Serialize the given data structure as pretty-printed JSON into the I/O
/// stream.
///
+/// Serialization guarantees it only feeds valid UTF-8 sequences to the writer.
+///
/// # Errors
///
/// Serialization can fail if `T`'s implementation of `Serialize` decides to
diff --git a/third_party/rust/serde_json/src/value/de.rs b/third_party/rust/serde_json/src/value/de.rs
index 9c266d08ae..936725635f 100644
--- a/third_party/rust/serde_json/src/value/de.rs
+++ b/third_party/rust/serde_json/src/value/de.rs
@@ -1,4 +1,4 @@
-use crate::error::Error;
+use crate::error::{Error, ErrorCode};
use crate::map::Map;
use crate::number::Number;
use crate::value::Value;
@@ -106,15 +106,15 @@ impl<'de> Deserialize<'de> for Value {
where
V: MapAccess<'de>,
{
- match visitor.next_key_seed(KeyClassifier)? {
+ match tri!(visitor.next_key_seed(KeyClassifier)) {
#[cfg(feature = "arbitrary_precision")]
Some(KeyClass::Number) => {
- let number: NumberFromString = visitor.next_value()?;
+ let number: NumberFromString = tri!(visitor.next_value());
Ok(Value::Number(number.value))
}
#[cfg(feature = "raw_value")]
Some(KeyClass::RawValue) => {
- let value = visitor.next_value_seed(crate::raw::BoxedFromString)?;
+ let value = tri!(visitor.next_value_seed(crate::raw::BoxedFromString));
crate::from_str(value.get()).map_err(de::Error::custom)
}
Some(KeyClass::Map(first_key)) => {
@@ -219,6 +219,8 @@ impl<'de> serde::Deserializer<'de> for Value {
Value::Number(n) => n.deserialize_any(visitor),
#[cfg(any(feature = "std", feature = "alloc"))]
Value::String(v) => visitor.visit_string(v),
+ #[cfg(not(any(feature = "std", feature = "alloc")))]
+ Value::String(_) => unreachable!(),
Value::Array(v) => visit_array(v, visitor),
Value::Object(v) => visit_object(v, visitor),
}
@@ -482,6 +484,14 @@ impl<'de> IntoDeserializer<'de, Error> for Value {
}
}
+impl<'de> IntoDeserializer<'de, Error> for &'de Value {
+ type Deserializer = Self;
+
+ fn into_deserializer(self) -> Self::Deserializer {
+ self
+ }
+}
+
struct VariantDeserializer {
value: Option<Value>,
}
@@ -1120,18 +1130,30 @@ struct MapKeyDeserializer<'de> {
key: Cow<'de, str>,
}
-macro_rules! deserialize_integer_key {
- ($method:ident => $visit:ident) => {
+macro_rules! deserialize_numeric_key {
+ ($method:ident) => {
+ deserialize_numeric_key!($method, deserialize_number);
+ };
+
+ ($method:ident, $using:ident) => {
fn $method<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
- match (self.key.parse(), self.key) {
- (Ok(integer), _) => visitor.$visit(integer),
- (Err(_), Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
- #[cfg(any(feature = "std", feature = "alloc"))]
- (Err(_), Cow::Owned(s)) => visitor.visit_string(s),
+ let mut de = crate::Deserializer::from_str(&self.key);
+
+ match tri!(de.peek()) {
+ Some(b'0'..=b'9' | b'-') => {}
+ _ => return Err(Error::syntax(ErrorCode::ExpectedNumericKey, 0, 0)),
+ }
+
+ let number = tri!(de.$using(visitor));
+
+ if tri!(de.peek()).is_some() {
+ return Err(Error::syntax(ErrorCode::ExpectedNumericKey, 0, 0));
}
+
+ Ok(number)
}
};
}
@@ -1146,16 +1168,38 @@ impl<'de> serde::Deserializer<'de> for MapKeyDeserializer<'de> {
BorrowedCowStrDeserializer::new(self.key).deserialize_any(visitor)
}
- deserialize_integer_key!(deserialize_i8 => visit_i8);
- deserialize_integer_key!(deserialize_i16 => visit_i16);
- deserialize_integer_key!(deserialize_i32 => visit_i32);
- deserialize_integer_key!(deserialize_i64 => visit_i64);
- deserialize_integer_key!(deserialize_i128 => visit_i128);
- deserialize_integer_key!(deserialize_u8 => visit_u8);
- deserialize_integer_key!(deserialize_u16 => visit_u16);
- deserialize_integer_key!(deserialize_u32 => visit_u32);
- deserialize_integer_key!(deserialize_u64 => visit_u64);
- deserialize_integer_key!(deserialize_u128 => visit_u128);
+ deserialize_numeric_key!(deserialize_i8);
+ deserialize_numeric_key!(deserialize_i16);
+ deserialize_numeric_key!(deserialize_i32);
+ deserialize_numeric_key!(deserialize_i64);
+ deserialize_numeric_key!(deserialize_u8);
+ deserialize_numeric_key!(deserialize_u16);
+ deserialize_numeric_key!(deserialize_u32);
+ deserialize_numeric_key!(deserialize_u64);
+ #[cfg(not(feature = "float_roundtrip"))]
+ deserialize_numeric_key!(deserialize_f32);
+ deserialize_numeric_key!(deserialize_f64);
+
+ #[cfg(feature = "float_roundtrip")]
+ deserialize_numeric_key!(deserialize_f32, do_deserialize_f32);
+ deserialize_numeric_key!(deserialize_i128, do_deserialize_i128);
+ deserialize_numeric_key!(deserialize_u128, do_deserialize_u128);
+
+ fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
+ where
+ V: Visitor<'de>,
+ {
+ if self.key == "true" {
+ visitor.visit_bool(true)
+ } else if self.key == "false" {
+ visitor.visit_bool(false)
+ } else {
+ Err(serde::de::Error::invalid_type(
+ Unexpected::Str(&self.key),
+ &visitor,
+ ))
+ }
+ }
#[inline]
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
@@ -1193,8 +1237,8 @@ impl<'de> serde::Deserializer<'de> for MapKeyDeserializer<'de> {
}
forward_to_deserialize_any! {
- bool f32 f64 char str string bytes byte_buf unit unit_struct seq tuple
- tuple_struct map struct identifier ignored_any
+ char str string bytes byte_buf unit unit_struct seq tuple tuple_struct
+ map struct identifier ignored_any
}
}
@@ -1297,6 +1341,8 @@ impl<'de> de::Deserializer<'de> for BorrowedCowStrDeserializer<'de> {
Cow::Borrowed(string) => visitor.visit_borrowed_str(string),
#[cfg(any(feature = "std", feature = "alloc"))]
Cow::Owned(string) => visitor.visit_string(string),
+ #[cfg(not(any(feature = "std", feature = "alloc")))]
+ Cow::Owned(_) => unreachable!(),
}
}
@@ -1327,7 +1373,7 @@ impl<'de> de::EnumAccess<'de> for BorrowedCowStrDeserializer<'de> {
where
T: de::DeserializeSeed<'de>,
{
- let value = seed.deserialize(self)?;
+ let value = tri!(seed.deserialize(self));
Ok((value, UnitOnly))
}
}
diff --git a/third_party/rust/serde_json/src/value/from.rs b/third_party/rust/serde_json/src/value/from.rs
index c5a6a3960b..ed1e3338b0 100644
--- a/third_party/rust/serde_json/src/value/from.rs
+++ b/third_party/rust/serde_json/src/value/from.rs
@@ -4,7 +4,6 @@ use crate::number::Number;
use alloc::borrow::Cow;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
-use core::iter::FromIterator;
macro_rules! from_integer {
($($ty:ident)*) => {
@@ -29,7 +28,8 @@ from_integer! {
}
impl From<f32> for Value {
- /// Convert 32-bit floating point number to `Value`
+ /// Convert 32-bit floating point number to `Value::Number`, or
+ /// `Value::Null` if infinite or NaN.
///
/// # Examples
///
@@ -40,12 +40,13 @@ impl From<f32> for Value {
/// let x: Value = f.into();
/// ```
fn from(f: f32) -> Self {
- From::from(f as f64)
+ Number::from_f32(f).map_or(Value::Null, Value::Number)
}
}
impl From<f64> for Value {
- /// Convert 64-bit floating point number to `Value`
+ /// Convert 64-bit floating point number to `Value::Number`, or
+ /// `Value::Null` if infinite or NaN.
///
/// # Examples
///
@@ -61,7 +62,7 @@ impl From<f64> for Value {
}
impl From<bool> for Value {
- /// Convert boolean to `Value`
+ /// Convert boolean to `Value::Bool`.
///
/// # Examples
///
@@ -77,7 +78,7 @@ impl From<bool> for Value {
}
impl From<String> for Value {
- /// Convert `String` to `Value`
+ /// Convert `String` to `Value::String`.
///
/// # Examples
///
@@ -92,8 +93,8 @@ impl From<String> for Value {
}
}
-impl<'a> From<&'a str> for Value {
- /// Convert string slice to `Value`
+impl From<&str> for Value {
+ /// Convert string slice to `Value::String`.
///
/// # Examples
///
@@ -109,7 +110,7 @@ impl<'a> From<&'a str> for Value {
}
impl<'a> From<Cow<'a, str>> for Value {
- /// Convert copy-on-write string to `Value`
+ /// Convert copy-on-write string to `Value::String`.
///
/// # Examples
///
@@ -134,7 +135,7 @@ impl<'a> From<Cow<'a, str>> for Value {
}
impl From<Number> for Value {
- /// Convert `Number` to `Value`
+ /// Convert `Number` to `Value::Number`.
///
/// # Examples
///
@@ -150,7 +151,7 @@ impl From<Number> for Value {
}
impl From<Map<String, Value>> for Value {
- /// Convert map (with string keys) to `Value`
+ /// Convert map (with string keys) to `Value::Object`.
///
/// # Examples
///
@@ -167,7 +168,7 @@ impl From<Map<String, Value>> for Value {
}
impl<T: Into<Value>> From<Vec<T>> for Value {
- /// Convert a `Vec` to `Value`
+ /// Convert a `Vec` to `Value::Array`.
///
/// # Examples
///
@@ -182,8 +183,8 @@ impl<T: Into<Value>> From<Vec<T>> for Value {
}
}
-impl<'a, T: Clone + Into<Value>> From<&'a [T]> for Value {
- /// Convert a slice to `Value`
+impl<T: Clone + Into<Value>> From<&[T]> for Value {
+ /// Convert a slice to `Value::Array`.
///
/// # Examples
///
@@ -193,13 +194,13 @@ impl<'a, T: Clone + Into<Value>> From<&'a [T]> for Value {
/// let v: &[&str] = &["lorem", "ipsum", "dolor"];
/// let x: Value = v.into();
/// ```
- fn from(f: &'a [T]) -> Self {
+ fn from(f: &[T]) -> Self {
Value::Array(f.iter().cloned().map(Into::into).collect())
}
}
impl<T: Into<Value>> FromIterator<T> for Value {
- /// Convert an iteratable type to a `Value`
+ /// Create a `Value::Array` by collecting an iterator of array elements.
///
/// # Examples
///
@@ -229,7 +230,7 @@ impl<T: Into<Value>> FromIterator<T> for Value {
}
impl<K: Into<String>, V: Into<Value>> FromIterator<(K, V)> for Value {
- /// Convert an iteratable type to a `Value`
+ /// Create a `Value::Object` by collecting an iterator of key-value pairs.
///
/// # Examples
///
@@ -249,7 +250,7 @@ impl<K: Into<String>, V: Into<Value>> FromIterator<(K, V)> for Value {
}
impl From<()> for Value {
- /// Convert `()` to `Value`
+ /// Convert `()` to `Value::Null`.
///
/// # Examples
///
diff --git a/third_party/rust/serde_json/src/value/index.rs b/third_party/rust/serde_json/src/value/index.rs
index c74042b75a..891ca8ef73 100644
--- a/third_party/rust/serde_json/src/value/index.rs
+++ b/third_party/rust/serde_json/src/value/index.rs
@@ -116,7 +116,7 @@ impl Index for String {
}
}
-impl<'a, T> Index for &'a T
+impl<T> Index for &T
where
T: ?Sized + Index,
{
diff --git a/third_party/rust/serde_json/src/value/mod.rs b/third_party/rust/serde_json/src/value/mod.rs
index 470b6b24da..b3f51ea0db 100644
--- a/third_party/rust/serde_json/src/value/mod.rs
+++ b/third_party/rust/serde_json/src/value/mod.rs
@@ -106,6 +106,7 @@ pub use crate::map::Map;
pub use crate::number::Number;
#[cfg(feature = "raw_value")]
+#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
pub use crate::raw::{to_raw_value, RawValue};
/// Represents any valid JSON value.
@@ -182,11 +183,11 @@ impl Debug for Value {
Value::Number(number) => Debug::fmt(number, formatter),
Value::String(string) => write!(formatter, "String({:?})", string),
Value::Array(vec) => {
- formatter.write_str("Array ")?;
+ tri!(formatter.write_str("Array "));
Debug::fmt(vec, formatter)
}
Value::Object(map) => {
- formatter.write_str("Object ")?;
+ tri!(formatter.write_str("Object "));
Debug::fmt(map, formatter)
}
}
@@ -514,6 +515,28 @@ impl Value {
}
}
+ /// If the `Value` is a Number, returns the associated [`Number`]. Returns
+ /// None otherwise.
+ ///
+ /// ```
+ /// # use serde_json::{json, Number};
+ /// #
+ /// let v = json!({ "a": 1, "b": 2.2, "c": -3, "d": "4" });
+ ///
+ /// assert_eq!(v["a"].as_number(), Some(&Number::from(1u64)));
+ /// assert_eq!(v["b"].as_number(), Some(&Number::from_f64(2.2).unwrap()));
+ /// assert_eq!(v["c"].as_number(), Some(&Number::from(-3i64)));
+ ///
+ /// // The string `"4"` is not a number.
+ /// assert_eq!(v["d"].as_number(), None);
+ /// ```
+ pub fn as_number(&self) -> Option<&Number> {
+ match self {
+ Value::Number(number) => Some(number),
+ _ => None,
+ }
+ }
+
/// Returns true if the `Value` is an integer between `i64::MIN` and
/// `i64::MAX`.
///
@@ -889,7 +912,6 @@ mod ser;
/// ```
/// use serde::Serialize;
/// use serde_json::json;
-///
/// use std::error::Error;
///
/// #[derive(Serialize)]
@@ -898,7 +920,7 @@ mod ser;
/// location: String,
/// }
///
-/// fn compare_json_values() -> Result<(), Box<Error>> {
+/// fn compare_json_values() -> Result<(), Box<dyn Error>> {
/// let u = User {
/// fingerprint: "0xF9BA143B95FF6D82".to_owned(),
/// location: "Menlo Park, CA".to_owned(),
diff --git a/third_party/rust/serde_json/src/value/partial_eq.rs b/third_party/rust/serde_json/src/value/partial_eq.rs
index b4ef84c4f3..46c1dbc33b 100644
--- a/third_party/rust/serde_json/src/value/partial_eq.rs
+++ b/third_party/rust/serde_json/src/value/partial_eq.rs
@@ -9,6 +9,13 @@ fn eq_u64(value: &Value, other: u64) -> bool {
value.as_u64().map_or(false, |i| i == other)
}
+fn eq_f32(value: &Value, other: f32) -> bool {
+ match value {
+ Value::Number(n) => n.as_f32().map_or(false, |i| i == other),
+ _ => false,
+ }
+}
+
fn eq_f64(value: &Value, other: f64) -> bool {
value.as_f64().map_or(false, |i| i == other)
}
@@ -27,7 +34,7 @@ impl PartialEq<str> for Value {
}
}
-impl<'a> PartialEq<&'a str> for Value {
+impl PartialEq<&str> for Value {
fn eq(&self, other: &&str) -> bool {
eq_str(self, *other)
}
@@ -39,7 +46,7 @@ impl PartialEq<Value> for str {
}
}
-impl<'a> PartialEq<Value> for &'a str {
+impl PartialEq<Value> for &str {
fn eq(&self, other: &Value) -> bool {
eq_str(other, *self)
}
@@ -90,6 +97,7 @@ macro_rules! partialeq_numeric {
partialeq_numeric! {
eq_i64[i8 i16 i32 i64 isize]
eq_u64[u8 u16 u32 u64 usize]
- eq_f64[f32 f64]
+ eq_f32[f32]
+ eq_f64[f64]
eq_bool[bool]
}
diff --git a/third_party/rust/serde_json/src/value/ser.rs b/third_party/rust/serde_json/src/value/ser.rs
index a29814e92a..e869ae160f 100644
--- a/third_party/rust/serde_json/src/value/ser.rs
+++ b/third_party/rust/serde_json/src/value/ser.rs
@@ -1,12 +1,9 @@
use crate::error::{Error, ErrorCode, Result};
use crate::map::Map;
-use crate::number::Number;
use crate::value::{to_value, Value};
use alloc::borrow::ToOwned;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
-#[cfg(not(feature = "arbitrary_precision"))]
-use core::convert::TryFrom;
use core::fmt::Display;
use core::result;
use serde::ser::{Impossible, Serialize};
@@ -32,6 +29,8 @@ impl Serialize for Value {
}
map.end()
}
+ #[cfg(not(any(feature = "std", feature = "alloc")))]
+ Value::Object(_) => unreachable!(),
}
}
}
@@ -149,13 +148,13 @@ impl serde::Serializer for Serializer {
}
#[inline]
- fn serialize_f32(self, value: f32) -> Result<Value> {
- self.serialize_f64(value as f64)
+ fn serialize_f32(self, float: f32) -> Result<Value> {
+ Ok(Value::from(float))
}
#[inline]
- fn serialize_f64(self, value: f64) -> Result<Value> {
- Ok(Number::from_f64(value).map_or(Value::Null, Value::Number))
+ fn serialize_f64(self, float: f64) -> Result<Value> {
+ Ok(Value::from(float))
}
#[inline]
@@ -452,6 +451,10 @@ fn key_must_be_a_string() -> Error {
Error::syntax(ErrorCode::KeyMustBeAString, 0, 0)
}
+fn float_key_must_be_finite() -> Error {
+ Error::syntax(ErrorCode::FloatKeyMustBeFinite, 0, 0)
+}
+
impl serde::Serializer for MapKeySerializer {
type Ok = String;
type Error = Error;
@@ -482,8 +485,8 @@ impl serde::Serializer for MapKeySerializer {
value.serialize(self)
}
- fn serialize_bool(self, _value: bool) -> Result<String> {
- Err(key_must_be_a_string())
+ fn serialize_bool(self, value: bool) -> Result<String> {
+ Ok(value.to_string())
}
fn serialize_i8(self, value: i8) -> Result<String> {
@@ -518,12 +521,20 @@ impl serde::Serializer for MapKeySerializer {
Ok(value.to_string())
}
- fn serialize_f32(self, _value: f32) -> Result<String> {
- Err(key_must_be_a_string())
+ fn serialize_f32(self, value: f32) -> Result<String> {
+ if value.is_finite() {
+ Ok(ryu::Buffer::new().format_finite(value).to_owned())
+ } else {
+ Err(float_key_must_be_finite())
+ }
}
- fn serialize_f64(self, _value: f64) -> Result<String> {
- Err(key_must_be_a_string())
+ fn serialize_f64(self, value: f64) -> Result<String> {
+ if value.is_finite() {
+ Ok(ryu::Buffer::new().format_finite(value).to_owned())
+ } else {
+ Err(float_key_must_be_finite())
+ }
}
#[inline]
@@ -641,7 +652,7 @@ impl serde::ser::SerializeStruct for SerializeMap {
#[cfg(feature = "arbitrary_precision")]
SerializeMap::Number { out_value } => {
if key == crate::number::TOKEN {
- *out_value = Some(value.serialize(NumberValueEmitter)?);
+ *out_value = Some(tri!(value.serialize(NumberValueEmitter)));
Ok(())
} else {
Err(invalid_number())
@@ -650,7 +661,7 @@ impl serde::ser::SerializeStruct for SerializeMap {
#[cfg(feature = "raw_value")]
SerializeMap::RawValue { out_value } => {
if key == crate::raw::TOKEN {
- *out_value = Some(value.serialize(RawValueEmitter)?);
+ *out_value = Some(tri!(value.serialize(RawValueEmitter)));
Ok(())
} else {
Err(invalid_raw_value())
diff --git a/third_party/rust/serde_json/tests/lexical.rs b/third_party/rust/serde_json/tests/lexical.rs
index 6e0f07b8c3..368c84478e 100644
--- a/third_party/rust/serde_json/tests/lexical.rs
+++ b/third_party/rust/serde_json/tests/lexical.rs
@@ -9,6 +9,7 @@
clippy::excessive_precision,
clippy::float_cmp,
clippy::if_not_else,
+ clippy::let_underscore_untyped,
clippy::module_name_repetitions,
clippy::needless_late_init,
clippy::shadow_unrelated,
@@ -25,11 +26,6 @@ extern crate alloc;
#[path = "../src/lexical/mod.rs"]
mod lexical;
-mod lib {
- pub use std::vec::Vec;
- pub use std::{cmp, iter, mem, ops};
-}
-
#[path = "lexical/algorithm.rs"]
mod algorithm;
diff --git a/third_party/rust/serde_json/tests/lexical/exponent.rs b/third_party/rust/serde_json/tests/lexical/exponent.rs
index f7a847be38..c109ff07df 100644
--- a/third_party/rust/serde_json/tests/lexical/exponent.rs
+++ b/third_party/rust/serde_json/tests/lexical/exponent.rs
@@ -17,38 +17,20 @@ fn scientific_exponent_test() {
assert_eq!(scientific_exponent(-10, 2, 20), -9);
// Underflow
- assert_eq!(
- scientific_exponent(i32::min_value(), 0, 0),
- i32::min_value()
- );
- assert_eq!(
- scientific_exponent(i32::min_value(), 0, 5),
- i32::min_value()
- );
+ assert_eq!(scientific_exponent(i32::MIN, 0, 0), i32::MIN);
+ assert_eq!(scientific_exponent(i32::MIN, 0, 5), i32::MIN);
// Overflow
- assert_eq!(
- scientific_exponent(i32::max_value(), 0, 0),
- i32::max_value() - 1
- );
- assert_eq!(
- scientific_exponent(i32::max_value(), 5, 0),
- i32::max_value()
- );
+ assert_eq!(scientific_exponent(i32::MAX, 0, 0), i32::MAX - 1);
+ assert_eq!(scientific_exponent(i32::MAX, 5, 0), i32::MAX);
}
#[test]
fn mantissa_exponent_test() {
assert_eq!(mantissa_exponent(10, 5, 0), 5);
assert_eq!(mantissa_exponent(0, 5, 0), -5);
- assert_eq!(
- mantissa_exponent(i32::max_value(), 5, 0),
- i32::max_value() - 5
- );
- assert_eq!(mantissa_exponent(i32::max_value(), 0, 5), i32::max_value());
- assert_eq!(mantissa_exponent(i32::min_value(), 5, 0), i32::min_value());
- assert_eq!(
- mantissa_exponent(i32::min_value(), 0, 5),
- i32::min_value() + 5
- );
+ assert_eq!(mantissa_exponent(i32::MAX, 5, 0), i32::MAX - 5);
+ assert_eq!(mantissa_exponent(i32::MAX, 0, 5), i32::MAX);
+ assert_eq!(mantissa_exponent(i32::MIN, 5, 0), i32::MIN);
+ assert_eq!(mantissa_exponent(i32::MIN, 0, 5), i32::MIN + 5);
}
diff --git a/third_party/rust/serde_json/tests/lexical/parse.rs b/third_party/rust/serde_json/tests/lexical/parse.rs
index 80ca25e772..03ec1a9a63 100644
--- a/third_party/rust/serde_json/tests/lexical/parse.rs
+++ b/third_party/rust/serde_json/tests/lexical/parse.rs
@@ -1,7 +1,7 @@
// Adapted from https://github.com/Alexhuszagh/rust-lexical.
use crate::lexical::num::Float;
-use crate::lexical::parse::{parse_concise_float, parse_truncated_float};
+use crate::lexical::{parse_concise_float, parse_truncated_float};
use core::f64;
use core::fmt::Debug;
diff --git a/third_party/rust/serde_json/tests/map.rs b/third_party/rust/serde_json/tests/map.rs
index ae01969561..538cd16ae0 100644
--- a/third_party/rust/serde_json/tests/map.rs
+++ b/third_party/rust/serde_json/tests/map.rs
@@ -35,7 +35,6 @@ fn test_append() {
assert!(val.is_empty());
}
-#[cfg(not(no_btreemap_retain))]
#[test]
fn test_retain() {
let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap();
diff --git a/third_party/rust/serde_json/tests/regression/issue1004.rs b/third_party/rust/serde_json/tests/regression/issue1004.rs
new file mode 100644
index 0000000000..c09fb96108
--- /dev/null
+++ b/third_party/rust/serde_json/tests/regression/issue1004.rs
@@ -0,0 +1,12 @@
+#![cfg(feature = "arbitrary_precision")]
+
+#[test]
+fn test() {
+ let float = 5.55f32;
+ let value = serde_json::to_value(float).unwrap();
+ let json = serde_json::to_string(&value).unwrap();
+
+ // If the f32 were cast to f64 by Value before serialization, then this
+ // would incorrectly serialize as 5.550000190734863.
+ assert_eq!(json, "5.55");
+}
diff --git a/third_party/rust/serde_json/tests/regression/issue520.rs b/third_party/rust/serde_json/tests/regression/issue520.rs
index 9ed367731b..730ecc60a8 100644
--- a/third_party/rust/serde_json/tests/regression/issue520.rs
+++ b/third_party/rust/serde_json/tests/regression/issue520.rs
@@ -1,6 +1,6 @@
#![allow(clippy::float_cmp)]
-use serde_derive::{Serialize, Deserialize};
+use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type", content = "data")]
diff --git a/third_party/rust/serde_json/tests/regression/issue795.rs b/third_party/rust/serde_json/tests/regression/issue795.rs
index bb82852c54..411e8af5d3 100644
--- a/third_party/rust/serde_json/tests/regression/issue795.rs
+++ b/third_party/rust/serde_json/tests/regression/issue795.rs
@@ -8,7 +8,10 @@ use std::fmt;
#[derive(Debug)]
pub enum Enum {
- Variant { x: u8 },
+ Variant {
+ #[allow(dead_code)]
+ x: u8,
+ },
}
impl<'de> Deserialize<'de> for Enum {
diff --git a/third_party/rust/serde_json/tests/regression/issue845.rs b/third_party/rust/serde_json/tests/regression/issue845.rs
index 56037ae669..7b6564dadb 100644
--- a/third_party/rust/serde_json/tests/regression/issue845.rs
+++ b/third_party/rust/serde_json/tests/regression/issue845.rs
@@ -1,7 +1,6 @@
#![allow(clippy::trait_duplication_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/8757
use serde::{Deserialize, Deserializer};
-use std::convert::TryFrom;
use std::fmt::{self, Display};
use std::marker::PhantomData;
use std::str::FromStr;
@@ -61,6 +60,7 @@ where
#[derive(Deserialize, Debug)]
pub struct Struct {
#[serde(deserialize_with = "deserialize_integer_or_string")]
+ #[allow(dead_code)]
pub i: i64,
}
diff --git a/third_party/rust/serde_json/tests/test.rs b/third_party/rust/serde_json/tests/test.rs
index f62a545e7f..7e6adad76f 100644
--- a/third_party/rust/serde_json/tests/test.rs
+++ b/third_party/rust/serde_json/tests/test.rs
@@ -5,7 +5,9 @@
clippy::derive_partial_eq_without_eq,
clippy::excessive_precision,
clippy::float_cmp,
+ clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257
clippy::items_after_statements,
+ clippy::let_underscore_untyped,
clippy::shadow_unrelated,
clippy::too_many_lines,
clippy::unreadable_literal,
@@ -13,9 +15,6 @@
clippy::vec_init_then_push,
clippy::zero_sized_map_values
)]
-#![cfg_attr(feature = "trace-macros", feature(trace_macros))]
-#[cfg(feature = "trace-macros")]
-trace_macros!(true);
#[macro_use]
mod macros;
@@ -32,27 +31,25 @@ use serde_json::{
from_reader, from_slice, from_str, from_value, json, to_string, to_string_pretty, to_value,
to_vec, Deserializer, Number, Value,
};
-use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
#[cfg(feature = "raw_value")]
use std::collections::HashMap;
use std::fmt::{self, Debug};
+use std::hash::BuildHasher;
+#[cfg(feature = "raw_value")]
use std::hash::{Hash, Hasher};
use std::io;
use std::iter;
use std::marker::PhantomData;
use std::mem;
use std::str::FromStr;
-use std::string::ToString;
use std::{f32, f64};
-use std::{i16, i32, i64, i8};
-use std::{u16, u32, u64, u8};
macro_rules! treemap {
() => {
BTreeMap::new()
};
- ($($k:expr => $v:expr),+) => {
+ ($($k:expr => $v:expr),+ $(,)?) => {
{
let mut m = BTreeMap::new();
$(
@@ -159,16 +156,28 @@ fn test_write_f64() {
#[test]
fn test_encode_nonfinite_float_yields_null() {
- let v = to_value(::std::f64::NAN).unwrap();
+ let v = to_value(f64::NAN.copysign(1.0)).unwrap();
+ assert!(v.is_null());
+
+ let v = to_value(f64::NAN.copysign(-1.0)).unwrap();
assert!(v.is_null());
- let v = to_value(::std::f64::INFINITY).unwrap();
+ let v = to_value(f64::INFINITY).unwrap();
assert!(v.is_null());
- let v = to_value(::std::f32::NAN).unwrap();
+ let v = to_value(-f64::INFINITY).unwrap();
assert!(v.is_null());
- let v = to_value(::std::f32::INFINITY).unwrap();
+ let v = to_value(f32::NAN.copysign(1.0)).unwrap();
+ assert!(v.is_null());
+
+ let v = to_value(f32::NAN.copysign(-1.0)).unwrap();
+ assert!(v.is_null());
+
+ let v = to_value(f32::INFINITY).unwrap();
+ assert!(v.is_null());
+
+ let v = to_value(-f32::INFINITY).unwrap();
assert!(v.is_null());
}
@@ -263,7 +272,7 @@ fn test_write_object() {
(
treemap!(
"a".to_string() => true,
- "b".to_string() => false
+ "b".to_string() => false,
),
"{\"a\":true,\"b\":false}",
),
@@ -274,7 +283,7 @@ fn test_write_object() {
treemap![
"a".to_string() => treemap![],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
"{\"a\":{},\"b\":{},\"c\":{}}",
),
@@ -283,10 +292,10 @@ fn test_write_object() {
"a".to_string() => treemap![
"a".to_string() => treemap!["a" => vec![1,2,3]],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
"{\"a\":{\"a\":{\"a\":[1,2,3]},\"b\":{},\"c\":{}},\"b\":{},\"c\":{}}",
),
@@ -296,9 +305,9 @@ fn test_write_object() {
"b".to_string() => treemap![
"a".to_string() => treemap!["a" => vec![1,2,3]],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
"{\"a\":{},\"b\":{\"a\":{\"a\":[1,2,3]},\"b\":{},\"c\":{}},\"c\":{}}",
),
@@ -309,8 +318,8 @@ fn test_write_object() {
"c".to_string() => treemap![
"a".to_string() => treemap!["a" => vec![1,2,3]],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
- ]
+ "c".to_string() => treemap![],
+ ],
],
"{\"a\":{},\"b\":{},\"c\":{\"a\":{\"a\":[1,2,3]},\"b\":{},\"c\":{}}}",
),
@@ -323,7 +332,7 @@ fn test_write_object() {
treemap![
"a".to_string() => treemap![],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
pretty_str!({
"a": {},
@@ -336,10 +345,10 @@ fn test_write_object() {
"a".to_string() => treemap![
"a".to_string() => treemap!["a" => vec![1,2,3]],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
pretty_str!({
"a": {
@@ -363,9 +372,9 @@ fn test_write_object() {
"b".to_string() => treemap![
"a".to_string() => treemap!["a" => vec![1,2,3]],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
- "c".to_string() => treemap![]
+ "c".to_string() => treemap![],
],
pretty_str!({
"a": {},
@@ -390,8 +399,8 @@ fn test_write_object() {
"c".to_string() => treemap![
"a".to_string() => treemap!["a" => vec![1,2,3]],
"b".to_string() => treemap![],
- "c".to_string() => treemap![]
- ]
+ "c".to_string() => treemap![],
+ ],
],
pretty_str!({
"a": {},
@@ -422,7 +431,7 @@ fn test_write_object() {
(
treemap!(
"a".to_string() => true,
- "b".to_string() => false
+ "b".to_string() => false,
),
pretty_str!( {
"a": true,
@@ -1191,8 +1200,8 @@ fn test_parse_object() {
treemap!(
"a".to_string() => treemap!(
"b".to_string() => 3u64,
- "c".to_string() => 4
- )
+ "c".to_string() => 4,
+ ),
),
)]);
@@ -1368,7 +1377,7 @@ fn test_parse_enum() {
),
treemap!(
"a".to_string() => Animal::Dog,
- "b".to_string() => Animal::Frog("Henry".to_string(), vec![])
+ "b".to_string() => Animal::Frog("Henry".to_string(), vec![]),
),
)]);
}
@@ -1451,7 +1460,6 @@ fn test_serialize_seq_with_no_len() {
where
T: ser::Serialize,
{
- #[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -1478,7 +1486,6 @@ fn test_serialize_seq_with_no_len() {
formatter.write_str("array")
}
- #[inline]
fn visit_unit<E>(self) -> Result<MyVec<T>, E>
where
E: de::Error,
@@ -1486,7 +1493,6 @@ fn test_serialize_seq_with_no_len() {
Ok(MyVec(Vec::new()))
}
- #[inline]
fn visit_seq<V>(self, mut visitor: V) -> Result<MyVec<T>, V::Error>
where
V: de::SeqAccess<'de>,
@@ -1537,7 +1543,6 @@ fn test_serialize_map_with_no_len() {
K: ser::Serialize + Ord,
V: ser::Serialize,
{
- #[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -1565,7 +1570,6 @@ fn test_serialize_map_with_no_len() {
formatter.write_str("map")
}
- #[inline]
fn visit_unit<E>(self) -> Result<MyMap<K, V>, E>
where
E: de::Error,
@@ -1573,7 +1577,6 @@ fn test_serialize_map_with_no_len() {
Ok(MyMap(BTreeMap::new()))
}
- #[inline]
fn visit_map<Visitor>(self, mut visitor: Visitor) -> Result<MyMap<K, V>, Visitor::Error>
where
Visitor: de::MapAccess<'de>,
@@ -1660,22 +1663,11 @@ fn test_deserialize_from_stream() {
}
#[test]
-fn test_serialize_rejects_bool_keys() {
- let map = treemap!(
- true => 2,
- false => 4
- );
-
- let err = to_vec(&map).unwrap_err();
- assert_eq!(err.to_string(), "key must be a string");
-}
-
-#[test]
fn test_serialize_rejects_adt_keys() {
let map = treemap!(
Some("a") => 2,
Some("b") => 4,
- None => 6
+ None => 6,
);
let err = to_vec(&map).unwrap_err();
@@ -1889,23 +1881,41 @@ fn test_integer_key() {
// map with integer keys
let map = treemap!(
1 => 2,
- -1 => 6
+ -1 => 6,
);
let j = r#"{"-1":6,"1":2}"#;
test_encode_ok(&[(&map, j)]);
test_parse_ok(vec![(j, map)]);
- let j = r#"{"x":null}"#;
- test_parse_err::<BTreeMap<i32, ()>>(&[(
- j,
- "invalid type: string \"x\", expected i32 at line 1 column 4",
- )]);
+ test_parse_err::<BTreeMap<i32, ()>>(&[
+ (
+ r#"{"x":null}"#,
+ "invalid value: expected key to be a number in quotes at line 1 column 2",
+ ),
+ (
+ r#"{" 123":null}"#,
+ "invalid value: expected key to be a number in quotes at line 1 column 2",
+ ),
+ (r#"{"123 ":null}"#, "expected `\"` at line 1 column 6"),
+ ]);
+
+ let err = from_value::<BTreeMap<i32, ()>>(json!({" 123":null})).unwrap_err();
+ assert_eq!(
+ err.to_string(),
+ "invalid value: expected key to be a number in quotes",
+ );
+
+ let err = from_value::<BTreeMap<i32, ()>>(json!({"123 ":null})).unwrap_err();
+ assert_eq!(
+ err.to_string(),
+ "invalid value: expected key to be a number in quotes",
+ );
}
#[test]
fn test_integer128_key() {
let map = treemap! {
- 100000000000000000000000000000000000000u128 => ()
+ 100000000000000000000000000000000000000u128 => (),
};
let j = r#"{"100000000000000000000000000000000000000":null}"#;
assert_eq!(to_string(&map).unwrap(), j);
@@ -1913,24 +1923,107 @@ fn test_integer128_key() {
}
#[test]
-fn test_deny_float_key() {
- #[derive(Eq, PartialEq, Ord, PartialOrd)]
+fn test_float_key() {
+ #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone)]
struct Float;
impl Serialize for Float {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
- serializer.serialize_f32(1.0)
+ serializer.serialize_f32(1.23)
+ }
+ }
+ impl<'de> Deserialize<'de> for Float {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: de::Deserializer<'de>,
+ {
+ f32::deserialize(deserializer).map(|_| Float)
}
}
// map with float key
- let map = treemap!(Float => "x");
+ let map = treemap!(Float => "x".to_owned());
+ let j = r#"{"1.23":"x"}"#;
+
+ test_encode_ok(&[(&map, j)]);
+ test_parse_ok(vec![(j, map)]);
+
+ let j = r#"{"x": null}"#;
+ test_parse_err::<BTreeMap<Float, ()>>(&[(
+ j,
+ "invalid value: expected key to be a number in quotes at line 1 column 2",
+ )]);
+}
+
+#[test]
+fn test_deny_non_finite_f32_key() {
+ // We store float bits so that we can derive Ord, and other traits. In a
+ // real context the code might involve a crate like ordered-float.
+
+ #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone)]
+ struct F32Bits(u32);
+ impl Serialize for F32Bits {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_f32(f32::from_bits(self.0))
+ }
+ }
+
+ let map = treemap!(F32Bits(f32::INFINITY.to_bits()) => "x".to_owned());
+ assert!(serde_json::to_string(&map).is_err());
+ assert!(serde_json::to_value(map).is_err());
+
+ let map = treemap!(F32Bits(f32::NEG_INFINITY.to_bits()) => "x".to_owned());
+ assert!(serde_json::to_string(&map).is_err());
+ assert!(serde_json::to_value(map).is_err());
+
+ let map = treemap!(F32Bits(f32::NAN.to_bits()) => "x".to_owned());
+ assert!(serde_json::to_string(&map).is_err());
assert!(serde_json::to_value(map).is_err());
}
#[test]
+fn test_deny_non_finite_f64_key() {
+ // We store float bits so that we can derive Ord, and other traits. In a
+ // real context the code might involve a crate like ordered-float.
+
+ #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone)]
+ struct F64Bits(u64);
+ impl Serialize for F64Bits {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_f64(f64::from_bits(self.0))
+ }
+ }
+
+ let map = treemap!(F64Bits(f64::INFINITY.to_bits()) => "x".to_owned());
+ assert!(serde_json::to_string(&map).is_err());
+ assert!(serde_json::to_value(map).is_err());
+
+ let map = treemap!(F64Bits(f64::NEG_INFINITY.to_bits()) => "x".to_owned());
+ assert!(serde_json::to_string(&map).is_err());
+ assert!(serde_json::to_value(map).is_err());
+
+ let map = treemap!(F64Bits(f64::NAN.to_bits()) => "x".to_owned());
+ assert!(serde_json::to_string(&map).is_err());
+ assert!(serde_json::to_value(map).is_err());
+}
+
+#[test]
+fn test_boolean_key() {
+ let map = treemap!(false => 0, true => 1);
+ let j = r#"{"false":0,"true":1}"#;
+ test_encode_ok(&[(&map, j)]);
+ test_parse_ok(vec![(j, map)]);
+}
+
+#[test]
fn test_borrowed_key() {
let map: BTreeMap<&str, ()> = from_str("{\"borrowed\":null}").unwrap();
let expected = treemap! { "borrowed" => () };
@@ -1953,7 +2046,7 @@ fn test_effectively_string_keys() {
}
let map = treemap! {
Enum::One => 1,
- Enum::Two => 2
+ Enum::Two => 2,
};
let expected = r#"{"One":1,"Two":2}"#;
test_encode_ok(&[(&map, expected)]);
@@ -1963,7 +2056,7 @@ fn test_effectively_string_keys() {
struct Wrapper(String);
let map = treemap! {
Wrapper("zero".to_owned()) => 0,
- Wrapper("one".to_owned()) => 1
+ Wrapper("one".to_owned()) => 1,
};
let expected = r#"{"one":1,"zero":0}"#;
test_encode_ok(&[(&map, expected)]);
@@ -2145,8 +2238,8 @@ fn null_invalid_type() {
#[test]
fn test_integer128() {
- let signed = &[i128::min_value(), -1, 0, 1, i128::max_value()];
- let unsigned = &[0, 1, u128::max_value()];
+ let signed = &[i128::MIN, -1, 0, 1, i128::MAX];
+ let unsigned = &[0, 1, u128::MAX];
for integer128 in signed {
let expected = integer128.to_string();
@@ -2182,8 +2275,8 @@ fn test_integer128() {
#[test]
fn test_integer128_to_value() {
- let signed = &[i128::from(i64::min_value()), i128::from(u64::max_value())];
- let unsigned = &[0, u128::from(u64::max_value())];
+ let signed = &[i128::from(i64::MIN), i128::from(u64::MAX)];
+ let unsigned = &[0, u128::from(u64::MAX)];
for integer128 in signed {
let expected = integer128.to_string();
@@ -2196,7 +2289,7 @@ fn test_integer128_to_value() {
}
if !cfg!(feature = "arbitrary_precision") {
- let err = to_value(u128::from(u64::max_value()) + 1).unwrap_err();
+ let err = to_value(u128::from(u64::MAX) + 1).unwrap_err();
assert_eq!(err.to_string(), "number out of range");
}
}
@@ -2240,6 +2333,8 @@ fn test_raw_value_in_map_key() {
#[repr(transparent)]
struct RawMapKey(RawValue);
+ #[allow(unknown_lints)]
+ #[allow(non_local_definitions)] // false positive: https://github.com/rust-lang/rust/issues/121621
impl<'de> Deserialize<'de> for &'de RawMapKey {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -2384,25 +2479,27 @@ fn test_value_into_deserializer() {
let mut map = BTreeMap::new();
map.insert("inner", json!({ "string": "Hello World" }));
+ let outer = Outer::deserialize(serde::de::value::MapDeserializer::new(
+ map.iter().map(|(k, v)| (*k, v)),
+ ))
+ .unwrap();
+ assert_eq!(outer.inner.string, "Hello World");
+
let outer = Outer::deserialize(map.into_deserializer()).unwrap();
assert_eq!(outer.inner.string, "Hello World");
}
#[test]
fn hash_positive_and_negative_zero() {
- fn hash(obj: impl Hash) -> u64 {
- let mut hasher = DefaultHasher::new();
- obj.hash(&mut hasher);
- hasher.finish()
- }
+ let rand = std::hash::RandomState::new();
let k1 = serde_json::from_str::<Number>("0.0").unwrap();
let k2 = serde_json::from_str::<Number>("-0.0").unwrap();
if cfg!(feature = "arbitrary_precision") {
assert_ne!(k1, k2);
- assert_ne!(hash(k1), hash(k2));
+ assert_ne!(rand.hash_one(k1), rand.hash_one(k2));
} else {
assert_eq!(k1, k2);
- assert_eq!(hash(k1), hash(k2));
+ assert_eq!(rand.hash_one(k1), rand.hash_one(k2));
}
}
diff --git a/third_party/rust/serde_json/tests/ui/parse_key.stderr b/third_party/rust/serde_json/tests/ui/parse_key.stderr
index f10c21800e..15662dc507 100644
--- a/third_party/rust/serde_json/tests/ui/parse_key.stderr
+++ b/third_party/rust/serde_json/tests/ui/parse_key.stderr
@@ -2,4 +2,4 @@ error[E0609]: no field `s` on type `&'static str`
--> tests/ui/parse_key.rs:4:16
|
4 | json!({ "".s : true });
- | ^
+ | ^ unknown field