/// A sign that you may not be choosing the right variable names is if you
/// see names getting repeated in your code, like accessing
/// `receiver.receiver` or `pat.pat` or `cond.cond`.
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub enum Expr {
/// A slice literal expression: `[a, b, c, d]`.
Array(ExprArray),
/// A yield expression: `yield expr`.
Yield(ExprYield),
+ // The following is the only supported idiom for exhaustive matching of
+ // this enum.
+ //
+ // match expr {
+ // Expr::Array(e) => {...}
+ // Expr::Assign(e) => {...}
+ // ...
+ // Expr::Yield(e) => {...}
+ //
+ // #[cfg(test)]
+ // Expr::__TestExhaustive(_) => unimplemented!(),
+ // #[cfg(not(test))]
+ // _ => { /* some sane fallback */ }
+ // }
+ //
+ // This way we fail your tests but don't break your library when adding
+ // a variant. You will be notified by a test failure when a variant is
+ // added, so that you can add code to handle it, but your library will
+ // continue to compile and work for downstream users in the interim.
+ //
+ // Once `deny(reachable)` is available in rustc, Expr will be
+ // reimplemented as a non_exhaustive enum.
+ // https://github.com/rust-lang/rust/issues/44109#issuecomment-521781237
#[doc(hidden)]
- __Nonexhaustive,
+ __TestExhaustive(crate::private),
}
}
/// A slice literal expression: `[a, b, c, d]`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprArray #full {
pub attrs: Vec<Attribute>,
pub bracket_token: token::Bracket,
/// An assignment expression: `a = compute()`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprAssign #full {
pub attrs: Vec<Attribute>,
pub left: Box<Expr>,
/// A compound assignment expression: `counter += 1`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprAssignOp #full {
pub attrs: Vec<Attribute>,
pub left: Box<Expr>,
/// An async block: `async { ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprAsync #full {
pub attrs: Vec<Attribute>,
pub async_token: Token![async],
/// An await expression: `fut.await`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprAwait #full {
pub attrs: Vec<Attribute>,
pub base: Box<Expr>,
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprBinary {
pub attrs: Vec<Attribute>,
pub left: Box<Expr>,
/// A blocked scope: `{ ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprBlock #full {
pub attrs: Vec<Attribute>,
pub label: Option<Label>,
/// A box expression: `box f`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprBox #full {
pub attrs: Vec<Attribute>,
pub box_token: Token![box],
/// expression.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprBreak #full {
pub attrs: Vec<Attribute>,
pub break_token: Token![break],
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprCall {
pub attrs: Vec<Attribute>,
pub func: Box<Expr>,
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprCast {
pub attrs: Vec<Attribute>,
pub expr: Box<Expr>,
/// A closure expression: `|a, b| a + b`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprClosure #full {
pub attrs: Vec<Attribute>,
pub asyncness: Option<Token![async]>,
/// A `continue`, with an optional label.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprContinue #full {
pub attrs: Vec<Attribute>,
pub continue_token: Token![continue],
/// field (`obj.0`).
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprField {
pub attrs: Vec<Attribute>,
pub base: Box<Expr>,
/// A for loop: `for pat in expr { ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprForLoop #full {
pub attrs: Vec<Attribute>,
pub label: Option<Label>,
/// `TokenStream`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprGroup #full {
pub attrs: Vec<Attribute>,
pub group_token: token::Group,
/// expression, not any of the other types of expression.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprIf #full {
pub attrs: Vec<Attribute>,
pub if_token: Token![if],
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprIndex {
pub attrs: Vec<Attribute>,
pub expr: Box<Expr>,
/// A `let` guard: `let Some(x) = opt`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprLet #full {
pub attrs: Vec<Attribute>,
pub let_token: Token![let],
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprLit {
pub attrs: Vec<Attribute>,
pub lit: Lit,
/// Conditionless loop: `loop { ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprLoop #full {
pub attrs: Vec<Attribute>,
pub label: Option<Label>,
/// A macro invocation expression: `format!("{}", q)`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprMacro #full {
pub attrs: Vec<Attribute>,
pub mac: Macro,
/// A `match` expression: `match n { Some(n) => {}, None => {} }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprMatch #full {
pub attrs: Vec<Attribute>,
pub match_token: Token![match],
/// A method call expression: `x.foo::<T>(a, b)`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprMethodCall #full {
pub attrs: Vec<Attribute>,
pub receiver: Box<Expr>,
/// A parenthesized expression: `(a + b)`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprParen {
pub attrs: Vec<Attribute>,
pub paren_token: token::Paren,
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprPath {
pub attrs: Vec<Attribute>,
pub qself: Option<QSelf>,
/// A range expression: `1..2`, `1..`, `..2`, `1..=2`, `..=2`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprRange #full {
pub attrs: Vec<Attribute>,
pub from: Option<Box<Expr>>,
/// A referencing operation: `&a` or `&mut a`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprReference #full {
pub attrs: Vec<Attribute>,
pub and_token: Token![&],
/// An array literal constructed from one repeated element: `[0u8; N]`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprRepeat #full {
pub attrs: Vec<Attribute>,
pub bracket_token: token::Bracket,
/// A `return`, with an optional value to be returned.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprReturn #full {
pub attrs: Vec<Attribute>,
pub return_token: Token![return],
/// 1, b: 1, ..rest }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprStruct #full {
pub attrs: Vec<Attribute>,
pub path: Path,
/// A try-expression: `expr?`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprTry #full {
pub attrs: Vec<Attribute>,
pub expr: Box<Expr>,
/// A try block: `try { ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprTryBlock #full {
pub attrs: Vec<Attribute>,
pub try_token: Token![try],
/// A tuple expression: `(a, b, c, d)`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprTuple #full {
pub attrs: Vec<Attribute>,
pub paren_token: token::Paren,
/// A type ascription expression: `foo: f64`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprType #full {
pub attrs: Vec<Attribute>,
pub expr: Box<Expr>,
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct ExprUnary {
pub attrs: Vec<Attribute>,
pub op: UnOp,
/// An unsafe block: `unsafe { ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprUnsafe #full {
pub attrs: Vec<Attribute>,
pub unsafe_token: Token![unsafe],
/// A while loop: `while expr { ... }`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprWhile #full {
pub attrs: Vec<Attribute>,
pub label: Option<Label>,
/// A yield expression: `yield expr`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct ExprYield #full {
pub attrs: Vec<Attribute>,
pub yield_token: Token![yield],
| Expr::TryBlock(ExprTryBlock { attrs, .. })
| Expr::Yield(ExprYield { attrs, .. }) => mem::replace(attrs, new),
Expr::Verbatim(_) => Vec::new(),
- Expr::__Nonexhaustive => unreachable!(),
+
+ #[cfg(test)]
+ Expr::__TestExhaustive(_) => unimplemented!(),
+ #[cfg(not(test))]
+ _ => unreachable!(),
}
}
}
///
/// *This type is available only if Syn is built with the `"derive"` or `"full"`
/// feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub enum Member {
/// A named field like `self.x`.
Named(Ident),
///
/// *This type is available only if Syn is built with the `"derive"` or `"full"`
/// feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct Index {
pub index: u32,
pub span: Span,
/// `parse::<u64>()`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct MethodTurbofish {
pub colon2_token: Token![::],
pub lt_token: Token![<],
/// An individual generic argument to a method, like `T`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub enum GenericMethodArgument {
/// A type argument.
Type(Type),
/// A field-value pair in a struct literal.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct FieldValue {
/// Attributes tagged on the field.
pub attrs: Vec<Attribute>,
/// A lifetime labeling a `for`, `while`, or `loop`.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct Label {
pub name: Lifetime,
pub colon_token: Token![:],
/// ```
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub struct Arm {
pub attrs: Vec<Attribute>,
pub pat: Pat,
/// Limit types of a range, inclusive or exclusive.
///
/// *This type is available only if Syn is built with the `"full"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
pub enum RangeLimits {
/// Inclusive at the beginning, exclusive at the end.
HalfOpen(Token![..]),
use super::*;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
+ #[cfg(feature = "full")]
+ use proc_macro2::TokenTree;
use std::cmp::Ordering;
crate::custom_keyword!(raw);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Expr {
fn parse(input: ParseStream) -> Result<Self> {
ambiguous_expr(input, AllowStruct(true))
/// implying tighter precedence for `..` than struct init, a
/// contradiction.
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(all(feature = "full", feature = "parsing"))))]
pub fn parse_without_eager_brace(input: ParseStream) -> Result<Expr> {
ambiguous_expr(input, AllowStruct(false))
}
let rhs = if input.is_empty()
|| input.peek(Token![,])
|| input.peek(Token![;])
+ || input.peek(Token![.]) && !input.peek(Token![..])
|| !allow_struct.0 && input.peek(token::Brace)
{
None
Precedence::Assign
} else if input.peek(Token![..]) {
Precedence::Range
- } else if input.peek(Token![as]) || input.peek(Token![:]) && !input.peek(Token![::]) {
+ } else if input.peek(Token![as])
+ || cfg!(feature = "full") && input.peek(Token![:]) && !input.peek(Token![::])
+ {
Precedence::Cast
} else {
Precedence::Any
}))
}
} else if input.peek(Token![box]) {
- Ok(Expr::Box(ExprBox {
- attrs,
- box_token: input.parse()?,
- expr: Box::new(unary_expr(input, allow_struct)?),
- }))
+ expr_box(input, attrs, allow_struct).map(Expr::Box)
} else if input.peek(Token![*]) || input.peek(Token![!]) || input.peek(Token![-]) {
- Ok(Expr::Unary(ExprUnary {
- attrs,
- op: input.parse()?,
- expr: Box::new(unary_expr(input, allow_struct)?),
- }))
+ expr_unary(input, attrs, allow_struct).map(Expr::Unary)
} else {
trailer_expr(attrs, input, allow_struct)
}
// <atom> ? ...
#[cfg(feature = "full")]
fn trailer_expr(
- outer_attrs: Vec<Attribute>,
+ mut attrs: Vec<Attribute>,
input: ParseStream,
allow_struct: AllowStruct,
) -> Result<Expr> {
let mut e = trailer_helper(input, atom)?;
let inner_attrs = e.replace_attrs(Vec::new());
- let attrs = private::attrs(outer_attrs, inner_attrs);
+ attrs.extend(inner_attrs);
e.replace_attrs(attrs);
Ok(e)
}
paren_token: parenthesized!(content in input),
args: content.parse_terminated(Expr::parse)?,
});
- } else if input.peek(Token![.]) && !input.peek(Token![..]) {
+ } else if input.peek(Token![.])
+ && !input.peek(Token![..])
+ && match e {
+ Expr::Range(_) => false,
+ _ => true,
+ }
+ {
let mut dot_token: Token![.] = input.parse()?;
let await_token: Option<token::Await> = input.parse()?;
} else if input.peek(Token![async])
&& (input.peek2(token::Brace) || input.peek2(Token![move]) && input.peek3(token::Brace))
{
- input.call(expr_async).map(Expr::Async)
+ input.parse().map(Expr::Async)
} else if input.peek(Token![try]) && input.peek2(token::Brace) {
- input.call(expr_try_block).map(Expr::TryBlock)
+ input.parse().map(Expr::TryBlock)
} else if input.peek(Token![|])
|| input.peek(Token![async]) && (input.peek2(Token![|]) || input.peek2(Token![move]))
|| input.peek(Token![static])
} else if input.peek(Token![break]) {
expr_break(input, allow_struct).map(Expr::Break)
} else if input.peek(Token![continue]) {
- input.call(expr_continue).map(Expr::Continue)
+ input.parse().map(Expr::Continue)
} else if input.peek(Token![return]) {
expr_ret(input, allow_struct).map(Expr::Return)
} else if input.peek(token::Bracket) {
array_or_repeat(input)
} else if input.peek(Token![let]) {
- input.call(expr_let).map(Expr::Let)
+ input.parse().map(Expr::Let)
} else if input.peek(Token![if]) {
input.parse().map(Expr::If)
} else if input.peek(Token![while]) {
} else if input.peek(Token![match]) {
input.parse().map(Expr::Match)
} else if input.peek(Token![yield]) {
- input.call(expr_yield).map(Expr::Yield)
+ input.parse().map(Expr::Yield)
} else if input.peek(Token![unsafe]) {
- input.call(expr_unsafe).map(Expr::Unsafe)
+ input.parse().map(Expr::Unsafe)
+ } else if input.peek(Token![const]) {
+ input.call(expr_const).map(Expr::Verbatim)
} else if input.peek(token::Brace) {
- input.call(expr_block).map(Expr::Block)
+ input.parse().map(Expr::Block)
} else if input.peek(Token![..]) {
expr_range(input, allow_struct).map(Expr::Range)
+ } else if input.peek(Token![_]) {
+ Ok(Expr::Verbatim(TokenStream::from(
+ input.parse::<TokenTree>()?,
+ )))
} else if input.peek(Lifetime) {
let the_label: Label = input.parse()?;
let mut expr = if input.peek(Token![while]) {
} else if input.peek(Token![loop]) {
Expr::Loop(input.parse()?)
} else if input.peek(token::Brace) {
- Expr::Block(input.call(expr_block)?)
+ Expr::Block(input.parse()?)
} else {
return Err(input.error("expected loop or block expression"));
};
}
}
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprMacro {
+ fn parse(input: ParseStream) -> Result<Self> {
+ Ok(ExprMacro {
+ attrs: Vec::new(),
+ mac: input.parse()?,
+ })
+ }
+ }
+
#[cfg(feature = "full")]
fn paren_or_tuple(input: ParseStream) -> Result<Expr> {
let content;
}
}
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprArray {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let content;
+ let bracket_token = bracketed!(content in input);
+ let inner_attrs = content.call(Attribute::parse_inner)?;
+ let mut elems = Punctuated::new();
+
+ while !content.is_empty() {
+ let first: Expr = content.parse()?;
+ elems.push_value(first);
+ if content.is_empty() {
+ break;
+ }
+ let punct = content.parse()?;
+ elems.push_punct(punct);
+ }
+
+ Ok(ExprArray {
+ attrs: inner_attrs,
+ bracket_token,
+ elems,
+ })
+ }
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprRepeat {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let content;
+ Ok(ExprRepeat {
+ bracket_token: bracketed!(content in input),
+ attrs: content.call(Attribute::parse_inner)?,
+ expr: content.parse()?,
+ semi_token: content.parse()?,
+ len: content.parse()?,
+ })
+ }
+ }
+
#[cfg(feature = "full")]
pub(crate) fn expr_early(input: ParseStream) -> Result<Expr> {
let mut attrs = input.call(expr_attrs)?;
} else if input.peek(Token![match]) {
Expr::Match(input.parse()?)
} else if input.peek(Token![try]) && input.peek2(token::Brace) {
- Expr::TryBlock(input.call(expr_try_block)?)
+ Expr::TryBlock(input.parse()?)
} else if input.peek(Token![unsafe]) {
- Expr::Unsafe(input.call(expr_unsafe)?)
+ Expr::Unsafe(input.parse()?)
+ } else if input.peek(Token![const]) {
+ Expr::Verbatim(input.call(expr_const)?)
} else if input.peek(token::Brace) {
- Expr::Block(input.call(expr_block)?)
+ Expr::Block(input.parse()?)
} else {
let allow_struct = AllowStruct(true);
let mut expr = unary_expr(input, allow_struct)?;
Ok(expr)
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprLit {
fn parse(input: ParseStream) -> Result<Self> {
Ok(ExprLit {
})
}
- #[cfg(not(feature = "full"))]
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprParen {
+ fn parse(input: ParseStream) -> Result<Self> {
+ expr_paren(input)
+ }
+ }
+
fn expr_paren(input: ParseStream) -> Result<ExprParen> {
let content;
Ok(ExprParen {
}
if input.peek(token::Brace) {
- let block = input.call(expr::parsing::expr_block)?;
+ let block: ExprBlock = input.parse()?;
return Ok(GenericMethodArgument::Const(Expr::Block(block)));
}
}
#[cfg(feature = "full")]
- fn expr_let(input: ParseStream) -> Result<ExprLet> {
- Ok(ExprLet {
- attrs: Vec::new(),
- let_token: input.parse()?,
- pat: pat::parsing::multi_pat_with_leading_vert(input)?,
- eq_token: input.parse()?,
- expr: Box::new(input.call(Expr::parse_without_eager_brace)?),
- })
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprLet {
+ fn parse(input: ParseStream) -> Result<Self> {
+ Ok(ExprLet {
+ attrs: Vec::new(),
+ let_token: input.parse()?,
+ pat: pat::parsing::multi_pat_with_leading_vert(input)?,
+ eq_token: input.parse()?,
+ expr: Box::new(input.call(Expr::parse_without_eager_brace)?),
+ })
+ }
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprIf {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprForLoop {
fn parse(input: ParseStream) -> Result<Self> {
- let outer_attrs = input.call(Attribute::parse_outer)?;
+ let mut attrs = input.call(Attribute::parse_outer)?;
let label: Option<Label> = input.parse()?;
let for_token: Token![for] = input.parse()?;
let content;
let brace_token = braced!(content in input);
- let inner_attrs = content.call(Attribute::parse_inner)?;
+ attr::parsing::parse_inner(&content, &mut attrs)?;
let stmts = content.call(Block::parse_within)?;
Ok(ExprForLoop {
- attrs: private::attrs(outer_attrs, inner_attrs),
+ attrs,
label,
for_token,
pat,
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprLoop {
fn parse(input: ParseStream) -> Result<Self> {
- let outer_attrs = input.call(Attribute::parse_outer)?;
+ let mut attrs = input.call(Attribute::parse_outer)?;
let label: Option<Label> = input.parse()?;
let loop_token: Token![loop] = input.parse()?;
let content;
let brace_token = braced!(content in input);
- let inner_attrs = content.call(Attribute::parse_inner)?;
+ attr::parsing::parse_inner(&content, &mut attrs)?;
let stmts = content.call(Block::parse_within)?;
Ok(ExprLoop {
- attrs: private::attrs(outer_attrs, inner_attrs),
+ attrs,
label,
loop_token,
body: Block { brace_token, stmts },
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprMatch {
fn parse(input: ParseStream) -> Result<Self> {
- let outer_attrs = input.call(Attribute::parse_outer)?;
+ let mut attrs = input.call(Attribute::parse_outer)?;
let match_token: Token![match] = input.parse()?;
let expr = Expr::parse_without_eager_brace(input)?;
let content;
let brace_token = braced!(content in input);
- let inner_attrs = content.call(Attribute::parse_inner)?;
+ attr::parsing::parse_inner(&content, &mut attrs)?;
let mut arms = Vec::new();
while !content.is_empty() {
}
Ok(ExprMatch {
- attrs: private::attrs(outer_attrs, inner_attrs),
+ attrs,
match_token,
expr: Box::new(expr),
brace_token,
) => {
$(
#[cfg(all(feature = "full", feature = "printing"))]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for $expr_type {
fn parse(input: ParseStream) -> Result<Self> {
let mut expr: Expr = input.parse()?;
}
impl_by_parsing_expr! {
- ExprBox, Box, "expected box expression",
- ExprArray, Array, "expected slice literal expression",
ExprCall, Call, "expected function call expression",
ExprMethodCall, MethodCall, "expected method call expression",
ExprTuple, Tuple, "expected tuple expression",
ExprBinary, Binary, "expected binary operation",
- ExprUnary, Unary, "expected unary operation",
ExprCast, Cast, "expected cast expression",
ExprType, Type, "expected type ascription expression",
- ExprLet, Let, "expected let guard",
- ExprClosure, Closure, "expected closure expression",
- ExprUnsafe, Unsafe, "expected unsafe block",
- ExprBlock, Block, "expected blocked scope",
ExprAssign, Assign, "expected assignment expression",
ExprAssignOp, AssignOp, "expected compound assignment expression",
ExprField, Field, "expected struct field access",
ExprIndex, Index, "expected indexing expression",
ExprRange, Range, "expected range expression",
- ExprReference, Reference, "expected referencing operation",
- ExprBreak, Break, "expected break expression",
- ExprContinue, Continue, "expected continue expression",
- ExprReturn, Return, "expected return expression",
- ExprMacro, Macro, "expected macro invocation expression",
- ExprStruct, Struct, "expected struct literal expression",
- ExprRepeat, Repeat, "expected array literal constructed from one repeated element",
- ExprParen, Paren, "expected parenthesized expression",
ExprTry, Try, "expected try expression",
- ExprAsync, Async, "expected async block",
- ExprTryBlock, TryBlock, "expected try block",
- ExprYield, Yield, "expected yield expression",
}
#[cfg(feature = "full")]
- fn expr_try_block(input: ParseStream) -> Result<ExprTryBlock> {
- Ok(ExprTryBlock {
- attrs: Vec::new(),
- try_token: input.parse()?,
- block: input.parse()?,
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprBox {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = Vec::new();
+ let allow_struct = AllowStruct(true);
+ expr_box(input, attrs, allow_struct)
+ }
+ }
+
+ #[cfg(feature = "full")]
+ fn expr_box(
+ input: ParseStream,
+ attrs: Vec<Attribute>,
+ allow_struct: AllowStruct,
+ ) -> Result<ExprBox> {
+ Ok(ExprBox {
+ attrs,
+ box_token: input.parse()?,
+ expr: Box::new(unary_expr(input, allow_struct)?),
})
}
#[cfg(feature = "full")]
- fn expr_yield(input: ParseStream) -> Result<ExprYield> {
- Ok(ExprYield {
- attrs: Vec::new(),
- yield_token: input.parse()?,
- expr: {
- if !input.is_empty() && !input.peek(Token![,]) && !input.peek(Token![;]) {
- Some(input.parse()?)
- } else {
- None
- }
- },
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprUnary {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = Vec::new();
+ let allow_struct = AllowStruct(true);
+ expr_unary(input, attrs, allow_struct)
+ }
+ }
+
+ #[cfg(feature = "full")]
+ fn expr_unary(
+ input: ParseStream,
+ attrs: Vec<Attribute>,
+ allow_struct: AllowStruct,
+ ) -> Result<ExprUnary> {
+ Ok(ExprUnary {
+ attrs,
+ op: input.parse()?,
+ expr: Box::new(unary_expr(input, allow_struct)?),
})
}
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprClosure {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let allow_struct = AllowStruct(true);
+ expr_closure(input, allow_struct)
+ }
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprReference {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let allow_struct = AllowStruct(true);
+ Ok(ExprReference {
+ attrs: Vec::new(),
+ and_token: input.parse()?,
+ raw: Reserved::default(),
+ mutability: input.parse()?,
+ expr: Box::new(unary_expr(input, allow_struct)?),
+ })
+ }
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprBreak {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let allow_struct = AllowStruct(true);
+ expr_break(input, allow_struct)
+ }
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprReturn {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let allow_struct = AllowStruct(true);
+ expr_ret(input, allow_struct)
+ }
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprTryBlock {
+ fn parse(input: ParseStream) -> Result<Self> {
+ Ok(ExprTryBlock {
+ attrs: Vec::new(),
+ try_token: input.parse()?,
+ block: input.parse()?,
+ })
+ }
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprYield {
+ fn parse(input: ParseStream) -> Result<Self> {
+ Ok(ExprYield {
+ attrs: Vec::new(),
+ yield_token: input.parse()?,
+ expr: {
+ if !input.is_empty() && !input.peek(Token![,]) && !input.peek(Token![;]) {
+ Some(input.parse()?)
+ } else {
+ None
+ }
+ },
+ })
+ }
+ }
+
#[cfg(feature = "full")]
fn expr_closure(input: ParseStream, allow_struct: AllowStruct) -> Result<ExprClosure> {
let asyncness: Option<Token![async]> = input.parse()?;
}
#[cfg(feature = "full")]
- fn expr_async(input: ParseStream) -> Result<ExprAsync> {
- Ok(ExprAsync {
- attrs: Vec::new(),
- async_token: input.parse()?,
- capture: input.parse()?,
- block: input.parse()?,
- })
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprAsync {
+ fn parse(input: ParseStream) -> Result<Self> {
+ Ok(ExprAsync {
+ attrs: Vec::new(),
+ async_token: input.parse()?,
+ capture: input.parse()?,
+ block: input.parse()?,
+ })
+ }
}
#[cfg(feature = "full")]
Pat::Type(_) => unreachable!(),
Pat::Verbatim(_) => {}
Pat::Wild(pat) => pat.attrs = attrs,
- Pat::__Nonexhaustive => unreachable!(),
+
+ #[cfg(test)]
+ Pat::__TestExhaustive(_) => unimplemented!(),
+ #[cfg(not(test))]
+ _ => unreachable!(),
}
Ok(pat)
}
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprWhile {
fn parse(input: ParseStream) -> Result<Self> {
- let outer_attrs = input.call(Attribute::parse_outer)?;
+ let mut attrs = input.call(Attribute::parse_outer)?;
let label: Option<Label> = input.parse()?;
let while_token: Token![while] = input.parse()?;
let cond = Expr::parse_without_eager_brace(input)?;
let content;
let brace_token = braced!(content in input);
- let inner_attrs = content.call(Attribute::parse_inner)?;
+ attr::parsing::parse_inner(&content, &mut attrs)?;
let stmts = content.call(Block::parse_within)?;
Ok(ExprWhile {
- attrs: private::attrs(outer_attrs, inner_attrs),
+ attrs,
label,
while_token,
cond: Box::new(cond),
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Label {
fn parse(input: ParseStream) -> Result<Self> {
Ok(Label {
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Option<Label> {
fn parse(input: ParseStream) -> Result<Self> {
if input.peek(Lifetime) {
}
#[cfg(feature = "full")]
- fn expr_continue(input: ParseStream) -> Result<ExprContinue> {
- Ok(ExprContinue {
- attrs: Vec::new(),
- continue_token: input.parse()?,
- label: input.parse()?,
- })
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprContinue {
+ fn parse(input: ParseStream) -> Result<Self> {
+ Ok(ExprContinue {
+ attrs: Vec::new(),
+ continue_token: input.parse()?,
+ label: input.parse()?,
+ })
+ }
}
#[cfg(feature = "full")]
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for FieldValue {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
}
}
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprStruct {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = Vec::new();
+ let path: Path = input.parse()?;
+ expr_struct_helper(input, attrs, path)
+ }
+ }
+
#[cfg(feature = "full")]
fn expr_struct_helper(
input: ParseStream,
- outer_attrs: Vec<Attribute>,
+ mut attrs: Vec<Attribute>,
path: Path,
) -> Result<ExprStruct> {
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);
+ attr::parsing::parse_inner(&content, &mut attrs)?;
let mut fields = Punctuated::new();
while !content.is_empty() {
path,
fields,
dot2_token: Some(content.parse()?),
- rest: Some(Box::new(content.parse()?)),
+ rest: if content.is_empty() {
+ None
+ } else {
+ Some(Box::new(content.parse()?))
+ },
});
}
}
#[cfg(feature = "full")]
- fn expr_unsafe(input: ParseStream) -> Result<ExprUnsafe> {
- let unsafe_token: Token![unsafe] = input.parse()?;
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprUnsafe {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let unsafe_token: Token![unsafe] = input.parse()?;
- let content;
- let brace_token = braced!(content in input);
- let inner_attrs = content.call(Attribute::parse_inner)?;
- let stmts = content.call(Block::parse_within)?;
+ let content;
+ let brace_token = braced!(content in input);
+ let inner_attrs = content.call(Attribute::parse_inner)?;
+ let stmts = content.call(Block::parse_within)?;
- Ok(ExprUnsafe {
- attrs: inner_attrs,
- unsafe_token,
- block: Block { brace_token, stmts },
- })
+ Ok(ExprUnsafe {
+ attrs: inner_attrs,
+ unsafe_token,
+ block: Block { brace_token, stmts },
+ })
+ }
}
#[cfg(feature = "full")]
- pub fn expr_block(input: ParseStream) -> Result<ExprBlock> {
- let label: Option<Label> = input.parse()?;
+ pub(crate) fn expr_const(input: ParseStream) -> Result<TokenStream> {
+ let begin = input.fork();
+ input.parse::<Token![const]>()?;
let content;
- let brace_token = braced!(content in input);
- let inner_attrs = content.call(Attribute::parse_inner)?;
- let stmts = content.call(Block::parse_within)?;
+ braced!(content in input);
+ content.call(Attribute::parse_inner)?;
+ content.call(Block::parse_within)?;
- Ok(ExprBlock {
- attrs: inner_attrs,
- label,
- block: Block { brace_token, stmts },
- })
+ Ok(verbatim::between(begin, input))
+ }
+
+ #[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for ExprBlock {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let mut attrs = input.call(Attribute::parse_outer)?;
+ let label: Option<Label> = input.parse()?;
+
+ let content;
+ let brace_token = braced!(content in input);
+ attr::parsing::parse_inner(&content, &mut attrs)?;
+ let stmts = content.call(Block::parse_within)?;
+
+ Ok(ExprBlock {
+ attrs,
+ label,
+ block: Block { brace_token, stmts },
+ })
+ }
}
#[cfg(feature = "full")]
if input.is_empty()
|| input.peek(Token![,])
|| input.peek(Token![;])
+ || input.peek(Token![.]) && !input.peek(Token![..])
|| !allow_struct.0 && input.peek(token::Brace)
{
None
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for RangeLimits {
fn parse(input: ParseStream) -> Result<Self> {
let lookahead = input.lookahead1();
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprPath {
fn parse(input: ParseStream) -> Result<Self> {
#[cfg(not(feature = "full"))]
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Member {
fn parse(input: ParseStream) -> Result<Self> {
if input.peek(Ident) {
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Arm {
fn parse(input: ParseStream) -> Result<Arm> {
let requires_comma;
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Index {
fn parse(input: ParseStream) -> Result<Self> {
let lit: LitInt = input.parse()?;
}
for part in float_repr.split('.') {
let index = crate::parse_str(part).map_err(|err| Error::new(float.span(), err))?;
- let base = mem::replace(e, Expr::__Nonexhaustive);
+ let base = mem::replace(e, Expr::__TestExhaustive(crate::private(())));
*e = Expr::Field(ExprField {
attrs: Vec::new(),
base: Box::new(base),
use super::*;
#[cfg(feature = "full")]
use crate::attr::FilterAttrs;
- #[cfg(feature = "full")]
- use crate::print::TokensOrDefault;
use proc_macro2::{Literal, TokenStream};
use quote::{ToTokens, TokenStreamExt};
fn inner_attrs_to_tokens(_attrs: &[Attribute], _tokens: &mut TokenStream) {}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprBox {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprArray {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprCall {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprMethodCall {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for MethodTurbofish {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.colon2_token.to_tokens(tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for GenericMethodArgument {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprTuple {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprBinary {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprUnary {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprLit {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprCast {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprType {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprLet {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprIf {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprWhile {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprForLoop {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprLoop {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprMatch {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprAsync {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprAwait {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprTryBlock {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprYield {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprClosure {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprUnsafe {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprBlock {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprAssign {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprAssignOp {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprField {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Member {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Index {
fn to_tokens(&self, tokens: &mut TokenStream) {
let mut lit = Literal::i64_unsuffixed(i64::from(self.index));
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprIndex {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprRange {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprPath {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprReference {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprBreak {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprContinue {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprReturn {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprMacro {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprStruct {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
self.brace_token.surround(tokens, |tokens| {
inner_attrs_to_tokens(&self.attrs, tokens);
self.fields.to_tokens(tokens);
- if self.rest.is_some() {
- TokensOrDefault(&self.dot2_token).to_tokens(tokens);
- self.rest.to_tokens(tokens);
+ if let Some(dot2_token) = &self.dot2_token {
+ dot2_token.to_tokens(tokens);
+ } else if self.rest.is_some() {
+ Token![..](Span::call_site()).to_tokens(tokens);
}
+ self.rest.to_tokens(tokens);
})
}
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprRepeat {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprGroup {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprParen {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ExprTry {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Label {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.name.to_tokens(tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for FieldValue {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Arm {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append_all(&self.attrs);