diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/zerovec-derive | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/zerovec-derive')
-rw-r--r-- | vendor/zerovec-derive/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/zerovec-derive/Cargo.lock | 77 | ||||
-rw-r--r-- | vendor/zerovec-derive/Cargo.toml | 22 | ||||
-rw-r--r-- | vendor/zerovec-derive/LICENSE | 79 | ||||
-rw-r--r-- | vendor/zerovec-derive/README.md | 4 | ||||
-rw-r--r-- | vendor/zerovec-derive/examples/make_var.rs | 37 | ||||
-rw-r--r-- | vendor/zerovec-derive/src/lib.rs | 7 | ||||
-rw-r--r-- | vendor/zerovec-derive/src/make_ule.rs | 25 | ||||
-rw-r--r-- | vendor/zerovec-derive/src/make_varule.rs | 78 | ||||
-rw-r--r-- | vendor/zerovec-derive/src/utils.rs | 55 |
10 files changed, 234 insertions, 152 deletions
diff --git a/vendor/zerovec-derive/.cargo-checksum.json b/vendor/zerovec-derive/.cargo-checksum.json index 50de4eacc..b6fe55595 100644 --- a/vendor/zerovec-derive/.cargo-checksum.json +++ b/vendor/zerovec-derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.lock":"e4e240b846cb0dbf1a90ff9982b2d197f8ac061bf9953bec8e0f89395d7117c7","Cargo.toml":"9dfe02636d0829e581beafdd6502cc12c75a1a486e5050f6e49d648407b2b9b2","LICENSE":"4ad7541d66a407234e2c84902124cef325c29f3e966353efdb800bedb8b8da21","README.md":"77ca5a17524e17ae9098ab00f91cb67996f5a298468d68a15d23a09bde940b9a","examples/derives.rs":"2541311f2b532301ab8600927fb2d12a842166ce98d57879997df12dcb928dd2","examples/make.rs":"709829d9aa1fa1d023437dfd8169183690629b71e65cc1316b1f4bf767588cc6","examples/make_var.rs":"bb84e153863be0fc94ca3070ac3d194ad75b701ca0d2370c3ee0c5240e793925","src/lib.rs":"4f4f2a1c0f0204ac782d741f9a188b474b9c0e23a5e6e4619b9a3e926c1e08e5","src/make_ule.rs":"c1e5f17db25d5ad3ec801150988ddd19eb5889b7030af29de1b6f0bf8e01ea98","src/make_varule.rs":"0c7d6561fdecf8ecfe64820c2441e5851abe96bb0efa19f7acb334285d7360f3","src/ule.rs":"1f0a46ff39e43bb19deb9e9a06289350096d4e6ca3f33cb76fec3c84c4a439d8","src/utils.rs":"26455d11457e9326ccc282ce28572fbcdcad5d8fddad786f052ebe06cbc37aee","src/varule.rs":"b0642df70023b2f04aca692010f6b2a81fd3f3db8612dbae072a200eb04f0913"},"package":"486558732d5dde10d0f8cb2936507c1bb21bc539d924c949baf5f36a58e51bac"}
\ No newline at end of file +{"files":{"Cargo.lock":"ccf6d724448a2fb71641bdf8aafc773be18e8db354d10d38214dbc6f1eeda156","Cargo.toml":"6224057ff9d0f6505bd9344ee309039b7bcbf9712b42a683e8b8c896c3dc8d78","LICENSE":"853f87c96f3d249f200fec6db1114427bc8bdf4afddc93c576956d78152ce978","README.md":"bacbc17b2cb457c169257f5e22c78a45d1c4a399eadae383f7732af909616ebc","examples/derives.rs":"2541311f2b532301ab8600927fb2d12a842166ce98d57879997df12dcb928dd2","examples/make.rs":"709829d9aa1fa1d023437dfd8169183690629b71e65cc1316b1f4bf767588cc6","examples/make_var.rs":"8a017467e9ac7cea1f4ab13536c32c9265e54bdbc361bca7d19c6fc0970c1abb","src/lib.rs":"029d2b251b8279e7c85d9cc8efb6cad5188da9464b0a27e9de3dd119f4ffef2e","src/make_ule.rs":"6b8fd0d027bd219315d4dada3bbc000f4cbf344188f7e0d9d2de95ebb103c552","src/make_varule.rs":"064270a6fef492f2f2426c65adaad8e2f4f58f55464f116a9c3eb30810c77b2f","src/ule.rs":"1f0a46ff39e43bb19deb9e9a06289350096d4e6ca3f33cb76fec3c84c4a439d8","src/utils.rs":"e5f73721d8ae3c1f5407816dec2314f3694d81e1f373ab6738e74f73442377fc","src/varule.rs":"b0642df70023b2f04aca692010f6b2a81fd3f3db8612dbae072a200eb04f0913"},"package":"acabf549809064225ff8878baedc4ce3732ac3b07e7c7ce6e5c2ccdbc485c324"}
\ No newline at end of file diff --git a/vendor/zerovec-derive/Cargo.lock b/vendor/zerovec-derive/Cargo.lock index aa9b0373e..9360b0559 100644 --- a/vendor/zerovec-derive/Cargo.lock +++ b/vendor/zerovec-derive/Cargo.lock @@ -13,48 +13,48 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.93" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -74,9 +74,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.107" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -84,32 +84,42 @@ dependencies = [ ] [[package]] -name = "synstructure" -version = "0.12.6" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "unicode-ident" -version = "1.0.6" +name = "zerofrom" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "655b0814c5c0b19ade497851070c640773304939a6c0fd5f5fb43da0696d05b7" [[package]] -name = "unicode-xid" -version = "0.2.4" +name = "zerovec" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +checksum = "1194130c5b155bf8ae50ab16c86ab758cd695cf9ad176d2f870b744cbdbb572e" +dependencies = [ + "serde", + "zerofrom", + "zerovec-derive 0.9.6", +] + +[[package]] +name = "zerovec-derive" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a4a1638a1934450809c2266a70362bfc96cd90550c073f5b8a55014d1010157" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "zerovec-derive" -version = "0.9.4" +version = "0.10.0" dependencies = [ "bincode", "proc-macro2", @@ -117,5 +127,6 @@ dependencies = [ "serde", "serde_json", "syn", - "synstructure", + "zerofrom", + "zerovec", ] diff --git a/vendor/zerovec-derive/Cargo.toml b/vendor/zerovec-derive/Cargo.toml index 667e6cc60..9ac0d2b2a 100644 --- a/vendor/zerovec-derive/Cargo.toml +++ b/vendor/zerovec-derive/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2021" name = "zerovec-derive" -version = "0.9.4" +version = "0.10.0" authors = ["Manish Goregaokar <manishsmail@gmail.com>"] description = "Custom derive for the zerovec crate" readme = "README.md" @@ -29,7 +29,7 @@ categories = [ "no-std", "data-structures", ] -license = "Unicode-DFS-2016" +license-file = "LICENSE" repository = "https://github.com/unicode-org/icu4x" [package.metadata.workspaces] @@ -46,15 +46,13 @@ version = "1.0.27" version = "1.0.9" [dependencies.syn] -version = "1.0.73" +version = "2" features = [ "derive", "parsing", + "extra-traits", ] -[dependencies.synstructure] -version = "0.12.4" - [dev-dependencies.bincode] version = "1.3" @@ -64,3 +62,15 @@ features = ["derive"] [dev-dependencies.serde_json] version = "1.0" + +[dev-dependencies.zerofrom] +version = "0.1.2" +default-features = false + +[dev-dependencies.zerovec] +version = ">=0.9.4, <0.11.0" +features = [ + "serde", + "derive", +] +default-features = false diff --git a/vendor/zerovec-derive/LICENSE b/vendor/zerovec-derive/LICENSE index 9858d01ab..9845aa5f4 100644 --- a/vendor/zerovec-derive/LICENSE +++ b/vendor/zerovec-derive/LICENSE @@ -1,49 +1,42 @@ -UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE - -See Terms of Use <https://www.unicode.org/copyright.html> -for definitions of Unicode Inc.’s Data Files and Software. - -NOTICE TO USER: Carefully read the following legal agreement. -BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S -DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), -YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE -TERMS AND CONDITIONS OF THIS AGREEMENT. -IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE -THE DATA FILES OR SOFTWARE. +UNICODE LICENSE V3 COPYRIGHT AND PERMISSION NOTICE -Copyright © 1991-2022 Unicode, Inc. All rights reserved. -Distributed under the Terms of Use in https://www.unicode.org/copyright.html. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Unicode data files and any associated documentation -(the "Data Files") or Unicode software and any associated documentation -(the "Software") to deal in the Data Files or Software -without restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, and/or sell copies of -the Data Files or Software, and to permit persons to whom the Data Files -or Software are furnished to do so, provided that either -(a) this copyright and permission notice appear with all copies -of the Data Files or Software, or -(b) this copyright and permission notice appear in associated -Documentation. - -THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT OF THIRD PARTY RIGHTS. -IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS -NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL -DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THE DATA FILES OR SOFTWARE. - -Except as contained in this notice, the name of a copyright holder -shall not be used in advertising or otherwise to promote the sale, -use or other dealings in these Data Files or Software without prior -written authorization of the copyright holder. +Copyright © 2020-2023 Unicode, Inc. + +NOTICE TO USER: Carefully read the following legal agreement. BY +DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR +SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT +DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of data files and any associated documentation (the "Data Files") or +software and any associated documentation (the "Software") to deal in the +Data Files or Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either (a) +this copyright and permission notice appear with all copies of the Data +Files or Software, or (b) this copyright and permission notice appear in +associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +THIRD PARTY RIGHTS. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE +BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, +OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA +FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall +not be used in advertising or otherwise to promote the sale, use or other +dealings in these Data Files or Software without prior written +authorization of the copyright holder. — diff --git a/vendor/zerovec-derive/README.md b/vendor/zerovec-derive/README.md index 219a5059d..e80b8abe5 100644 --- a/vendor/zerovec-derive/README.md +++ b/vendor/zerovec-derive/README.md @@ -1,7 +1,11 @@ # zerovec-derive [![crates.io](https://img.shields.io/crates/v/zerovec-derive)](https://crates.io/crates/zerovec-derive) +<!-- cargo-rdme start --> + Proc macros for generating `ULE`, `VarULE` impls and types for the `zerovec` crate +<!-- cargo-rdme end --> + ## More Information For more information on development, authorship, contributing etc. please visit [`ICU4X home page`](https://github.com/unicode-org/icu4x). diff --git a/vendor/zerovec-derive/examples/make_var.rs b/vendor/zerovec-derive/examples/make_var.rs index 7dedfd3e9..47e1418cd 100644 --- a/vendor/zerovec-derive/examples/make_var.rs +++ b/vendor/zerovec-derive/examples/make_var.rs @@ -59,6 +59,30 @@ struct MultiFieldStruct<'a> { f: char, } +#[make_varule(MultiFieldConsecutiveStructULE)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, serde::Serialize, serde::Deserialize)] +#[zerovec::derive(Serialize, Deserialize, Debug)] +struct MultiFieldConsecutiveStruct<'a> { + #[serde(borrow)] + a: Cow<'a, str>, + #[serde(borrow)] + b: Cow<'a, str>, + #[serde(borrow)] + c: Cow<'a, str>, + #[serde(borrow)] + d: Cow<'a, str>, +} + +#[make_varule(CustomVarFieldULE)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, serde::Serialize, serde::Deserialize)] +#[zerovec::derive(Serialize, Deserialize, Debug)] +struct CustomVarField<'a> { + #[zerovec::varule(MultiFieldStructULE)] + #[serde(borrow)] + a: MultiFieldStruct<'a>, + b: u32, +} + #[make_varule(MultiFieldTupleULE)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, serde::Serialize, serde::Deserialize)] #[zerovec::derive(Serialize, Deserialize, Debug)] @@ -129,6 +153,11 @@ fn main() { assert_eq!(stack, &MultiFieldStruct::zero_from(zero)) }); + assert_zerovec::<MultiFieldConsecutiveStructULE, MultiFieldConsecutiveStruct, _>( + TEST_MULTICONSECUTIVE, + |stack, zero| assert_eq!(stack, &MultiFieldConsecutiveStruct::zero_from(zero)), + ); + let vartuples = &[ VarTupleStruct(101, 'ø', TEST_STRINGS1.into()), VarTupleStruct(9499, '⸘', TEST_STRINGS2.into()), @@ -187,3 +216,11 @@ const TEST_MULTIFIELD: &[MultiFieldStruct<'static>] = &[ f: 'ə', }, ]; + +const TEST_MULTICONSECUTIVE: &[MultiFieldConsecutiveStruct<'static>] = + &[MultiFieldConsecutiveStruct { + a: Cow::Borrowed("one"), + b: Cow::Borrowed("2"), + c: Cow::Borrowed("three"), + d: Cow::Borrowed("four"), + }]; diff --git a/vendor/zerovec-derive/src/lib.rs b/vendor/zerovec-derive/src/lib.rs index 5a0de6429..9c3007147 100644 --- a/vendor/zerovec-derive/src/lib.rs +++ b/vendor/zerovec-derive/src/lib.rs @@ -5,8 +5,7 @@ //! Proc macros for generating `ULE`, `VarULE` impls and types for the `zerovec` crate use proc_macro::TokenStream; -use syn::{parse_macro_input, AttributeArgs, DeriveInput}; - +use syn::{parse_macro_input, DeriveInput, Ident}; mod make_ule; mod make_varule; pub(crate) mod ule; @@ -31,7 +30,7 @@ pub fn varule_derive(input: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn make_ule(attr: TokenStream, item: TokenStream) -> TokenStream { let input = parse_macro_input!(item as DeriveInput); - let attr = parse_macro_input!(attr as AttributeArgs); + let attr = parse_macro_input!(attr as Ident); TokenStream::from(make_ule::make_ule_impl(attr, input)) } @@ -39,6 +38,6 @@ pub fn make_ule(attr: TokenStream, item: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn make_varule(attr: TokenStream, item: TokenStream) -> TokenStream { let input = parse_macro_input!(item as DeriveInput); - let attr = parse_macro_input!(attr as AttributeArgs); + let attr = parse_macro_input!(attr as Ident); TokenStream::from(make_varule::make_varule_impl(attr, input)) } diff --git a/vendor/zerovec-derive/src/make_ule.rs b/vendor/zerovec-derive/src/make_ule.rs index fb94cbc2c..92a200e0b 100644 --- a/vendor/zerovec-derive/src/make_ule.rs +++ b/vendor/zerovec-derive/src/make_ule.rs @@ -6,15 +6,11 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; use crate::utils::{self, FieldInfo, ZeroVecAttrs}; -use syn::spanned::Spanned; -use syn::{ - parse_quote, AttributeArgs, Data, DataEnum, DataStruct, DeriveInput, Error, Expr, Fields, - Ident, Lit, -}; - use std::collections::HashSet; +use syn::spanned::Spanned; +use syn::{parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Expr, Fields, Ident, Lit}; -pub fn make_ule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStream2 { +pub fn make_ule_impl(ule_name: Ident, mut input: DeriveInput) -> TokenStream2 { if input.generics.type_params().next().is_some() || input.generics.lifetimes().next().is_some() || input.generics.const_params().next().is_some() @@ -25,17 +21,6 @@ pub fn make_ule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStream ) .to_compile_error(); } - - if attr.len() != 1 { - return Error::new( - input.span(), - "#[make_ule] takes one argument for the name of the ULE type it produces", - ) - .to_compile_error(); - } - let arg = &attr[0]; - let ule_name: Ident = parse_quote!(#arg); - let sp = input.span(); let attrs = match utils::extract_attributes_common(&mut input.attrs, sp, false) { Ok(val) => val, @@ -112,7 +97,7 @@ fn make_ule_enum_impl( let mut not_found = HashSet::new(); for (i, variant) in enu.variants.iter().enumerate() { - if variant.fields != Fields::Unit { + if !matches!(variant.fields, Fields::Unit) { // This can be supported in the future, see zerovec/design_doc.md return Error::new( variant.span(), @@ -225,7 +210,7 @@ fn make_ule_enum_impl( impl #name { /// Attempt to construct the value from its corresponding integer, - /// returning None if not possible + /// returning `None` if not possible pub(crate) fn new_from_u8(value: u8) -> Option<Self> { if value <= #max { unsafe { diff --git a/vendor/zerovec-derive/src/make_varule.rs b/vendor/zerovec-derive/src/make_varule.rs index 62cf0d9db..56aa0b4f3 100644 --- a/vendor/zerovec-derive/src/make_varule.rs +++ b/vendor/zerovec-derive/src/make_varule.rs @@ -8,11 +8,11 @@ use proc_macro2::TokenStream as TokenStream2; use quote::{quote, ToTokens}; use syn::spanned::Spanned; use syn::{ - parse_quote, AttributeArgs, Data, DeriveInput, Error, Field, Fields, GenericArgument, Ident, - Lifetime, PathArguments, Type, + parse_quote, Data, DeriveInput, Error, Field, Fields, GenericArgument, Ident, Lifetime, + PathArguments, Type, TypePath, }; -pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStream2 { +pub fn make_varule_impl(ule_name: Ident, mut input: DeriveInput) -> TokenStream2 { if input.generics.type_params().next().is_some() || input.generics.const_params().next().is_some() || input.generics.lifetimes().count() > 1 @@ -44,20 +44,11 @@ pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStr let lt = lt.map(|l| &l.lifetime); - if attr.len() != 1 { - return Error::new( - input.span(), - "#[make_ule] takes one argument for the name of the ULE type it produces", - ) - .to_compile_error(); - } - let arg = &attr[0]; - let ule_name: Ident = parse_quote!(#arg); - let name = &input.ident; + let input_span = input.span(); let fields = match input.data { - Data::Struct(ref s) => &s.fields, + Data::Struct(ref mut s) => &mut s.fields, _ => { return Error::new(input.span(), "#[make_varule] must be applied to a struct") .to_compile_error(); @@ -75,16 +66,32 @@ pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStr let mut sized_fields = vec![]; let mut unsized_fields = vec![]; + let mut custom_varule_idents = vec![]; + + for field in fields.iter_mut() { + match utils::extract_field_attributes(&mut field.attrs) { + Ok(i) => custom_varule_idents.push(i), + Err(e) => return e.to_compile_error(), + } + } + for (i, field) in fields.iter().enumerate() { - match UnsizedField::new(field, i) { + match UnsizedField::new(field, i, custom_varule_idents[i].clone()) { Ok(o) => unsized_fields.push(o), Err(_) => sized_fields.push(FieldInfo::new_for_field(field, i)), } } if unsized_fields.is_empty() { + let last_field_index = fields.len() - 1; let last_field = fields.iter().next_back().unwrap(); - let e = UnsizedField::new(last_field, fields.len() - 1).unwrap_err(); + + let e = UnsizedField::new( + last_field, + last_field_index, + custom_varule_idents[last_field_index].clone(), + ) + .unwrap_err(); return Error::new(last_field.span(), e).to_compile_error(); } @@ -112,10 +119,13 @@ pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStr let field_inits = utils::wrap_field_inits(&field_inits, fields); let vis = &input.vis; - let doc = format!("[`VarULE`](zerovec::ule::VarULE) type for {name}"); + let doc = format!( + "[`VarULE`](zerovec::ule::VarULE) type for [`{name}`]. See [`{name}`] for documentation." + ); let varule_struct: DeriveInput = parse_quote!( #[repr(#repr_attr)] #[doc = #doc] + #[allow(missing_docs)] #vis struct #ule_name #field_inits #semi ); @@ -138,7 +148,7 @@ pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStr name, &ule_name, lt, - input.span(), + input_span, ); let eq_impl = quote!( @@ -409,11 +419,13 @@ enum OwnULETy<'a> { } /// Represents the type of the last field of the struct -#[derive(Copy, Clone, Debug)] +#[derive(Clone, Debug)] enum UnsizedFieldKind<'a> { Cow(OwnULETy<'a>), ZeroVec(&'a Type), VarZeroVec(&'a Type), + /// Custom VarULE type, and the identifier corresponding to the VarULE type + Custom(&'a TypePath, Ident), // Generally you should be using the above ones for maximum zero-copy, but these will still work Growable(OwnULETy<'a>), @@ -568,9 +580,13 @@ impl<'a> UnsizedFields<'a> { } impl<'a> UnsizedField<'a> { - fn new(field: &'a Field, index: usize) -> Result<Self, String> { + fn new( + field: &'a Field, + index: usize, + custom_varule_ident: Option<Ident>, + ) -> Result<Self, String> { Ok(UnsizedField { - kind: UnsizedFieldKind::new(&field.ty)?, + kind: UnsizedFieldKind::new(&field.ty, custom_varule_ident)?, field: FieldInfo::new_for_field(field, index), }) } @@ -596,7 +612,10 @@ impl<'a> UnsizedField<'a> { impl<'a> UnsizedFieldKind<'a> { /// Construct a UnsizedFieldKind for the type of a UnsizedFieldKind if possible - fn new(ty: &'a Type) -> Result<UnsizedFieldKind<'a>, String> { + fn new( + ty: &'a Type, + custom_varule_ident: Option<Ident>, + ) -> Result<UnsizedFieldKind<'a>, String> { static PATH_TYPE_IDENTITY_ERROR: &str = "Can only automatically detect corresponding VarULE types for path types \ that are Cow, ZeroVec, VarZeroVec, Box, String, or Vec"; @@ -607,6 +626,9 @@ impl<'a> UnsizedFieldKind<'a> { match *ty { Type::Reference(ref tyref) => OwnULETy::new(&tyref.elem, "reference").map(UnsizedFieldKind::Ref), Type::Path(ref typath) => { + if let Some(custom_varule_ident) = custom_varule_ident { + return Ok(UnsizedFieldKind::Custom(typath, custom_varule_ident)); + } if typath.path.segments.len() != 1 { return Err("Can only automatically detect corresponding VarULE types for \ path types with a single path segment".into()); @@ -678,6 +700,7 @@ impl<'a> UnsizedFieldKind<'a> { let inner_ule = inner.varule_ty(); quote!(#inner_ule) } + Self::Custom(_, ref name) => quote!(#name), Self::ZeroVec(ref inner) => quote!(zerovec::ZeroSlice<#inner>), Self::VarZeroVec(ref inner) => quote!(zerovec::VarZeroSlice<#inner>), } @@ -688,8 +711,8 @@ impl<'a> UnsizedFieldKind<'a> { match *self { Self::Ref(_) | Self::Cow(_) | Self::Growable(_) | Self::Boxed(_) => quote!(&*#value), - Self::ZeroVec(_) => quote!(&*#value), - Self::VarZeroVec(_) => quote!(&*#value), + Self::Custom(..) => quote!(&#value), + Self::ZeroVec(_) | Self::VarZeroVec(_) => quote!(&*#value), } } @@ -701,15 +724,16 @@ impl<'a> UnsizedFieldKind<'a> { | Self::Growable(ref inner) | Self::Boxed(ref inner) => inner.varule_ty(), - Self::ZeroVec(ty) => quote!(zerovec::ZeroSlice<#ty>), - Self::VarZeroVec(ty) => quote!(zerovec::VarZeroSlice<#ty>), + Self::Custom(ref path, _) => quote!(#path), + Self::ZeroVec(ref ty) => quote!(zerovec::ZeroSlice<#ty>), + Self::VarZeroVec(ref ty) => quote!(zerovec::VarZeroSlice<#ty>), } } fn has_zf(&self) -> bool { matches!( *self, - Self::Ref(_) | Self::Cow(_) | Self::ZeroVec(_) | Self::VarZeroVec(_) + Self::Ref(_) | Self::Cow(_) | Self::ZeroVec(_) | Self::VarZeroVec(_) | Self::Custom(..) ) } } diff --git a/vendor/zerovec-derive/src/utils.rs b/vendor/zerovec-derive/src/utils.rs index 3ebf33bf0..6d37444ca 100644 --- a/vendor/zerovec-derive/src/utils.rs +++ b/vendor/zerovec-derive/src/utils.rs @@ -9,19 +9,16 @@ use proc_macro2::TokenStream as TokenStream2; use syn::parse::{Parse, ParseStream}; use syn::punctuated::Punctuated; use syn::spanned::Spanned; -use syn::{parenthesized, parse2, Attribute, Error, Field, Fields, Ident, Index, Result, Token}; +use syn::{Attribute, Error, Field, Fields, Ident, Index, Result, Token}; // Check that there are repr attributes satisfying the given predicate pub fn has_valid_repr(attrs: &[Attribute], predicate: impl Fn(&Ident) -> bool + Copy) -> bool { - attrs - .iter() - .filter(|a| a.path.get_ident().map(|a| a == "repr").unwrap_or(false)) - .any(|a| { - parse2::<IdentListAttribute>(a.tokens.clone()) - .ok() - .and_then(|s| s.idents.iter().find(|s| predicate(s)).map(|_| ())) - .is_some() - }) + attrs.iter().filter(|a| a.path().is_ident("repr")).any(|a| { + a.parse_args::<IdentListAttribute>() + .ok() + .and_then(|s| s.idents.iter().find(|s| predicate(s)).map(|_| ())) + .is_some() + }) } // An attribute that is a list of idents @@ -31,10 +28,8 @@ struct IdentListAttribute { impl Parse for IdentListAttribute { fn parse(input: ParseStream) -> Result<Self> { - let content; - let _paren = parenthesized!(content in input); Ok(IdentListAttribute { - idents: content.parse_terminated(Ident::parse)?, + idents: input.parse_terminated(Ident::parse, Token![,])?, }) } } @@ -164,16 +159,16 @@ pub fn extract_parenthetical_zerovec_attrs( let mut error = None; attrs.retain(|a| { // skip the "zerovec" part - let second_segment = a.path.segments.iter().nth(1); + let second_segment = a.path().segments.iter().nth(1); if let Some(second) = second_segment { if second.ident == name { - let list = match parse2::<IdentListAttribute>(a.tokens.clone()) { + let list = match a.parse_args::<IdentListAttribute>() { Ok(l) => l, Err(_) => { error = Some(Error::new( a.span(), - "#[zerovec::name(..)] takes in a comma separated list of identifiers", + format!("#[zerovec::{name}(..)] takes in a comma separated list of identifiers"), )); return false; } @@ -196,7 +191,7 @@ pub fn extract_parenthetical_zerovec_attrs( pub fn extract_zerovec_attributes(attrs: &mut Vec<Attribute>) -> Vec<Attribute> { let mut ret = vec![]; attrs.retain(|a| { - if a.path.segments.len() == 2 && a.path.segments[0].ident == "zerovec" { + if a.path().segments.len() == 2 && a.path().segments[0].ident == "zerovec" { ret.push(a.clone()); return false; } @@ -205,6 +200,30 @@ pub fn extract_zerovec_attributes(attrs: &mut Vec<Attribute>) -> Vec<Attribute> ret } +/// Extract attributes from field, and return them +/// +/// Only current field attribute is `zerovec::varule(VarUleType)` +pub fn extract_field_attributes(attrs: &mut Vec<Attribute>) -> Result<Option<Ident>> { + let mut zerovec_attrs = extract_zerovec_attributes(attrs); + let varule = extract_parenthetical_zerovec_attrs(&mut zerovec_attrs, "varule")?; + + if varule.len() > 1 { + return Err(Error::new( + varule[1].span(), + "Found multiple #[zerovec::varule()] on one field", + )); + } + + if !zerovec_attrs.is_empty() { + return Err(Error::new( + zerovec_attrs[1].span(), + "Found unusable #[zerovec::] attrs on field, only #[zerovec::varule()] supported", + )); + } + + Ok(varule.get(0).cloned()) +} + #[derive(Default, Copy, Clone)] pub struct ZeroVecAttrs { pub skip_kv: bool, @@ -215,7 +234,7 @@ pub struct ZeroVecAttrs { pub hash: bool, } -/// Removes all known zerovec:: attributes from attrs and validates them +/// Removes all known zerovec:: attributes from struct attrs and validates them pub fn extract_attributes_common( attrs: &mut Vec<Attribute>, span: Span, |