Skip to content

Commit

Permalink
Reserve a Pat variant for type ascription patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 29, 2019
1 parent a63858c commit 0c9cf72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,16 @@ ast_enum_of_structs! {
pub pat: PatTuple,
}),

/// A type ascription pattern: `foo: f64`.
///
/// *This type is available if Syn is built with the `"full"` feature.*
pub Type(PatType {
pub attrs: Vec<Attribute>,
pub pat: Box<Pat>,
pub colon_token: Token![:],
pub ty: Type,
}),

/// Tokens in pattern position not interpreted by Syn.
///
/// *This type is available if Syn is built with the `"full"` feature.*
Expand Down Expand Up @@ -3742,6 +3752,15 @@ mod printing {
}
}

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

#[cfg(feature = "full")]
impl ToTokens for PatPath {
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 @@ -332,7 +332,7 @@ pub use crate::expr::{
pub use crate::expr::{
Arm, Block, ClosureArg, FieldPat, FieldValue, GenericMethodArgument, Label, Local, MethodTurbofish, Pat,
PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatReference, PatSlice, PatStruct, PatTuple,
PatTupleStruct, PatVerbatim, PatWild, RangeLimits, Stmt,
PatTupleStruct, PatType, PatVerbatim, PatWild, RangeLimits, Stmt,
};

#[cfg(any(feature = "full", feature = "derive"))]
Expand Down

0 comments on commit 0c9cf72

Please sign in to comment.