From 56fe9ac25f172c9dfb36187040e94bb5fd7b5a92 Mon Sep 17 00:00:00 2001 From: Dan Mosedale Date: Fri, 2 Oct 2020 01:10:38 +0000 Subject: [PATCH] Bug 1668704 - upgrade serde to 1.0.116 so we can vendor in Nimbus SDK r=markh Differential Revision: https://phabricator.services.mozilla.com/D92164 --- Cargo.lock | 8 +- third_party/rust/serde/.cargo-checksum.json | 2 +- third_party/rust/serde/Cargo.toml | 14 +- third_party/rust/serde/README.md | 28 ++- third_party/rust/serde/build.rs | 2 +- third_party/rust/serde/crates-io.md | 22 ++- third_party/rust/serde/src/de/impls.rs | 21 ++- third_party/rust/serde/src/de/mod.rs | 2 +- third_party/rust/serde/src/lib.rs | 30 ++- third_party/rust/serde/src/private/de.rs | 26 ++- third_party/rust/serde/src/private/ser.rs | 14 +- third_party/rust/serde/src/ser/fmt.rs | 174 ++++++++++++++++++ third_party/rust/serde/src/ser/impls.rs | 7 +- third_party/rust/serde/src/ser/mod.rs | 41 +---- .../rust/serde_derive/.cargo-checksum.json | 2 +- third_party/rust/serde_derive/Cargo.toml | 13 +- third_party/rust/serde_derive/README.md | 28 ++- third_party/rust/serde_derive/build.rs | 30 +++ third_party/rust/serde_derive/crates-io.md | 22 ++- third_party/rust/serde_derive/src/bound.rs | 8 +- third_party/rust/serde_derive/src/de.rs | 89 ++++----- third_party/rust/serde_derive/src/dummy.rs | 17 +- .../rust/serde_derive/src/internals/ast.rs | 10 +- .../rust/serde_derive/src/internals/attr.rs | 55 ++++-- .../rust/serde_derive/src/internals/check.rs | 4 +- .../rust/serde_derive/src/internals/mod.rs | 9 + third_party/rust/serde_derive/src/lib.rs | 67 ++++--- third_party/rust/serde_derive/src/ser.rs | 47 +++-- 28 files changed, 540 insertions(+), 252 deletions(-) create mode 100644 third_party/rust/serde/src/ser/fmt.rs create mode 100644 third_party/rust/serde_derive/build.rs diff --git a/Cargo.lock b/Cargo.lock index ab044ebdc962..47b2d26bfd69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4408,9 +4408,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.104" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" dependencies = [ "serde_derive", ] @@ -4426,9 +4426,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" dependencies = [ "proc-macro2", "quote", diff --git a/third_party/rust/serde/.cargo-checksum.json b/third_party/rust/serde/.cargo-checksum.json index 55a682e6173c..ce86133bd389 100644 --- a/third_party/rust/serde/.cargo-checksum.json +++ b/third_party/rust/serde/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"7bfd3feb65f16a263364f337fc01ae2d89323fd60976ba503ae8131bab2948ff","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"b919da154e92b23653a6d0432feb95f210cdac2617126f4e05c4842f170dc395","build.rs":"00972536ef079d36b6a547057ae423352b30da93554c5f22d33196e3e1753dbc","crates-io.md":"131dee2d4beaf83485aed22942b98815ef65af9bcfb65f02b5b90c59b8bc7b8b","src/de/from_primitive.rs":"058fa17313ed3a9c29ec04c6ec67f21a756f6f28cdeb4b0dfcd7012b3e702d0b","src/de/ignored_any.rs":"6a0527edd497a56a103ae65f5e73da675b3f99094d6dcad3c335c8d932daaf40","src/de/impls.rs":"d1677459c53e3ca99a2b6f3ae58d1ff9c906d953e3d27273f3bcf3fbad2e95d8","src/de/mod.rs":"0dd0c8bdefa86f621fdeba8f7b5575463c111bf034b0297e80d3aa8fedf40955","src/de/utf8.rs":"f17524ee0af98ec3abcfd7d0b812fbd1033263bd8e2ce2f57c1e1999ce153558","src/de/value.rs":"a878f6bdd57d25b0b93bfc6288ed1e46c50870dc8703748b6fbb8c0965a6b586","src/export.rs":"2ebdf0eccaa64c5e98c6dfd13b4980474f627fc3fae90cfc2c741acf860afd5d","src/integer128.rs":"b213ec6c1ecf8c8228d9591e0b2c31b78d972cd4c6a0b231468090f15784f6f6","src/lib.rs":"020f529e77865c1273e50337d6ec187a4f4f77d4572f8db3976837b35f1ebdf1","src/macros.rs":"f18fc25c5fb857238bf119cdee5c7987a8584dea69c51f27ca718b7dfd871d0f","src/private/de.rs":"87f7352697c1a711e57246d38eddcf81b61033f1f2a101bbf378ff6cc3f1ee3d","src/private/macros.rs":"ebb6affd4c89e3b5f9a42e03f8b7d966bc588875e9b44e962d0b7aba7f80a10f","src/private/mod.rs":"f8f2cd5edbfc26c268b34cdb89db1b34e6348f81384f03d18532e7568575006d","src/private/ser.rs":"67c085463d348806225f323eabd32b5bfd540ec8d78a1b515436af9b8a9636ec","src/ser/impls.rs":"741d6e24635911e65e31bc67d2596284a8e90b5682c975bacf11388e9b3d05e4","src/ser/impossible.rs":"3dd0e165b88fc67e698e675f16569b91fab9e054caa4c3e1997f929ba364fe90","src/ser/mod.rs":"3b90c5cb48d895a653ef94328c77e7956c7f4b6e0aaddd9101afabe87ff0f23a","src/std_error.rs":"3aac687856c035517fae44ed2906dd4a1e3184bae4bf613adcdeb73f74126c57"},"package":"414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"} \ No newline at end of file +{"files":{"Cargo.toml":"736542df95689176d660863d0493740313de4a030a09ffa2b5559c80223769ac","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"5cf9d2158d70048a2916360ad59d9079f6233c6f68781a7a792e70f8b772d8ce","build.rs":"d6af5a05be728765c2d98d960406ba648333745ed8644be311d2a1f52d7075f0","crates-io.md":"25ed421fe25d0f6f74c4b78674144bef2843a5f78bf552d0a8ec633be69d282b","src/de/from_primitive.rs":"058fa17313ed3a9c29ec04c6ec67f21a756f6f28cdeb4b0dfcd7012b3e702d0b","src/de/ignored_any.rs":"6a0527edd497a56a103ae65f5e73da675b3f99094d6dcad3c335c8d932daaf40","src/de/impls.rs":"077487d2bacd1fd2093e3ef2fa0d52abe7b9530a84d1ccf9eefb4ad81b6bbad1","src/de/mod.rs":"b59c365b05e4e09a7467c958f85b2c64435514c59c17275be019397ad7ccb00e","src/de/utf8.rs":"f17524ee0af98ec3abcfd7d0b812fbd1033263bd8e2ce2f57c1e1999ce153558","src/de/value.rs":"a878f6bdd57d25b0b93bfc6288ed1e46c50870dc8703748b6fbb8c0965a6b586","src/export.rs":"2ebdf0eccaa64c5e98c6dfd13b4980474f627fc3fae90cfc2c741acf860afd5d","src/integer128.rs":"b213ec6c1ecf8c8228d9591e0b2c31b78d972cd4c6a0b231468090f15784f6f6","src/lib.rs":"c8b0d22a63c9250342fbd3a3b263435e7bca98d9091a3bad5db026eac4877ef9","src/macros.rs":"f18fc25c5fb857238bf119cdee5c7987a8584dea69c51f27ca718b7dfd871d0f","src/private/de.rs":"bce814fa2f2fd689c6d4a354839f38d7ea260509339181ce83d9b0fdbe0e1b3b","src/private/macros.rs":"ebb6affd4c89e3b5f9a42e03f8b7d966bc588875e9b44e962d0b7aba7f80a10f","src/private/mod.rs":"f8f2cd5edbfc26c268b34cdb89db1b34e6348f81384f03d18532e7568575006d","src/private/ser.rs":"96a1e23ad7f3c8ee51a02d799d92780e19dd3c18fa0f1ad791abef7cb346e224","src/ser/fmt.rs":"7827ed07fd8897e6324f75625ba0c926a4c4e7ec2914cd067391ce54d942ac7b","src/ser/impls.rs":"ce9996998c6485c88bbc77516611e9f5a9a92cbb12d34bb4f8ae022530be85e0","src/ser/impossible.rs":"3dd0e165b88fc67e698e675f16569b91fab9e054caa4c3e1997f929ba364fe90","src/ser/mod.rs":"9c26100d8058a5c39aea72512fb78de959e4ed9199481eef47996f0864df0f2c","src/std_error.rs":"3aac687856c035517fae44ed2906dd4a1e3184bae4bf613adcdeb73f74126c57"},"package":"96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"} \ No newline at end of file diff --git a/third_party/rust/serde/Cargo.toml b/third_party/rust/serde/Cargo.toml index 972213272f3a..4e6fa348f2a9 100644 --- a/third_party/rust/serde/Cargo.toml +++ b/third_party/rust/serde/Cargo.toml @@ -12,10 +12,10 @@ [package] name = "serde" -version = "1.0.104" +version = "1.0.116" authors = ["Erick Tryzelaar ", "David Tolnay "] build = "build.rs" -include = ["Cargo.toml", "build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] description = "A generic serialization/deserialization framework" homepage = "https://serde.rs" documentation = "https://docs.serde.rs/serde/" @@ -24,10 +24,13 @@ keywords = ["serde", "serialization", "no_std"] categories = ["encoding"] license = "MIT OR Apache-2.0" repository = "https://github.com/serde-rs/serde" +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + [package.metadata.playground] features = ["derive", "rc"] [dependencies.serde_derive] -version = "=1.0.104" +version = "=1.0.116" optional = true [dev-dependencies.serde_derive] version = "1.0" @@ -39,8 +42,3 @@ derive = ["serde_derive"] rc = [] std = [] unstable = [] -[badges.appveyor] -repository = "serde-rs/serde" - -[badges.travis-ci] -repository = "serde-rs/serde" diff --git a/third_party/rust/serde/README.md b/third_party/rust/serde/README.md index 426ad6c1022a..14b00982e004 100644 --- a/third_party/rust/serde/README.md +++ b/third_party/rust/serde/README.md @@ -1,7 +1,7 @@ -# Serde   [![Build Status]][travis] [![Latest Version]][crates.io] [![serde: rustc 1.13+]][Rust 1.13] [![serde_derive: rustc 1.31+]][Rust 1.31] +# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.13+]][Rust 1.13] [![serde_derive: rustc 1.31+]][Rust 1.31] -[Build Status]: https://api.travis-ci.org/serde-rs/serde.svg?branch=master -[travis]: https://travis-ci.org/serde-rs/serde +[Build Status]: https://img.shields.io/github/workflow/status/serde-rs/serde/CI/master +[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster [Latest Version]: https://img.shields.io/crates/v/serde.svg [crates.io]: https://crates.io/crates/serde [serde: rustc 1.13+]: https://img.shields.io/badge/serde-rustc_1.13+-lightgray.svg @@ -75,13 +75,23 @@ fn main() { ## Getting help -Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The -\#rust channel is also a good resource with generally faster response time but -less specific knowledge about Serde. If IRC is not your thing or you don't get a -good response, we are happy to respond to [GitHub issues][issues] as well. +Serde is one of the most widely used Rust libraries so any place that Rustaceans +congregate will be able to help you out. For chat, consider trying the +[#general] or [#beginners] channels of the unofficial community Discord, the +[#rust-usage] channel of the official Rust Project Discord, or the +[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag +on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned +weekly easy questions post, or the Rust [Discourse forum][discourse]. It's +acceptable to file a support issue in this repo but they tend not to get as many +eyes as any of the above and may get closed without a response after some time. -[irc]: https://wiki.mozilla.org/IRC -[issues]: https://github.com/serde-rs/serde/issues/new/choose +[#general]: https://discord.com/channels/273534239310479360/274215136414400513 +[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281 +[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848 +[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general +[stackoverflow]: https://stackoverflow.com/questions/tagged/rust +[/r/rust]: https://www.reddit.com/r/rust +[discourse]: https://users.rust-lang.org
diff --git a/third_party/rust/serde/build.rs b/third_party/rust/serde/build.rs index 1453adf10707..613760811c7b 100644 --- a/third_party/rust/serde/build.rs +++ b/third_party/rust/serde/build.rs @@ -66,7 +66,7 @@ fn main() { } // Non-zero integers stabilized in Rust 1.28: - // https://github.com/rust-lang/rust/pull/50808 + // https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#library-stabilizations if minor >= 28 { println!("cargo:rustc-cfg=num_nonzero"); } diff --git a/third_party/rust/serde/crates-io.md b/third_party/rust/serde/crates-io.md index 3c6caa1a113e..07757614a7d4 100644 --- a/third_party/rust/serde/crates-io.md +++ b/third_party/rust/serde/crates-io.md @@ -43,10 +43,20 @@ fn main() { ## Getting help -Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The -\#rust channel is also a good resource with generally faster response time but -less specific knowledge about Serde. If IRC is not your thing or you don't get a -good response, we are happy to respond to [GitHub issues][issues] as well. +Serde is one of the most widely used Rust libraries so any place that Rustaceans +congregate will be able to help you out. For chat, consider trying the +[#general] or [#beginners] channels of the unofficial community Discord, the +[#rust-usage] channel of the official Rust Project Discord, or the +[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag +on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned +weekly easy questions post, or the Rust [Discourse forum][discourse]. It's +acceptable to file a support issue in this repo but they tend not to get as many +eyes as any of the above and may get closed without a response after some time. -[irc]: https://wiki.mozilla.org/IRC -[issues]: https://github.com/serde-rs/serde/issues/new/choose +[#general]: https://discord.com/channels/273534239310479360/274215136414400513 +[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281 +[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848 +[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general +[stackoverflow]: https://stackoverflow.com/questions/tagged/rust +[/r/rust]: https://www.reddit.com/r/rust +[discourse]: https://users.rust-lang.org diff --git a/third_party/rust/serde/src/de/impls.rs b/third_party/rust/serde/src/de/impls.rs index efd194ccc8cd..ae4f9dc806bf 100644 --- a/third_party/rust/serde/src/de/impls.rs +++ b/third_party/rust/serde/src/de/impls.rs @@ -90,10 +90,13 @@ macro_rules! visit_integer_method { { match FromPrimitive::$from_method(v) { Some(v) => Ok(v), - None => Err(Error::invalid_value(Unexpected::$group(v as $group_ty), &self)), + None => Err(Error::invalid_value( + Unexpected::$group(v as $group_ty), + &self, + )), } } - } + }; } macro_rules! visit_float_method { @@ -105,7 +108,7 @@ macro_rules! visit_float_method { { Ok(v as Self::Value) } - } + }; } macro_rules! impl_deserialize_num { @@ -1310,7 +1313,7 @@ macro_rules! variant_identifier { formatter.write_str($expecting_message) } - fn visit_u32(self, value: u32) -> Result + fn visit_u64(self, value: u64) -> Result where E: Error, { @@ -1318,7 +1321,7 @@ macro_rules! variant_identifier { $( $index => Ok($name_kind :: $variant), )* - _ => Err(Error::invalid_value(Unexpected::Unsigned(value as u64), &self),), + _ => Err(Error::invalid_value(Unexpected::Unsigned(value), &self),), } } @@ -2323,7 +2326,7 @@ where formatter.write_str("`Unbounded`, `Included` or `Excluded`") } - fn visit_u32(self, value: u32) -> Result + fn visit_u64(self, value: u64) -> Result where E: Error, { @@ -2332,7 +2335,7 @@ where 1 => Ok(Field::Included), 2 => Ok(Field::Excluded), _ => Err(Error::invalid_value( - Unexpected::Unsigned(value as u64), + Unexpected::Unsigned(value), &self, )), } @@ -2489,7 +2492,7 @@ where formatter.write_str("`Ok` or `Err`") } - fn visit_u32(self, value: u32) -> Result + fn visit_u64(self, value: u64) -> Result where E: Error, { @@ -2497,7 +2500,7 @@ where 0 => Ok(Field::Ok), 1 => Ok(Field::Err), _ => Err(Error::invalid_value( - Unexpected::Unsigned(value as u64), + Unexpected::Unsigned(value), &self, )), } diff --git a/third_party/rust/serde/src/de/mod.rs b/third_party/rust/serde/src/de/mod.rs index f1b8b3129ad7..6d39473633ea 100644 --- a/third_party/rust/serde/src/de/mod.rs +++ b/third_party/rust/serde/src/de/mod.rs @@ -104,7 +104,7 @@ //! [`Deserialize`]: ../trait.Deserialize.html //! [`Deserializer`]: ../trait.Deserializer.html //! [`LinkedHashMap`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html -//! [`bincode`]: https://github.com/TyOverby/bincode +//! [`bincode`]: https://github.com/servo/bincode //! [`linked-hash-map`]: https://crates.io/crates/linked-hash-map //! [`serde_derive`]: https://crates.io/crates/serde_derive //! [`serde_json`]: https://github.com/serde-rs/json diff --git a/third_party/rust/serde/src/lib.rs b/third_party/rust/serde/src/lib.rs index 6d1e298937ca..fe40eb1ca897 100644 --- a/third_party/rust/serde/src/lib.rs +++ b/third_party/rust/serde/src/lib.rs @@ -37,8 +37,8 @@ //! used for IPC within the Servo rendering engine. //! - [CBOR], a Concise Binary Object Representation designed for small message //! size without the need for version negotiation. -//! - [YAML], a popular human-friendly configuration language that ain't markup -//! language. +//! - [YAML], a self-proclaimed human-friendly configuration language that ain't +//! markup language. //! - [MessagePack], an efficient binary format that resembles a compact JSON. //! - [TOML], a minimal configuration format used by [Cargo]. //! - [Pickle], a format common in the Python world. @@ -48,14 +48,18 @@ //! definition. //! - [JSON5], A superset of JSON including some productions from ES5. //! - [Postcard], a no\_std and embedded-systems friendly compact binary format. -//! - [URL], the x-www-form-urlencoded format. +//! - [URL] query strings, in the x-www-form-urlencoded format. //! - [Envy], a way to deserialize environment variables into Rust structs. //! *(deserialization only)* //! - [Envy Store], a way to deserialize [AWS Parameter Store] parameters into //! Rust structs. *(deserialization only)* +//! - [S-expressions], the textual representation of code and data used by the +//! Lisp language family. +//! - [D-Bus]'s binary wire format. +//! - [FlexBuffers], the schemaless cousin of Google's FlatBuffers zero-copy serialization format. //! //! [JSON]: https://github.com/serde-rs/json -//! [Bincode]: https://github.com/TyOverby/bincode +//! [Bincode]: https://github.com/servo/bincode //! [CBOR]: https://github.com/pyfisch/cbor //! [YAML]: https://github.com/dtolnay/serde-yaml //! [MessagePack]: https://github.com/3Hren/msgpack-rust @@ -66,23 +70,26 @@ //! [Avro]: https://github.com/flavray/avro-rs //! [JSON5]: https://github.com/callum-oakley/json5-rs //! [Postcard]: https://github.com/jamesmunns/postcard -//! [URL]: https://github.com/nox/serde_urlencoded +//! [URL]: https://docs.rs/serde_qs //! [Envy]: https://github.com/softprops/envy //! [Envy Store]: https://github.com/softprops/envy-store //! [Cargo]: http://doc.crates.io/manifest.html //! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html +//! [S-expressions]: https://github.com/rotty/lexpr-rs +//! [D-Bus]: https://docs.rs/zvariant +//! [FlexBuffers]: https://github.com/google/flatbuffers/tree/master/rust/flexbuffers //////////////////////////////////////////////////////////////////////////////// // Serde types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/serde/1.0.104")] +#![doc(html_root_url = "https://docs.rs/serde/1.0.116")] // Support using Serde without the standard library! #![cfg_attr(not(feature = "std"), no_std)] // Unstable functionality only if the user asks for it. For tracking and // discussion of these features please refer to this issue: // // https://github.com/serde-rs/serde/issues/812 -#![cfg_attr(feature = "unstable", feature(specialization, never_type))] +#![cfg_attr(feature = "unstable", feature(never_type))] #![allow(unknown_lints, bare_trait_objects, deprecated)] #![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))] #![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] @@ -90,6 +97,8 @@ #![cfg_attr( feature = "cargo-clippy", allow( + // clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704 + unnested_or_patterns, // not available in our oldest supported compiler checked_conversions, empty_enum, @@ -102,23 +111,30 @@ // things are often more readable this way cast_lossless, module_name_repetitions, + option_if_let_else, single_match_else, type_complexity, use_self, zero_prefixed_literal, + // correctly used + enum_glob_use, + wildcard_imports, // not practical needless_pass_by_value, similar_names, too_many_lines, // preference doc_markdown, + unseparated_literal_suffix, // false positive needless_doctest_main, // noisy + missing_errors_doc, must_use_candidate, ) )] // Rustc lints. +#![forbid(unsafe_code)] #![deny(missing_docs, unused_imports)] //////////////////////////////////////////////////////////////////////////////// diff --git a/third_party/rust/serde/src/private/de.rs b/third_party/rust/serde/src/private/de.rs index 1c7fda3a1a13..bcb964a9c010 100644 --- a/third_party/rust/serde/src/private/de.rs +++ b/third_party/rust/serde/src/private/de.rs @@ -53,9 +53,10 @@ where } #[cfg(any(feature = "std", feature = "alloc"))] -pub fn borrow_cow_str<'de: 'a, 'a, D>(deserializer: D) -> Result, D::Error> +pub fn borrow_cow_str<'de: 'a, 'a, D, R>(deserializer: D) -> Result where D: Deserializer<'de>, + R: From>, { struct CowStrVisitor; @@ -121,13 +122,14 @@ where } } - deserializer.deserialize_str(CowStrVisitor) + deserializer.deserialize_str(CowStrVisitor).map(From::from) } #[cfg(any(feature = "std", feature = "alloc"))] -pub fn borrow_cow_bytes<'de: 'a, 'a, D>(deserializer: D) -> Result, D::Error> +pub fn borrow_cow_bytes<'de: 'a, 'a, D, R>(deserializer: D) -> Result where D: Deserializer<'de>, + R: From>, { struct CowBytesVisitor; @@ -181,7 +183,9 @@ where } } - deserializer.deserialize_bytes(CowBytesVisitor) + deserializer + .deserialize_bytes(CowBytesVisitor) + .map(From::from) } pub mod size_hint { @@ -1558,7 +1562,7 @@ mod content { other.unexpected(), &"struct variant", )), - _ => Err(de::Error::invalid_type( + None => Err(de::Error::invalid_type( de::Unexpected::UnitVariant, &"struct variant", )), @@ -2248,7 +2252,7 @@ mod content { other.unexpected(), &"struct variant", )), - _ => Err(de::Error::invalid_type( + None => Err(de::Error::invalid_type( de::Unexpected::UnitVariant, &"struct variant", )), @@ -2470,7 +2474,7 @@ mod content { where M: MapAccess<'de>, { - while let Some(_) = try!(access.next_entry::()) {} + while try!(access.next_entry::()).is_some() {} Ok(()) } } @@ -2759,6 +2763,13 @@ where } } + fn deserialize_unit(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + visitor.visit_unit() + } + forward_to_deserialize_other! { deserialize_bool() deserialize_i8() @@ -2776,7 +2787,6 @@ where deserialize_string() deserialize_bytes() deserialize_byte_buf() - deserialize_unit() deserialize_unit_struct(&'static str) deserialize_seq() deserialize_tuple(usize) diff --git a/third_party/rust/serde/src/private/ser.rs b/third_party/rust/serde/src/private/ser.rs index 4d9bce8c0d8d..eb8cfc9881ee 100644 --- a/third_party/rust/serde/src/private/ser.rs +++ b/third_party/rust/serde/src/private/ser.rs @@ -1124,7 +1124,7 @@ where } fn serialize_unit(self) -> Result { - Err(Self::bad_type(Unsupported::Unit)) + Ok(()) } fn serialize_unit_struct(self, _: &'static str) -> Result { @@ -1243,6 +1243,18 @@ where self.0.serialize_value(value) } + fn serialize_entry( + &mut self, + key: &K, + value: &V, + ) -> Result<(), Self::Error> + where + K: Serialize, + V: Serialize, + { + self.0.serialize_entry(key, value) + } + fn end(self) -> Result<(), Self::Error> { Ok(()) } diff --git a/third_party/rust/serde/src/ser/fmt.rs b/third_party/rust/serde/src/ser/fmt.rs new file mode 100644 index 000000000000..e7e09a1bfe94 --- /dev/null +++ b/third_party/rust/serde/src/ser/fmt.rs @@ -0,0 +1,174 @@ +use lib::*; +use ser::{Error, Impossible, Serialize, Serializer}; + +impl Error for fmt::Error { + fn custom(_msg: T) -> Self { + fmt::Error + } +} + +macro_rules! fmt_primitives { + ($($f:ident: $t:ty,)*) => { + $( + fn $f(self, v: $t) -> fmt::Result { + Display::fmt(&v, self) + } + )* + }; +} + +/// ```edition2018 +/// use serde::Serialize; +/// use std::fmt::{self, Display}; +/// +/// #[derive(Serialize)] +/// #[serde(rename_all = "kebab-case")] +/// pub enum MessageType { +/// StartRequest, +/// EndRequest, +/// } +/// +/// impl Display for MessageType { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// self.serialize(f) +/// } +/// } +/// ``` +impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> { + type Ok = (); + type Error = fmt::Error; + type SerializeSeq = Impossible<(), fmt::Error>; + type SerializeTuple = Impossible<(), fmt::Error>; + type SerializeTupleStruct = Impossible<(), fmt::Error>; + type SerializeTupleVariant = Impossible<(), fmt::Error>; + type SerializeMap = Impossible<(), fmt::Error>; + type SerializeStruct = Impossible<(), fmt::Error>; + type SerializeStructVariant = Impossible<(), fmt::Error>; + + fmt_primitives! { + serialize_bool: bool, + serialize_i8: i8, + serialize_i16: i16, + serialize_i32: i32, + serialize_i64: i64, + serialize_u8: u8, + serialize_u16: u16, + serialize_u32: u32, + serialize_u64: u64, + serialize_f32: f32, + serialize_f64: f64, + serialize_char: char, + serialize_str: &str, + serialize_unit_struct: &'static str, + } + + serde_if_integer128! { + fmt_primitives! { + serialize_i128: i128, + serialize_u128: u128, + } + } + + fn serialize_unit_variant( + self, + _name: &'static str, + _variant_index: u32, + variant: &'static str, + ) -> fmt::Result { + Display::fmt(variant, self) + } + + fn serialize_newtype_struct(self, _name: &'static str, value: &T) -> fmt::Result + where + T: Serialize, + { + Serialize::serialize(value, self) + } + + fn serialize_bytes(self, _v: &[u8]) -> fmt::Result { + Err(fmt::Error) + } + + fn serialize_none(self) -> fmt::Result { + Err(fmt::Error) + } + + fn serialize_some(self, _value: &T) -> fmt::Result + where + T: Serialize, + { + Err(fmt::Error) + } + + fn serialize_unit(self) -> fmt::Result { + Err(fmt::Error) + } + + fn serialize_newtype_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + _value: &T, + ) -> fmt::Result + where + T: Serialize, + { + Err(fmt::Error) + } + + fn serialize_seq(self, _len: Option) -> Result { + Err(fmt::Error) + } + + fn serialize_tuple(self, _len: usize) -> Result { + Err(fmt::Error) + } + + fn serialize_tuple_struct( + self, + _name: &'static str, + _len: usize, + ) -> Result { + Err(fmt::Error) + } + + fn serialize_tuple_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + _len: usize, + ) -> Result { + Err(fmt::Error) + } + + fn serialize_map(self, _len: Option) -> Result { + Err(fmt::Error) + } + + fn serialize_struct( + self, + _name: &'static str, + _len: usize, + ) -> Result { + Err(fmt::Error) + } + + fn serialize_struct_variant( + self, + _name: &'static str, + _variant_index: u32, + _variant: &'static str, + _len: usize, + ) -> Result { + Err(fmt::Error) + } + + fn collect_str(self, value: &T) -> fmt::Result + where + T: Display, + { + Display::fmt(value, self) + } +} diff --git a/third_party/rust/serde/src/ser/impls.rs b/third_party/rust/serde/src/ser/impls.rs index 0ac667dbfc4a..0dc8085f4948 100644 --- a/third_party/rust/serde/src/ser/impls.rs +++ b/third_party/rust/serde/src/ser/impls.rs @@ -616,7 +616,7 @@ impl Serialize for SystemTime { use super::SerializeStruct; let duration_since_epoch = self .duration_since(UNIX_EPOCH) - .expect("SystemTime must be later than UNIX_EPOCH"); + .map_err(|_| S::Error::custom("SystemTime must be later than UNIX_EPOCH"))?; let mut state = try!(serializer.serialize_struct("SystemTime", 2)); try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs())); try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos())); @@ -633,8 +633,7 @@ impl Serialize for SystemTime { #[cfg(feature = "std")] macro_rules! serialize_display_bounded_length { ($value:expr, $max:expr, $serializer:expr) => {{ - #[allow(deprecated)] - let mut buffer: [u8; $max] = unsafe { mem::uninitialized() }; + let mut buffer = [0u8; $max]; let remaining_len = { let mut remaining = &mut buffer[..]; write!(remaining, "{}", $value).unwrap(); @@ -646,7 +645,7 @@ macro_rules! serialize_display_bounded_length { // write! only provides fmt::Formatter to Display implementations, which // has methods write_str and write_char but no method to write arbitrary // bytes. Therefore `written` must be valid UTF-8. - let written_str = unsafe { str::from_utf8_unchecked(written) }; + let written_str = str::from_utf8(written).expect("must be valid UTF-8"); $serializer.serialize_str(written_str) }}; } diff --git a/third_party/rust/serde/src/ser/mod.rs b/third_party/rust/serde/src/ser/mod.rs index 8fb2434fa41f..8a4b2e366964 100644 --- a/third_party/rust/serde/src/ser/mod.rs +++ b/third_party/rust/serde/src/ser/mod.rs @@ -99,7 +99,7 @@ //! [`LinkedHashMap`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html //! [`Serialize`]: ../trait.Serialize.html //! [`Serializer`]: ../trait.Serializer.html -//! [`bincode`]: https://github.com/TyOverby/bincode +//! [`bincode`]: https://github.com/servo/bincode //! [`linked-hash-map`]: https://crates.io/crates/linked-hash-map //! [`serde_derive`]: https://crates.io/crates/serde_derive //! [`serde_json`]: https://github.com/serde-rs/json @@ -109,6 +109,7 @@ use lib::*; +mod fmt; mod impls; mod impossible; @@ -1277,7 +1278,7 @@ pub trait Serializer: Sized { ::Item: Serialize, { let iter = iter.into_iter(); - let mut serializer = try!(self.serialize_seq(iter.len_hint())); + let mut serializer = try!(self.serialize_seq(iterator_len_hint(&iter))); for item in iter { try!(serializer.serialize_element(&item)); } @@ -1317,7 +1318,7 @@ pub trait Serializer: Sized { I: IntoIterator, { let iter = iter.into_iter(); - let mut serializer = try!(self.serialize_map(iter.len_hint())); + let mut serializer = try!(self.serialize_map(iterator_len_hint(&iter))); for (key, value) in iter { try!(serializer.serialize_entry(&key, &value)); } @@ -1359,10 +1360,7 @@ pub trait Serializer: Sized { where T: Display, { - use lib::fmt::Write; - let mut string = String::new(); - write!(string, "{}", value).unwrap(); - self.serialize_str(&string) + self.serialize_str(&value.to_string()) } /// Serialize a string produced by an implementation of `Display`. @@ -1955,35 +1953,6 @@ pub trait SerializeStructVariant { fn end(self) -> Result; } -trait LenHint: Iterator { - fn len_hint(&self) -> Option; -} - -impl LenHint for I -where - I: Iterator, -{ - #[cfg(not(feature = "unstable"))] - fn len_hint(&self) -> Option { - iterator_len_hint(self) - } - - #[cfg(feature = "unstable")] - default fn len_hint(&self) -> Option { - iterator_len_hint(self) - } -} - -#[cfg(feature = "unstable")] -impl LenHint for I -where - I: ExactSizeIterator, -{ - fn len_hint(&self) -> Option { - Some(self.len()) - } -} - fn iterator_len_hint(iter: &I) -> Option where I: Iterator, diff --git a/third_party/rust/serde_derive/.cargo-checksum.json b/third_party/rust/serde_derive/.cargo-checksum.json index 128e19d427bb..915ba422d66f 100644 --- a/third_party/rust/serde_derive/.cargo-checksum.json +++ b/third_party/rust/serde_derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"8af4d75ed437af2996977a82edd6cec6581323408be0d5bce95bc4a9b06e1abd","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"b919da154e92b23653a6d0432feb95f210cdac2617126f4e05c4842f170dc395","crates-io.md":"131dee2d4beaf83485aed22942b98815ef65af9bcfb65f02b5b90c59b8bc7b8b","src/bound.rs":"3db01a4e6820cca4a543f1eea33bbdadc8ba03912c3de5d3eee001f4b8676c4e","src/de.rs":"55725e8fb87c77534754077f60b48bcd5c03f8b2a7a9a53c075ed97e861acc07","src/dummy.rs":"911edb959db048500c865517f68f4077f95d2bd653da21054ee9c1261c6a497a","src/fragment.rs":"5548ba65a53d90a296f60c1328a7a7fb040db467f59c2f5210b2fb320457145d","src/internals/ast.rs":"dbcde9eb31fd33e9a386f56cdf8cd2dd8a6855e491002864a8d29d6e125524ec","src/internals/attr.rs":"1e4c751fef7c6afa4102812eff44103e2173597ec78e74d0786688126a8def24","src/internals/case.rs":"b2024f414f5d832bafa53b9ae7924b2d43a29175b19bb3da36f15c9071666558","src/internals/check.rs":"15d5226997b1e46aae28a305648f37920bd2eb00a140e96c9206fce9ac6562cc","src/internals/ctxt.rs":"6fa544ae52914498a62a395818ebdc1b36ac2fb5903c60afb741a864ad559f1c","src/internals/mod.rs":"0ee6cb3c55ac8a5907f1938748c8fd934d5138a06525d13163f05110dc7cf7e8","src/internals/symbol.rs":"9f2b4b9cd83dc09def75165187c97d0050bffa4218782c27b478bcf93f925a74","src/lib.rs":"d73d85272d1e7499099a7a07f5fc03ccae3143d2cfb0d281f37b942f3021bfa0","src/pretend.rs":"ffeb23da4c2abc4e501c378cffa8b776bab506735ea70d4ed10f4c0f3755321b","src/ser.rs":"eb7eaf8d447119449d5136be741552d1ae34a88de82901642158bc6abd4c1b51","src/try.rs":"b9a10c8690d442a57fc7097d42c9a4f13034c7b4a30b7eb02d538fdbf8ae0a8d"},"package":"128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"} \ No newline at end of file +{"files":{"Cargo.toml":"74677f4031ffe40137aad8407d240dfe0bd3ed5d07c518afb1983b384f4ee283","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"5cf9d2158d70048a2916360ad59d9079f6233c6f68781a7a792e70f8b772d8ce","build.rs":"17fac4a28904e90c1e46b517839bd17fd54dbc69cfbff7451f695ecf7bab34ef","crates-io.md":"25ed421fe25d0f6f74c4b78674144bef2843a5f78bf552d0a8ec633be69d282b","src/bound.rs":"66643d6cd044a2167b2bb8a1970e5b2a07069e362ce1326a4b00fef7bcfcd5c8","src/de.rs":"8bea1aa8057c824264bb4700fa6531747bfaed88be2d1f90bb6455600aa8e222","src/dummy.rs":"7bc4267039808046fe0a7fbeb462b301ac30ea1152fcbde8a3b934dc143fe468","src/fragment.rs":"5548ba65a53d90a296f60c1328a7a7fb040db467f59c2f5210b2fb320457145d","src/internals/ast.rs":"f1a1b13cf6b68e2bf27c5cdcdbde6883f86cde1ba8c0595dffdbf2e11c4ec8b1","src/internals/attr.rs":"554bf48da8fb4e8a5ac2d16143cc9dc05e9bc493b4a4c8a196ace360bce110d5","src/internals/case.rs":"b2024f414f5d832bafa53b9ae7924b2d43a29175b19bb3da36f15c9071666558","src/internals/check.rs":"9a01a0db1fc3086891e998f544836e7498ebfc7cc5e1956199d0526e6a8d9a3c","src/internals/ctxt.rs":"6fa544ae52914498a62a395818ebdc1b36ac2fb5903c60afb741a864ad559f1c","src/internals/mod.rs":"989df41dae7a9066eec3e5afd5b262fd94a12281df30f4c03f319370811beea0","src/internals/symbol.rs":"9f2b4b9cd83dc09def75165187c97d0050bffa4218782c27b478bcf93f925a74","src/lib.rs":"ae786031bb024d49a73e8c0aee126441a9e61dd2bc50ddf7aad4a586fa89081d","src/pretend.rs":"ffeb23da4c2abc4e501c378cffa8b776bab506735ea70d4ed10f4c0f3755321b","src/ser.rs":"4ac3d23e5a84b72137d42eaa38ef8ec1516c4d4d9ca040dc5ce2abbf33126443","src/try.rs":"b9a10c8690d442a57fc7097d42c9a4f13034c7b4a30b7eb02d538fdbf8ae0a8d"},"package":"f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8"} \ No newline at end of file diff --git a/third_party/rust/serde_derive/Cargo.toml b/third_party/rust/serde_derive/Cargo.toml index 4d462cb69c5a..d06a1bb40a6c 100644 --- a/third_party/rust/serde_derive/Cargo.toml +++ b/third_party/rust/serde_derive/Cargo.toml @@ -12,9 +12,9 @@ [package] name = "serde_derive" -version = "1.0.104" +version = "1.0.116" authors = ["Erick Tryzelaar ", "David Tolnay "] -include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]" homepage = "https://serde.rs" documentation = "https://serde.rs/derive.html" @@ -22,6 +22,8 @@ readme = "crates-io.md" keywords = ["serde", "serialization", "no_std"] license = "MIT OR Apache-2.0" repository = "https://github.com/serde-rs/serde" +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] [lib] name = "serde_derive" @@ -33,7 +35,7 @@ version = "1.0" version = "1.0" [dependencies.syn] -version = "1.0" +version = "1.0.33" features = ["visit"] [dev-dependencies.serde] version = "1.0" @@ -41,8 +43,3 @@ version = "1.0" [features] default = [] deserialize_in_place = [] -[badges.appveyor] -repository = "serde-rs/serde" - -[badges.travis-ci] -repository = "serde-rs/serde" diff --git a/third_party/rust/serde_derive/README.md b/third_party/rust/serde_derive/README.md index 426ad6c1022a..14b00982e004 100644 --- a/third_party/rust/serde_derive/README.md +++ b/third_party/rust/serde_derive/README.md @@ -1,7 +1,7 @@ -# Serde   [![Build Status]][travis] [![Latest Version]][crates.io] [![serde: rustc 1.13+]][Rust 1.13] [![serde_derive: rustc 1.31+]][Rust 1.31] +# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.13+]][Rust 1.13] [![serde_derive: rustc 1.31+]][Rust 1.31] -[Build Status]: https://api.travis-ci.org/serde-rs/serde.svg?branch=master -[travis]: https://travis-ci.org/serde-rs/serde +[Build Status]: https://img.shields.io/github/workflow/status/serde-rs/serde/CI/master +[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster [Latest Version]: https://img.shields.io/crates/v/serde.svg [crates.io]: https://crates.io/crates/serde [serde: rustc 1.13+]: https://img.shields.io/badge/serde-rustc_1.13+-lightgray.svg @@ -75,13 +75,23 @@ fn main() { ## Getting help -Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The -\#rust channel is also a good resource with generally faster response time but -less specific knowledge about Serde. If IRC is not your thing or you don't get a -good response, we are happy to respond to [GitHub issues][issues] as well. +Serde is one of the most widely used Rust libraries so any place that Rustaceans +congregate will be able to help you out. For chat, consider trying the +[#general] or [#beginners] channels of the unofficial community Discord, the +[#rust-usage] channel of the official Rust Project Discord, or the +[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag +on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned +weekly easy questions post, or the Rust [Discourse forum][discourse]. It's +acceptable to file a support issue in this repo but they tend not to get as many +eyes as any of the above and may get closed without a response after some time. -[irc]: https://wiki.mozilla.org/IRC -[issues]: https://github.com/serde-rs/serde/issues/new/choose +[#general]: https://discord.com/channels/273534239310479360/274215136414400513 +[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281 +[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848 +[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general +[stackoverflow]: https://stackoverflow.com/questions/tagged/rust +[/r/rust]: https://www.reddit.com/r/rust +[discourse]: https://users.rust-lang.org
diff --git a/third_party/rust/serde_derive/build.rs b/third_party/rust/serde_derive/build.rs new file mode 100644 index 000000000000..6e1b7b6dd6ef --- /dev/null +++ b/third_party/rust/serde_derive/build.rs @@ -0,0 +1,30 @@ +use std::env; +use std::process::Command; +use std::str; + +// The rustc-cfg strings below are *not* public API. Please let us know by +// opening a GitHub issue if your build environment requires some way to enable +// these cfgs other than by executing our build script. +fn main() { + let minor = match rustc_minor_version() { + Some(minor) => minor, + None => return, + }; + + // Underscore const names stabilized in Rust 1.37: + // https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros + if minor >= 37 { + println!("cargo:rustc-cfg=underscore_consts"); + } +} + +fn rustc_minor_version() -> Option { + 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; + } + pieces.next()?.parse().ok() +} diff --git a/third_party/rust/serde_derive/crates-io.md b/third_party/rust/serde_derive/crates-io.md index 3c6caa1a113e..07757614a7d4 100644 --- a/third_party/rust/serde_derive/crates-io.md +++ b/third_party/rust/serde_derive/crates-io.md @@ -43,10 +43,20 @@ fn main() { ## Getting help -Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The -\#rust channel is also a good resource with generally faster response time but -less specific knowledge about Serde. If IRC is not your thing or you don't get a -good response, we are happy to respond to [GitHub issues][issues] as well. +Serde is one of the most widely used Rust libraries so any place that Rustaceans +congregate will be able to help you out. For chat, consider trying the +[#general] or [#beginners] channels of the unofficial community Discord, the +[#rust-usage] channel of the official Rust Project Discord, or the +[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag +on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned +weekly easy questions post, or the Rust [Discourse forum][discourse]. It's +acceptable to file a support issue in this repo but they tend not to get as many +eyes as any of the above and may get closed without a response after some time. -[irc]: https://wiki.mozilla.org/IRC -[issues]: https://github.com/serde-rs/serde/issues/new/choose +[#general]: https://discord.com/channels/273534239310479360/274215136414400513 +[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281 +[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848 +[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general +[stackoverflow]: https://stackoverflow.com/questions/tagged/rust +[/r/rust]: https://www.reddit.com/r/rust +[discourse]: https://users.rust-lang.org diff --git a/third_party/rust/serde_derive/src/bound.rs b/third_party/rust/serde_derive/src/bound.rs index 293540abe3fc..ec2eafe89fcb 100644 --- a/third_party/rust/serde_derive/src/bound.rs +++ b/third_party/rust/serde_derive/src/bound.rs @@ -5,7 +5,7 @@ use syn::punctuated::{Pair, Punctuated}; use syn::visit::{self, Visit}; use internals::ast::{Container, Data}; -use internals::attr; +use internals::{attr, ungroup}; use proc_macro2::Span; @@ -114,7 +114,7 @@ pub fn with_bound( } impl<'ast> Visit<'ast> for FindTyParams<'ast> { fn visit_field(&mut self, field: &'ast syn::Field) { - if let syn::Type::Path(ty) = &field.ty { + if let syn::Type::Path(ty) = ungroup(&field.ty) { if let Some(Pair::Punctuated(t, _)) = ty.path.segments.pairs().next() { if self.all_type_params.contains(&t.ident) { self.associated_type_usage.push(ty); @@ -156,7 +156,7 @@ pub fn with_bound( .collect(); let mut visitor = FindTyParams { - all_type_params: all_type_params, + all_type_params, relevant_type_params: HashSet::new(), associated_type_usage: Vec::new(), }; @@ -271,7 +271,7 @@ pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Gen .collect(); syn::Generics { - params: params, + params, ..generics.clone() } } diff --git a/third_party/rust/serde_derive/src/de.rs b/third_party/rust/serde_derive/src/de.rs index 64113a603fbf..1f5733a6d5ed 100644 --- a/third_party/rust/serde_derive/src/de.rs +++ b/third_party/rust/serde_derive/src/de.rs @@ -8,7 +8,7 @@ use bound; use dummy; use fragment::{Expr, Fragment, Match, Stmts}; use internals::ast::{Container, Data, Field, Style, Variant}; -use internals::{attr, Ctxt, Derive}; +use internals::{attr, ungroup, Ctxt, Derive}; use pretend; use std::collections::BTreeSet; @@ -77,7 +77,7 @@ fn precondition(cx: &Ctxt, cont: &Container) { fn precondition_sized(cx: &Ctxt, cont: &Container) { if let Data::Struct(_, fields) = &cont.data { if let Some(last) = fields.last() { - if let syn::Type::Slice(_) = *last.ty { + if let syn::Type::Slice(_) = ungroup(last.ty) { cx.error_spanned_by( cont.original, "cannot deserialize a dynamically sized struct", @@ -134,11 +134,11 @@ impl Parameters { let has_getter = cont.data.has_getter(); Parameters { - local: local, - this: this, - generics: generics, - borrowed: borrowed, - has_getter: has_getter, + local, + this, + generics, + borrowed, + has_getter, } } @@ -310,12 +310,7 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option { - if let Some(code) = deserialize_struct_in_place(None, params, fields, &cont.attrs, None) - { - code - } else { - return None; - } + deserialize_struct_in_place(None, params, fields, &cont.attrs, None)? } Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => { deserialize_tuple_in_place(None, params, fields, &cont.attrs, None) @@ -1158,10 +1153,13 @@ fn prepare_enum_variant_enum( variants: &[Variant], cattrs: &attr::Container, ) -> (TokenStream, Stmts) { - let variant_names_idents: Vec<_> = variants + let mut deserialized_variants = variants .iter() .enumerate() - .filter(|&(_, variant)| !variant.attrs.skip_deserializing()) + .filter(|&(_, variant)| !variant.attrs.skip_deserializing()); + + let variant_names_idents: Vec<_> = deserialized_variants + .clone() .map(|(i, variant)| { ( variant.attrs.name().deserialize_name(), @@ -1171,7 +1169,7 @@ fn prepare_enum_variant_enum( }) .collect(); - let other_idx = variants.iter().position(|variant| variant.attrs.other()); + let other_idx = deserialized_variants.position(|(_, variant)| variant.attrs.other()); let variants_stmt = { let variant_names = variant_names_idents.iter().map(|(name, _, _)| name); @@ -1379,39 +1377,44 @@ fn deserialize_adjacently_tagged_enum( } }; - fn is_unit(variant: &Variant) -> bool { - match variant.style { - Style::Unit => true, - Style::Struct | Style::Tuple | Style::Newtype => false, - } - } - let mut missing_content = quote! { _serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content)) }; - if variants.iter().any(is_unit) { - let fallthrough = if variants.iter().all(is_unit) { - None - } else { - Some(quote! { - _ => #missing_content - }) - }; - let arms = variants - .iter() - .enumerate() - .filter(|&(_, variant)| !variant.attrs.skip_deserializing() && is_unit(variant)) - .map(|(i, variant)| { - let variant_index = field_i(i); - let variant_ident = &variant.ident; - quote! { - __Field::#variant_index => _serde::export::Ok(#this::#variant_ident), + let mut missing_content_fallthrough = quote!(); + let missing_content_arms = variants + .iter() + .enumerate() + .filter(|&(_, variant)| !variant.attrs.skip_deserializing()) + .filter_map(|(i, variant)| { + let variant_index = field_i(i); + let variant_ident = &variant.ident; + + let arm = match variant.style { + Style::Unit => quote! { + _serde::export::Ok(#this::#variant_ident) + }, + Style::Newtype if variant.attrs.deserialize_with().is_none() => { + let span = variant.original.span(); + let func = quote_spanned!(span=> _serde::private::de::missing_field); + quote! { + #func(#content).map(#this::#variant_ident) + } } - }); + _ => { + missing_content_fallthrough = quote!(_ => #missing_content); + return None; + } + }; + Some(quote! { + __Field::#variant_index => #arm, + }) + }) + .collect::>(); + if !missing_content_arms.is_empty() { missing_content = quote! { match __field { - #(#arms)* - #fallthrough + #(#missing_content_arms)* + #missing_content_fallthrough } }; } diff --git a/third_party/rust/serde_derive/src/dummy.rs b/third_party/rust/serde_derive/src/dummy.rs index 90a3514caec2..9a4e5f085fd5 100644 --- a/third_party/rust/serde_derive/src/dummy.rs +++ b/third_party/rust/serde_derive/src/dummy.rs @@ -1,4 +1,5 @@ -use proc_macro2::{Ident, Span, TokenStream}; +use proc_macro2::{Ident, TokenStream}; +use quote::format_ident; use syn; use try; @@ -11,24 +12,24 @@ pub fn wrap_in_const( ) -> TokenStream { let try_replacement = try::replacement(); - let dummy_const = Ident::new( - &format!("_IMPL_{}_FOR_{}", trait_, unraw(ty)), - Span::call_site(), - ); + let dummy_const = if cfg!(underscore_consts) { + format_ident!("_") + } else { + format_ident!("_IMPL_{}_FOR_{}", trait_, unraw(ty)) + }; let use_serde = match serde_path { Some(path) => quote! { use #path as _serde; }, None => quote! { - #[allow(unknown_lints)] - #[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))] - #[allow(rust_2018_idioms)] + #[allow(rust_2018_idioms, clippy::useless_attribute)] extern crate serde as _serde; }, }; quote! { + #[doc(hidden)] #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const #dummy_const: () = { #use_serde diff --git a/third_party/rust/serde_derive/src/internals/ast.rs b/third_party/rust/serde_derive/src/internals/ast.rs index 415a6ea659dc..1afdaee540fd 100644 --- a/third_party/rust/serde_derive/src/internals/ast.rs +++ b/third_party/rust/serde_derive/src/internals/ast.rs @@ -110,8 +110,8 @@ impl<'a> Container<'a> { let mut item = Container { ident: item.ident.clone(), - attrs: attrs, - data: data, + attrs, + data, generics: &item.generics, original: item, }; @@ -148,9 +148,9 @@ fn enum_from_ast<'a>( struct_from_ast(cx, &variant.fields, Some(&attrs), container_default); Variant { ident: variant.ident.clone(), - attrs: attrs, - style: style, - fields: fields, + attrs, + style, + fields, original: variant, } }) diff --git a/third_party/rust/serde_derive/src/internals/attr.rs b/third_party/rust/serde_derive/src/internals/attr.rs index 0a5595dc7c46..e6f72dfe7f6f 100644 --- a/third_party/rust/serde_derive/src/internals/attr.rs +++ b/third_party/rust/serde_derive/src/internals/attr.rs @@ -1,5 +1,5 @@ use internals::symbol::*; -use internals::Ctxt; +use internals::{ungroup, Ctxt}; use proc_macro2::{Group, Span, TokenStream, TokenTree}; use quote::ToTokens; use std::borrow::Cow; @@ -32,8 +32,8 @@ struct Attr<'c, T> { impl<'c, T> Attr<'c, T> { fn none(cx: &'c Ctxt, name: Symbol) -> Self { Attr { - cx: cx, - name: name, + cx, + name, tokens: TokenStream::new(), value: None, } @@ -101,8 +101,8 @@ struct VecAttr<'c, T> { impl<'c, T> VecAttr<'c, T> { fn none(cx: &'c Ctxt, name: Symbol) -> Self { VecAttr { - cx: cx, - name: name, + cx, + name, first_dup_tokens: TokenStream::new(), values: Vec::new(), } @@ -176,7 +176,7 @@ impl Name { serialize_renamed: ser_renamed, deserialize: de_name.unwrap_or(source_name), deserialize_renamed: de_renamed, - deserialize_aliases: deserialize_aliases, + deserialize_aliases, } } @@ -222,6 +222,7 @@ pub struct Container { identifier: Identifier, has_flatten: bool, serde_path: Option, + is_packed: bool, } /// Styles of representing an enum. @@ -592,6 +593,20 @@ impl Container { } } + let mut is_packed = false; + for attr in &item.attrs { + if attr.path.is_ident("repr") { + let _ = attr.parse_args_with(|input: ParseStream| { + while let Some(token) = input.parse()? { + if let TokenTree::Ident(ident) = token { + is_packed |= ident == "packed"; + } + } + Ok(()) + }); + } + } + Container { name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None), transparent: transparent.get(), @@ -611,6 +626,7 @@ impl Container { identifier: decide_identifier(cx, item, field_identifier, variant_identifier), has_flatten: false, serde_path: serde_path.get(), + is_packed, } } @@ -662,6 +678,10 @@ impl Container { self.remote.as_ref() } + pub fn is_packed(&self) -> bool { + self.is_packed + } + pub fn identifier(&self) -> Identifier { self.identifier } @@ -716,7 +736,7 @@ fn decide_tag( } } } - TagType::Internal { tag: tag } + TagType::Internal { tag } } (Some((untagged_tokens, _)), Some((tag_tokens, _)), None) => { cx.error_spanned_by( @@ -747,10 +767,7 @@ fn decide_tag( ); TagType::External } - (None, Some((_, tag)), Some((_, content))) => TagType::Adjacent { - tag: tag, - content: content, - }, + (None, Some((_, tag)), Some((_, content))) => TagType::Adjacent { tag, content }, (Some((untagged_tokens, _)), Some((tag_tokens, _)), Some((content_tokens, _))) => { cx.error_spanned_by( untagged_tokens, @@ -1383,7 +1400,7 @@ impl Field { let expr = syn::ExprPath { attrs: Vec::new(), qself: None, - path: path, + path, }; deserialize_with.set_if_none(expr); } else if is_cow(&field.ty, is_slice_u8) { @@ -1400,7 +1417,7 @@ impl Field { let expr = syn::ExprPath { attrs: Vec::new(), qself: None, - path: path, + path, }; deserialize_with.set_if_none(expr); } @@ -1420,7 +1437,7 @@ impl Field { deserialize_with: deserialize_with.get(), ser_bound: ser_bound.get(), de_bound: de_bound.get(), - borrowed_lifetimes: borrowed_lifetimes, + borrowed_lifetimes, getter: getter.get(), flatten: flatten.get(), transparent: false, @@ -1724,7 +1741,7 @@ fn is_implicitly_borrowed_reference(ty: &syn::Type) -> bool { // cow: Cow<'a, str>, // } fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool { - let path = match ty { + let path = match ungroup(ty) { syn::Type::Path(ty) => &ty.path, _ => { return false; @@ -1751,7 +1768,7 @@ fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool { } fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool { - let path = match ty { + let path = match ungroup(ty) { syn::Type::Path(ty) => &ty.path, _ => { return false; @@ -1798,7 +1815,7 @@ fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool { // r: &'a str, // } fn is_reference(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool { - match ty { + match ungroup(ty) { syn::Type::Reference(ty) => ty.mutability.is_none() && elem(&ty.elem), _ => false, } @@ -1809,14 +1826,14 @@ fn is_str(ty: &syn::Type) -> bool { } fn is_slice_u8(ty: &syn::Type) -> bool { - match ty { + match ungroup(ty) { syn::Type::Slice(ty) => is_primitive_type(&ty.elem, "u8"), _ => false, } } fn is_primitive_type(ty: &syn::Type, primitive: &str) -> bool { - match ty { + match ungroup(ty) { syn::Type::Path(ty) => ty.qself.is_none() && is_primitive_path(&ty.path, primitive), _ => false, } diff --git a/third_party/rust/serde_derive/src/internals/check.rs b/third_party/rust/serde_derive/src/internals/check.rs index bf4cb170bf5c..30ede1ce5821 100644 --- a/third_party/rust/serde_derive/src/internals/check.rs +++ b/third_party/rust/serde_derive/src/internals/check.rs @@ -1,6 +1,6 @@ use internals::ast::{Container, Data, Field, Style}; use internals::attr::{Identifier, TagType}; -use internals::{Ctxt, Derive}; +use internals::{ungroup, Ctxt, Derive}; use syn::{Member, Type}; /// Cross-cutting checks that require looking at more than a single attrs @@ -396,7 +396,7 @@ fn member_message(member: &Member) -> String { } fn allow_transparent(field: &Field, derive: Derive) -> bool { - if let Type::Path(ty) = field.ty { + if let Type::Path(ty) = ungroup(&field.ty) { if let Some(seg) = ty.path.segments.last() { if seg.ident == "PhantomData" { return false; diff --git a/third_party/rust/serde_derive/src/internals/mod.rs b/third_party/rust/serde_derive/src/internals/mod.rs index 688588e22687..d36b6e45c48e 100644 --- a/third_party/rust/serde_derive/src/internals/mod.rs +++ b/third_party/rust/serde_derive/src/internals/mod.rs @@ -8,8 +8,17 @@ mod case; mod check; mod symbol; +use syn::Type; + #[derive(Copy, Clone)] pub enum Derive { Serialize, Deserialize, } + +pub fn ungroup(mut ty: &Type) -> &Type { + while let Type::Group(group) = ty { + ty = &group.elem; + } + ty +} diff --git a/third_party/rust/serde_derive/src/lib.rs b/third_party/rust/serde_derive/src/lib.rs index 9e4896e17ce8..9307ae8147cb 100644 --- a/third_party/rust/serde_derive/src/lib.rs +++ b/third_party/rust/serde_derive/src/lib.rs @@ -13,46 +13,43 @@ //! //! [https://serde.rs/derive.html]: https://serde.rs/derive.html -#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.104")] +#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.116")] #![allow(unknown_lints, bare_trait_objects)] -#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))] -#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] +#![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints -#![cfg_attr( - feature = "cargo-clippy", - allow( - cognitive_complexity, - enum_variant_names, - needless_pass_by_value, - redundant_field_names, - too_many_arguments, - trivially_copy_pass_by_ref, - used_underscore_binding, - ) +#![allow( + clippy::cognitive_complexity, + clippy::enum_variant_names, + clippy::match_like_matches_macro, + clippy::needless_pass_by_value, + clippy::too_many_arguments, + clippy::trivially_copy_pass_by_ref, + clippy::used_underscore_binding, + clippy::wildcard_in_or_patterns, + // clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704 + clippy::unnested_or_patterns, )] // Ignored clippy_pedantic lints -#![cfg_attr( - feature = "cargo-clippy", - allow( - cast_possible_truncation, - checked_conversions, - doc_markdown, - enum_glob_use, - filter_map, - indexing_slicing, - items_after_statements, - match_same_arms, - module_name_repetitions, - must_use_candidate, - similar_names, - single_match_else, - too_many_lines, - unseparated_literal_suffix, - use_self, - ) +#![allow( + clippy::cast_possible_truncation, + clippy::checked_conversions, + clippy::doc_markdown, + clippy::enum_glob_use, + clippy::filter_map, + clippy::indexing_slicing, + clippy::items_after_statements, + clippy::match_same_arms, + clippy::module_name_repetitions, + clippy::must_use_candidate, + clippy::option_if_let_else, + clippy::similar_names, + clippy::single_match_else, + clippy::struct_excessive_bools, + clippy::too_many_lines, + clippy::unseparated_literal_suffix, + clippy::use_self, + clippy::wildcard_imports )] -// The `quote!` macro requires deep recursion. -#![recursion_limit = "512"] #[macro_use] extern crate quote; diff --git a/third_party/rust/serde_derive/src/ser.rs b/third_party/rust/serde_derive/src/ser.rs index a7109ea6223c..f29d73809c70 100644 --- a/third_party/rust/serde_derive/src/ser.rs +++ b/third_party/rust/serde_derive/src/ser.rs @@ -87,6 +87,9 @@ struct Parameters { /// Type has a `serde(remote = "...")` attribute. is_remote: bool, + + /// Type has a repr(packed) attribute. + is_packed: bool, } impl Parameters { @@ -103,13 +106,16 @@ impl Parameters { None => cont.ident.clone().into(), }; + let is_packed = cont.attrs.is_packed(); + let generics = build_generics(cont); Parameters { - self_var: self_var, - this: this, - generics: generics, - is_remote: is_remote, + self_var, + this, + generics, + is_remote, + is_packed, } } @@ -538,17 +544,17 @@ fn serialize_externally_tagged_variant( } Style::Tuple => serialize_tuple_variant( TupleVariant::ExternallyTagged { - type_name: type_name, - variant_index: variant_index, - variant_name: variant_name, + type_name, + variant_index, + variant_name, }, params, &variant.fields, ), Style::Struct => serialize_struct_variant( StructVariant::ExternallyTagged { - variant_index: variant_index, - variant_name: variant_name, + variant_index, + variant_name, }, params, &variant.fields, @@ -614,10 +620,7 @@ fn serialize_internally_tagged_variant( } } Style::Struct => serialize_struct_variant( - StructVariant::InternallyTagged { - tag: tag, - variant_name: variant_name, - }, + StructVariant::InternallyTagged { tag, variant_name }, params, &variant.fields, &type_name, @@ -870,9 +873,9 @@ fn serialize_struct_variant<'a>( } let struct_trait = match context { - StructVariant::ExternallyTagged { .. } => (StructTrait::SerializeStructVariant), + StructVariant::ExternallyTagged { .. } => StructTrait::SerializeStructVariant, StructVariant::InternallyTagged { .. } | StructVariant::Untagged => { - (StructTrait::SerializeStruct) + StructTrait::SerializeStruct } }; @@ -1241,9 +1244,19 @@ fn mut_if(is_mut: bool) -> Option { fn get_member(params: &Parameters, field: &Field, member: &Member) -> TokenStream { let self_var = ¶ms.self_var; match (params.is_remote, field.attrs.getter()) { - (false, None) => quote!(&#self_var.#member), + (false, None) => { + if params.is_packed { + quote!(&{#self_var.#member}) + } else { + quote!(&#self_var.#member) + } + } (true, None) => { - let inner = quote!(&#self_var.#member); + let inner = if params.is_packed { + quote!(&{#self_var.#member}) + } else { + quote!(&#self_var.#member) + }; let ty = field.ty; quote!(_serde::private::ser::constrain::<#ty>(#inner)) }