Check for None-delimited group in attribute value

This commit is contained in:
David Tolnay 2023-03-20 04:03:25 -07:00
parent c3d637f397
commit dd460f82a1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 21 additions and 16 deletions

View File

@ -24,7 +24,7 @@ proc-macro = true
[dependencies] [dependencies]
proc-macro2 = "1.0" proc-macro2 = "1.0"
quote = "1.0" quote = "1.0"
syn = "2.0" syn = "2.0.3"
[dev-dependencies] [dev-dependencies]
serde = { version = "1.0", path = "../serde" } serde = { version = "1.0", path = "../serde" }

View File

@ -1381,12 +1381,18 @@ fn get_lit_str2(
meta_item_name: Symbol, meta_item_name: Symbol,
meta: &ParseNestedMeta, meta: &ParseNestedMeta,
) -> syn::Result<Option<syn::LitStr>> { ) -> syn::Result<Option<syn::LitStr>> {
match meta.value()?.parse()? { let expr: syn::Expr = meta.value()?.parse()?;
syn::Expr::Lit(syn::ExprLit { let mut value = &expr;
while let syn::Expr::Group(e) = value {
value = &e.expr;
}
if let syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(lit), lit: syn::Lit::Str(lit),
.. ..
}) => Ok(Some(lit)), }) = value
expr => { {
Ok(Some(lit.clone()))
} else {
cx.error_spanned_by( cx.error_spanned_by(
expr, expr,
format!( format!(
@ -1397,7 +1403,6 @@ fn get_lit_str2(
Ok(None) Ok(None)
} }
} }
}
fn parse_lit_into_path( fn parse_lit_into_path(
cx: &Ctxt, cx: &Ctxt,