From 0c9cf7284a86f2230dc388305c73b0d30825cef4 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 28 Jul 2019 17:31:57 -0700 Subject: [PATCH] Reserve a Pat variant for type ascription patterns --- src/expr.rs | 19 +++++++++++++++++++ src/lib.rs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index b574262ee..933f0ce37 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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, + pub pat: Box, + 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.* @@ -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) { diff --git a/src/lib.rs b/src/lib.rs index 3d11ddb2e..274314d19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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"))]