Update to latest syn-1.0.16
* fill back missing NOTICE,METADATA,*LICENSE* files
Bug: 150877376
Test: make
Test: atest --host -c --include-subdirs external/rust/crates
Change-Id: Ib5df6b8fb97764214e701a888e44fab3a4245800
diff --git a/src/expr.rs b/src/expr.rs
index 2874a46..b40f1ca 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -3,7 +3,10 @@
#[cfg(feature = "extra-traits")]
use crate::tt::TokenStreamHelper;
use proc_macro2::{Span, TokenStream};
-#[cfg(feature = "extra-traits")]
+#[cfg(feature = "printing")]
+use quote::IdentFragment;
+#[cfg(feature = "printing")]
+use std::fmt::{self, Display};
use std::hash::{Hash, Hasher};
#[cfg(all(feature = "parsing", feature = "full"))]
use std::mem;
@@ -998,7 +1001,8 @@
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
- pub enum Member {
+ #[derive(Eq, PartialEq, Hash)]
+ pub enum Member #manual_extra_traits {
/// A named field like `self.x`.
Named(Ident),
/// An unnamed field like `self.0`.
@@ -1006,6 +1010,23 @@
}
}
+#[cfg(feature = "printing")]
+impl IdentFragment for Member {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ Member::Named(m) => Display::fmt(m, formatter),
+ Member::Unnamed(m) => Display::fmt(&m.index, formatter),
+ }
+ }
+
+ fn span(&self) -> Option<Span> {
+ match self {
+ Member::Named(m) => Some(m.span()),
+ Member::Unnamed(m) => Some(m.span),
+ }
+ }
+}
+
ast_struct! {
/// The index of an unnamed tuple struct field.
///
@@ -1027,28 +1048,36 @@
}
}
-#[cfg(feature = "extra-traits")]
impl Eq for Index {}
-#[cfg(feature = "extra-traits")]
impl PartialEq for Index {
fn eq(&self, other: &Self) -> bool {
self.index == other.index
}
}
-#[cfg(feature = "extra-traits")]
impl Hash for Index {
fn hash<H: Hasher>(&self, state: &mut H) {
self.index.hash(state);
}
}
+#[cfg(feature = "printing")]
+impl IdentFragment for Index {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ Display::fmt(&self.index, formatter)
+ }
+
+ fn span(&self) -> Option<Span> {
+ Some(self.span)
+ }
+}
+
#[cfg(feature = "full")]
ast_struct! {
#[derive(Default)]
pub struct Reserved {
- private: (),
+ _private: (),
}
}
@@ -1181,9 +1210,12 @@
pub(crate) mod parsing {
use super::*;
+ use crate::parse::discouraged::Speculative;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
+ crate::custom_keyword!(raw);
+
// When we're parsing expressions which occur before blocks, like in an if
// statement's condition, we cannot parse a struct literal.
//
@@ -1436,24 +1468,41 @@
// box <trailer>
#[cfg(feature = "full")]
fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
- // TODO: optimize using advance_to
+ let begin = input.fork();
let ahead = input.fork();
- ahead.call(Attribute::parse_outer)?;
+ let attrs = ahead.call(Attribute::parse_outer)?;
if ahead.peek(Token![&])
|| ahead.peek(Token![box])
|| ahead.peek(Token![*])
|| ahead.peek(Token![!])
|| ahead.peek(Token![-])
{
- let attrs = input.call(Attribute::parse_outer)?;
+ input.advance_to(&ahead);
if input.peek(Token![&]) {
- Ok(Expr::Reference(ExprReference {
- attrs,
- and_token: input.parse()?,
- raw: Reserved::default(),
- mutability: input.parse()?,
- expr: Box::new(unary_expr(input, allow_struct)?),
- }))
+ let and_token: Token![&] = input.parse()?;
+ let raw: Option<raw> = if input.peek(raw)
+ && (input.peek2(Token![mut]) || input.peek2(Token![const]))
+ {
+ Some(input.parse()?)
+ } else {
+ None
+ };
+ let mutability: Option<Token![mut]> = input.parse()?;
+ if raw.is_some() && mutability.is_none() {
+ input.parse::<Token![const]>()?;
+ }
+ let expr = Box::new(unary_expr(input, allow_struct)?);
+ if raw.is_some() {
+ Ok(Expr::Verbatim(verbatim::between(begin, input)))
+ } else {
+ Ok(Expr::Reference(ExprReference {
+ attrs,
+ and_token,
+ raw: Reserved::default(),
+ mutability,
+ expr,
+ }))
+ }
} else if input.peek(Token![box]) {
Ok(Expr::Box(ExprBox {
attrs,
@@ -1474,12 +1523,12 @@
#[cfg(not(feature = "full"))]
fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
- // TODO: optimize using advance_to
let ahead = input.fork();
- ahead.call(Attribute::parse_outer)?;
+ let attrs = ahead.call(Attribute::parse_outer)?;
if ahead.peek(Token![*]) || ahead.peek(Token![!]) || ahead.peek(Token![-]) {
+ input.advance_to(&ahead);
Ok(Expr::Unary(ExprUnary {
- attrs: input.call(Attribute::parse_outer)?,
+ attrs,
op: input.parse()?,
expr: Box::new(unary_expr(input, allow_struct)?),
}))
@@ -1905,7 +1954,7 @@
return parse_expr(input, expr, allow_struct, Precedence::Any);
};
- if input.peek(Token![.]) || input.peek(Token![?]) {
+ if input.peek(Token![.]) && !input.peek(Token![..]) || input.peek(Token![?]) {
expr = trailer_helper(input, expr)?;
attrs.extend(expr.replace_attrs(Vec::new()));
@@ -2399,6 +2448,7 @@
#[cfg(feature = "full")]
impl Parse for FieldValue {
fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = input.call(Attribute::parse_outer)?;
let member: Member = input.parse()?;
let (colon_token, value) = if input.peek(Token![:]) || !member.is_named() {
let colon_token: Token![:] = input.parse()?;
@@ -2416,7 +2466,7 @@
};
Ok(FieldValue {
- attrs: Vec::new(),
+ attrs,
member,
colon_token,
expr: value,
@@ -2433,24 +2483,22 @@
let content;
let brace_token = braced!(content in input);
let inner_attrs = content.call(Attribute::parse_inner)?;
+ let attrs = private::attrs(outer_attrs, inner_attrs);
let mut fields = Punctuated::new();
- loop {
- let attrs = content.call(Attribute::parse_outer)?;
- // TODO: optimize using advance_to
- if content.fork().parse::<Member>().is_err() {
- if attrs.is_empty() {
- break;
- } else {
- return Err(content.error("expected struct field"));
- }
+ while !content.is_empty() {
+ if content.peek(Token![..]) {
+ return Ok(ExprStruct {
+ attrs,
+ brace_token,
+ path,
+ fields,
+ dot2_token: Some(content.parse()?),
+ rest: Some(Box::new(content.parse()?)),
+ });
}
- fields.push(FieldValue {
- attrs,
- ..content.parse()?
- });
-
+ fields.push(content.parse()?);
if !content.peek(Token![,]) {
break;
}
@@ -2458,21 +2506,13 @@
fields.push_punct(punct);
}
- let (dot2_token, rest) = if fields.empty_or_trailing() && content.peek(Token![..]) {
- let dot2_token: Token![..] = content.parse()?;
- let rest: Expr = content.parse()?;
- (Some(dot2_token), Some(Box::new(rest)))
- } else {
- (None, None)
- };
-
Ok(ExprStruct {
- attrs: private::attrs(outer_attrs, inner_attrs),
+ attrs,
brace_token,
path,
fields,
- dot2_token,
- rest,
+ dot2_token: None,
+ rest: None,
})
}