Skip to content

Commit

Permalink
Make .. a pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 29, 2019
1 parent 43b8ded commit dab8097
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,14 @@ ast_enum_of_structs! {
pub pat: Box<Pat>,
}),

/// The dots in a tuple or slice pattern: `[0, 1, ..]`
///
/// *This type is available if Syn is built with the `"full"` feature.*
pub Rest(PatRest {
pub attrs: Vec<Attribute>,
pub dot2_token: Token![..],
}),

/// A dynamically sized slice pattern: `[a, b, i.., y, z]`.
///
/// *This type is available if Syn is built with the `"full"` feature.*
Expand Down Expand Up @@ -2123,6 +2131,7 @@ pub mod parsing {
Pat::Path(pat) => pat.attrs = attrs,
Pat::Range(pat) => pat.attrs = attrs,
Pat::Reference(pat) => pat.attrs = attrs,
Pat::Rest(pat) => pat.attrs = attrs,
Pat::Slice(pat) => pat.attrs = attrs,
Pat::Struct(pat) => pat.attrs = attrs,
Pat::Tuple(pat) => pat.attrs = attrs,
Expand Down Expand Up @@ -3812,6 +3821,13 @@ mod printing {
}
}

#[cfg(feature = "full")]
impl ToTokens for PatRest {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.dot2_token.to_tokens(tokens);
}
}

#[cfg(feature = "full")]
impl ToTokens for PatLit {
fn to_tokens(&self, tokens: &mut TokenStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub use crate::expr::{
#[cfg(feature = "full")]
pub use crate::expr::{
Arm, Block, FieldPat, FieldValue, GenericMethodArgument, Label, Local, MethodTurbofish, Pat,
PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatReference, PatSlice, PatStruct, PatTuple,
PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatReference, PatRest, PatSlice, PatStruct, PatTuple,
PatTupleStruct, PatType, PatVerbatim, PatWild, RangeLimits, Stmt,
};

Expand Down

0 comments on commit dab8097

Please sign in to comment.