Skip to content

Commit

Permalink
tools/prost-build: update prost to 0.12.1
Browse files Browse the repository at this point in the history
Also run `cargo update`, which includes the same fix as
BitBoxSwiss#1140 (bump
rustix from 0.36.11 to 0.36.16).
  • Loading branch information
benma committed Nov 2, 2023
1 parent c0f903f commit ac22643
Show file tree
Hide file tree
Showing 18 changed files with 448 additions and 357 deletions.
10 changes: 5 additions & 5 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/bitbox02-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bitcoin = { version = "0.30.0", default-features = false, features = ["no-std"],

[dependencies.prost]
# keep version in sync with tools/prost-build/Cargo.toml.
version = "0.11.5"
version = "0.12.1"
default-features = false
features = ["prost-derive"]

Expand Down
2 changes: 1 addition & 1 deletion src/rust/vendor/prost-derive/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"830ca416b545d756142214029e79dd0def97b991527623943fce4275667628d4","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"6c67fa1e48f14adfaf834f520f798ddfb79f90804f46cc215ee391a7d57913a4","src/field/group.rs":"0370fda09a6dc7e8e91cfab1a6638c0117f0b968bcc7d1a8f397c2bf00042481","src/field/map.rs":"30b678fbbeca1411e7e16f2dfeadf38860ba654266ad66da16019369153618f2","src/field/message.rs":"a5672412435bb9fafbd4a99b1a6c6d5bbf636a571959358a44196bfd69efc2d1","src/field/mod.rs":"5265820ea953a100ee33db71c416f72bac5e1dd375a98ebdd6755a334f5bed0f","src/field/oneof.rs":"4fc488445b05e464070fadd8799cafb806db5c23d1494c4300cb293394863012","src/field/scalar.rs":"6859f9910a12a2864397f7f6fa36541c992c43b3ff8d15d4191aa93e92f5b078","src/lib.rs":"8ba979a94503dcd8d487237e856367a0a345b4873de7a73135c1b577ecb16bd9"},"package":"c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720"}
{"files":{"Cargo.toml":"7d555d8783ebeebdb3c3190ff57fa833db7cbd14eecba8a5a101f87e7dca3f71","LICENSE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","README.md":"6c67fa1e48f14adfaf834f520f798ddfb79f90804f46cc215ee391a7d57913a4","src/field/group.rs":"0370fda09a6dc7e8e91cfab1a6638c0117f0b968bcc7d1a8f397c2bf00042481","src/field/map.rs":"a03791fc758802cdf4e75e197acd7975141377e3d1ad1273e6cefab2b7fddfe9","src/field/message.rs":"a5672412435bb9fafbd4a99b1a6c6d5bbf636a571959358a44196bfd69efc2d1","src/field/mod.rs":"108b98c676b780fbe55907a3c2825bdf77cd0f857292bfa82a78f5b20fa499c5","src/field/oneof.rs":"128e990b8bb711fdbadd35b711f127c02f64b84b5ca95307b428956896d15721","src/field/scalar.rs":"16a4210578e7e643d49b5c769078f8bf295dae738f3ba2b6e48af7291b9e7951","src/lib.rs":"0b86c9fdace3d3f942afad55f7aa21d4dc2c7d8447906d03fd9c650d311c47ee"},"package":"265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32"}
8 changes: 4 additions & 4 deletions src/rust/vendor/prost-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

[package]
edition = "2021"
rust-version = "1.56"
rust-version = "1.60"
name = "prost-derive"
version = "0.11.5"
version = "0.12.1"
authors = [
"Dan Burkert <dan@danburkert.com>",
"Lucio Franco <luciofranco14@gmail.com>",
Expand All @@ -32,7 +32,7 @@ proc_macro = true
version = "1.0.1"

[dependencies.itertools]
version = "0.10"
version = ">=0.10, <0.12"
features = ["use_alloc"]
default-features = false

Expand All @@ -43,5 +43,5 @@ version = "1"
version = "1"

[dependencies.syn]
version = "1.0.3"
version = "2"
features = ["extra-traits"]
40 changes: 21 additions & 19 deletions src/rust/vendor/prost-derive/src/field/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::{bail, Error};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{Ident, Lit, Meta, MetaNameValue, NestedMeta};
use syn::punctuated::Punctuated;
use syn::{Expr, ExprLit, Ident, Lit, Meta, MetaNameValue, Token};

use crate::field::{scalar, set_option, tag_attr};

Expand Down Expand Up @@ -67,7 +68,11 @@ impl Field {
{
let (k, v): (String, String) = match attr {
Meta::NameValue(MetaNameValue {
lit: Lit::Str(lit), ..
value:
Expr::Lit(ExprLit {
lit: Lit::Str(lit), ..
}),
..
}) => {
let items = lit.value();
let mut items = items.split(',').map(ToString::to_string);
Expand All @@ -82,23 +87,14 @@ impl Field {
(k, v)
}
Meta::List(meta_list) => {
// TODO(rustlang/rust#23121): slice pattern matching would make this much nicer.
if meta_list.nested.len() != 2 {
let nested = meta_list
.parse_args_with(Punctuated::<Ident, Token![,]>::parse_terminated)?
.into_iter()
.collect::<Vec<_>>();
if nested.len() != 2 {
bail!("invalid map attribute: must contain key and value types");
}
let k = match &meta_list.nested[0] {
NestedMeta::Meta(Meta::Path(k)) if k.get_ident().is_some() => {
k.get_ident().unwrap().to_string()
}
_ => bail!("invalid map attribute: key must be an identifier"),
};
let v = match &meta_list.nested[1] {
NestedMeta::Meta(Meta::Path(v)) if v.get_ident().is_some() => {
v.get_ident().unwrap().to_string()
}
_ => bail!("invalid map attribute: value must be an identifier"),
};
(k, v)
(nested[0].to_string(), nested[1].to_string())
}
_ => return Ok(None),
};
Expand Down Expand Up @@ -279,11 +275,17 @@ impl Field {
Some(quote! {
#[doc=#get_doc]
pub fn #get(&self, key: #key_ref_ty) -> ::core::option::Option<#ty> {
self.#ident.get(#take_ref key).cloned().and_then(#ty::from_i32)
self.#ident.get(#take_ref key).cloned().and_then(|x| {
let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
result.ok()
})
}
#[doc=#insert_doc]
pub fn #insert(&mut self, key: #key_ty, value: #ty) -> ::core::option::Option<#ty> {
self.#ident.insert(key, value as i32).and_then(#ty::from_i32)
self.#ident.insert(key, value as i32).and_then(|x| {
let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
result.ok()
})
}
})
} else {
Expand Down
97 changes: 45 additions & 52 deletions src/rust/vendor/prost-derive/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use std::slice;
use anyhow::{bail, Error};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Attribute, Lit, LitBool, Meta, MetaList, MetaNameValue, NestedMeta};
use syn::punctuated::Punctuated;
use syn::{Attribute, Expr, ExprLit, Lit, LitBool, LitInt, Meta, MetaNameValue, Token};

#[derive(Clone)]
pub enum Field {
Expand All @@ -32,7 +33,7 @@ impl Field {
/// If the meta items are invalid, an error will be returned.
/// If the field should be ignored, `None` is returned.
pub fn new(attrs: Vec<Attribute>, inferred_tag: Option<u32>) -> Result<Option<Field>, Error> {
let attrs = prost_attrs(attrs);
let attrs = prost_attrs(attrs)?;

// TODO: check for ignore attribute.

Expand All @@ -58,7 +59,7 @@ impl Field {
/// If the meta items are invalid, an error will be returned.
/// If the field should be ignored, `None` is returned.
pub fn new_oneof(attrs: Vec<Attribute>) -> Result<Option<Field>, Error> {
let attrs = prost_attrs(attrs);
let attrs = prost_attrs(attrs)?;

// TODO: check for ignore attribute.

Expand Down Expand Up @@ -224,27 +225,20 @@ impl fmt::Display for Label {
}

/// Get the items belonging to the 'prost' list attribute, e.g. `#[prost(foo, bar="baz")]`.
fn prost_attrs(attrs: Vec<Attribute>) -> Vec<Meta> {
attrs
.iter()
.flat_map(Attribute::parse_meta)
.flat_map(|meta| match meta {
Meta::List(MetaList { path, nested, .. }) => {
if path.is_ident("prost") {
nested.into_iter().collect()
} else {
Vec::new()
}
}
_ => Vec::new(),
})
.flat_map(|attr| -> Result<_, _> {
match attr {
NestedMeta::Meta(attr) => Ok(attr),
NestedMeta::Lit(lit) => bail!("invalid prost attribute: {:?}", lit),
fn prost_attrs(attrs: Vec<Attribute>) -> Result<Vec<Meta>, Error> {
let mut result = Vec::new();
for attr in attrs.iter() {
if let Meta::List(meta_list) = &attr.meta {
if meta_list.path.is_ident("prost") {
result.extend(
meta_list
.parse_args_with(Punctuated::<Meta, Token![,]>::parse_terminated)?
.into_iter(),
)
}
})
.collect()
}
}
Ok(result)
}

pub fn set_option<T>(option: &mut Option<T>, value: T, message: &str) -> Result<(), Error>
Expand Down Expand Up @@ -276,24 +270,26 @@ fn bool_attr(key: &str, attr: &Meta) -> Result<Option<bool>, Error> {
match *attr {
Meta::Path(..) => Ok(Some(true)),
Meta::List(ref meta_list) => {
// TODO(rustlang/rust#23121): slice pattern matching would make this much nicer.
if meta_list.nested.len() == 1 {
if let NestedMeta::Lit(Lit::Bool(LitBool { value, .. })) = meta_list.nested[0] {
return Ok(Some(value));
}
}
bail!("invalid {} attribute", key);
return Ok(Some(meta_list.parse_args::<LitBool>()?.value()));
}
Meta::NameValue(MetaNameValue {
lit: Lit::Str(ref lit),
value:
Expr::Lit(ExprLit {
lit: Lit::Str(ref lit),
..
}),
..
}) => lit
.value()
.parse::<bool>()
.map_err(Error::from)
.map(Option::Some),
Meta::NameValue(MetaNameValue {
lit: Lit::Bool(LitBool { value, .. }),
value:
Expr::Lit(ExprLit {
lit: Lit::Bool(LitBool { value, .. }),
..
}),
..
}) => Ok(Some(value)),
_ => bail!("invalid {} attribute", key),
Expand All @@ -315,15 +311,12 @@ pub(super) fn tag_attr(attr: &Meta) -> Result<Option<u32>, Error> {
}
match *attr {
Meta::List(ref meta_list) => {
// TODO(rustlang/rust#23121): slice pattern matching would make this much nicer.
if meta_list.nested.len() == 1 {
if let NestedMeta::Lit(Lit::Int(ref lit)) = meta_list.nested[0] {
return Ok(Some(lit.base10_parse()?));
}
}
bail!("invalid tag attribute: {:?}", attr);
return Ok(Some(meta_list.parse_args::<LitInt>()?.base10_parse()?));
}
Meta::NameValue(ref meta_name_value) => match meta_name_value.lit {
Meta::NameValue(MetaNameValue {
value: Expr::Lit(ref expr),
..
}) => match expr.lit {
Lit::Str(ref lit) => lit
.value()
.parse::<u32>()
Expand All @@ -341,19 +334,19 @@ fn tags_attr(attr: &Meta) -> Result<Option<Vec<u32>>, Error> {
return Ok(None);
}
match *attr {
Meta::List(ref meta_list) => {
let mut tags = Vec::with_capacity(meta_list.nested.len());
for item in &meta_list.nested {
if let NestedMeta::Lit(Lit::Int(ref lit)) = *item {
tags.push(lit.base10_parse()?);
} else {
bail!("invalid tag attribute: {:?}", attr);
}
}
Ok(Some(tags))
}
Meta::List(ref meta_list) => Ok(Some(
meta_list
.parse_args_with(Punctuated::<LitInt, Token![,]>::parse_terminated)?
.iter()
.map(LitInt::base10_parse)
.collect::<Result<Vec<_>, _>>()?,
)),
Meta::NameValue(MetaNameValue {
lit: Lit::Str(ref lit),
value:
Expr::Lit(ExprLit {
lit: Lit::Str(ref lit),
..
}),
..
}) => lit
.value()
Expand Down
21 changes: 7 additions & 14 deletions src/rust/vendor/prost-derive/src/field/oneof.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{bail, Error};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_str, Lit, Meta, MetaNameValue, NestedMeta, Path};
use syn::{parse_str, Expr, ExprLit, Ident, Lit, Meta, MetaNameValue, Path};

use crate::field::{set_option, tags_attr};

Expand All @@ -21,21 +21,14 @@ impl Field {
if attr.path().is_ident("oneof") {
let t = match *attr {
Meta::NameValue(MetaNameValue {
lit: Lit::Str(ref lit),
value:
Expr::Lit(ExprLit {
lit: Lit::Str(ref lit),
..
}),
..
}) => parse_str::<Path>(&lit.value())?,
Meta::List(ref list) if list.nested.len() == 1 => {
// TODO(rustlang/rust#23121): slice pattern matching would make this much nicer.
if let NestedMeta::Meta(Meta::Path(ref path)) = list.nested[0] {
if let Some(ident) = path.get_ident() {
Path::from(ident.clone())
} else {
bail!("invalid oneof attribute: item must be an identifier");
}
} else {
bail!("invalid oneof attribute: item must be an identifier");
}
}
Meta::List(ref list) => list.parse_args::<Ident>()?.into(),
_ => bail!("invalid oneof attribute: {:?}", attr),
};
set_option(&mut ty, t, "duplicate oneof attribute")?;
Expand Down
Loading

0 comments on commit ac22643

Please sign in to comment.