mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 04:09:48 +00:00
Update to syn-2
Change-Id: I0043acbdcd7a697063931a3505f6e90354f92d2a Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5078521 Commit-Queue: Frederick Mayle <fmayle@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
f832d41758
commit
8aabb8d9c0
7 changed files with 39 additions and 27 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -127,7 +127,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote 1.0.33",
|
||||
"syn 1.0.103",
|
||||
"syn 2.0.37",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -252,7 +252,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote 1.0.33",
|
||||
"syn 1.0.103",
|
||||
"syn 2.0.37",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -310,7 +310,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote 1.0.33",
|
||||
"syn 1.0.103",
|
||||
"syn 2.0.37",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2423,7 +2423,7 @@ dependencies = [
|
|||
"argh",
|
||||
"proc-macro2",
|
||||
"quote 1.0.33",
|
||||
"syn 1.0.103",
|
||||
"syn 2.0.37",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -7,6 +7,6 @@ edition = "2021"
|
|||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
syn = {version = "1.0", features = ["extra-traits"]}
|
||||
syn = { version = "2", features = ["extra-traits"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
|
|
|
@ -136,20 +136,26 @@ pub fn pad_description_for_argh(
|
|||
if let syn::Fields::Named(fields) = &mut s.fields {
|
||||
for f in fields.named.iter_mut() {
|
||||
for a in f.attrs.iter_mut() {
|
||||
if a.path
|
||||
if a.path()
|
||||
.get_ident()
|
||||
.map(|i| i.to_string())
|
||||
.unwrap_or_default()
|
||||
== *"doc"
|
||||
{
|
||||
if let Ok(syn::Meta::NameValue(nv)) = a.parse_meta() {
|
||||
if let syn::Lit::Str(s) = nv.lit {
|
||||
let doc = s.value().lines().fold(String::new(), |mut output, s| {
|
||||
let _ = write!(output, "{: <61}", s);
|
||||
output
|
||||
});
|
||||
*a = syn::parse_quote! { #[doc= #doc] };
|
||||
}
|
||||
if let syn::Meta::NameValue(syn::MetaNameValue {
|
||||
value:
|
||||
syn::Expr::Lit(syn::ExprLit {
|
||||
lit: syn::Lit::Str(s),
|
||||
..
|
||||
}),
|
||||
..
|
||||
}) = &a.meta
|
||||
{
|
||||
let doc = s.value().lines().fold(String::new(), |mut output, s| {
|
||||
let _ = write!(output, "{: <61}", s);
|
||||
output
|
||||
});
|
||||
*a = syn::parse_quote! { #[doc= #doc] };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@ proc-macro = true
|
|||
[dependencies]
|
||||
proc-macro2 = "^1"
|
||||
quote = "^1"
|
||||
syn = "^1"
|
||||
syn = "2"
|
||||
|
|
|
@ -7,7 +7,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
proc-macro2 = "^1"
|
||||
quote = "^1"
|
||||
syn = "^1"
|
||||
syn = { version = "2", features = ["full"] }
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
|
|
@ -24,6 +24,7 @@ use syn::Ident;
|
|||
use syn::Lit;
|
||||
use syn::LitInt;
|
||||
use syn::Meta;
|
||||
use syn::MetaNameValue;
|
||||
use syn::Type;
|
||||
use syn::Visibility;
|
||||
|
||||
|
@ -391,10 +392,10 @@ fn parse_bits_attr(attrs: &[Attribute]) -> Result<Option<LitInt>> {
|
|||
let mut expected_bits = None;
|
||||
|
||||
for attr in attrs {
|
||||
if attr.path.is_ident("doc") {
|
||||
if attr.path().is_ident("doc") {
|
||||
continue;
|
||||
}
|
||||
if let Some(v) = try_parse_bits_attr(attr)? {
|
||||
if let Some(v) = try_parse_bits_attr(attr) {
|
||||
expected_bits = Some(v);
|
||||
continue;
|
||||
}
|
||||
|
@ -406,15 +407,20 @@ fn parse_bits_attr(attrs: &[Attribute]) -> Result<Option<LitInt>> {
|
|||
}
|
||||
|
||||
// This function will return None if the attribute is not #[bits = *].
|
||||
fn try_parse_bits_attr(attr: &Attribute) -> Result<Option<LitInt>> {
|
||||
if attr.path.is_ident("bits") {
|
||||
if let Meta::NameValue(name_value) = attr.parse_meta()? {
|
||||
if let Lit::Int(int) = name_value.lit {
|
||||
return Ok(Some(int));
|
||||
}
|
||||
fn try_parse_bits_attr(attr: &Attribute) -> Option<LitInt> {
|
||||
if attr.path().is_ident("bits") {
|
||||
if let Meta::NameValue(MetaNameValue {
|
||||
value:
|
||||
syn::Expr::Lit(syn::ExprLit {
|
||||
lit: Lit::Int(int), ..
|
||||
}),
|
||||
..
|
||||
}) = &attr.meta
|
||||
{
|
||||
return Some(int).cloned();
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
None
|
||||
}
|
||||
|
||||
fn parse_remove_bits_attr(ast: &mut DeriveInput) -> Result<Option<u64>> {
|
||||
|
@ -422,7 +428,7 @@ fn parse_remove_bits_attr(ast: &mut DeriveInput) -> Result<Option<u64>> {
|
|||
let mut bits_idx = 0;
|
||||
|
||||
for (i, attr) in ast.attrs.iter().enumerate() {
|
||||
if let Some(w) = try_parse_bits_attr(attr)? {
|
||||
if let Some(w) = try_parse_bits_attr(attr) {
|
||||
bits_idx = i;
|
||||
width = Some(w.base10_parse()?);
|
||||
}
|
||||
|
|
|
@ -9,5 +9,5 @@ proc-macro = true
|
|||
[dependencies]
|
||||
argh = "0.1.7"
|
||||
proc-macro2 = "1.0"
|
||||
syn = "1.0"
|
||||
syn = "2"
|
||||
quote = "1.0"
|
||||
|
|
Loading…
Reference in a new issue