Expand Type::Macro and Pat::Macro into real variants
diff --git a/src/expr.rs b/src/expr.rs
index 17834d4..6578aff 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -681,7 +681,9 @@
pub back: Delimited<Pat, Token![,]>,
}),
/// A macro pattern; pre-expansion
- pub Macro(Macro),
+ pub Macro(PatMacro {
+ pub mac: Macro,
+ }),
pub Verbatim(PatVerbatim #manual_extra_traits {
pub tts: TokenStream,
}),
@@ -2105,7 +2107,7 @@
|
syn!(PatStruct) => { Pat::Struct } // must be before pat_ident
|
- syn!(Macro) => { Pat::Macro } // must be before pat_ident
+ syn!(PatMacro) => { Pat::Macro } // must be before pat_ident
|
syn!(PatLit) => { Pat::Lit } // must be before pat_ident
|
@@ -2413,6 +2415,11 @@
}
));
}
+
+ #[cfg(feature = "full")]
+ impl Synom for PatMacro {
+ named!(parse -> Self, map!(syn!(Macro), |mac| PatMacro { mac: mac }));
+ }
}
#[cfg(feature = "printing")]
@@ -3124,6 +3131,13 @@
}
#[cfg(feature = "full")]
+ impl ToTokens for PatMacro {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.mac.to_tokens(tokens);
+ }
+ }
+
+ #[cfg(feature = "full")]
impl ToTokens for PatVerbatim {
fn to_tokens(&self, tokens: &mut Tokens) {
self.tts.to_tokens(tokens);
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index 25c337b..1ce2f31 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -274,6 +274,8 @@
# [ cfg ( feature = "full" ) ]
fn fold_pat_lit(&mut self, i: PatLit) -> PatLit { fold_pat_lit(self, i) }
# [ cfg ( feature = "full" ) ]
+fn fold_pat_macro(&mut self, i: PatMacro) -> PatMacro { fold_pat_macro(self, i) }
+# [ cfg ( feature = "full" ) ]
fn fold_pat_path(&mut self, i: PatPath) -> PatPath { fold_pat_path(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_pat_range(&mut self, i: PatRange) -> PatRange { fold_pat_range(self, i) }
@@ -338,6 +340,8 @@
fn fold_type_infer(&mut self, i: TypeInfer) -> TypeInfer { fold_type_infer(self, i) }
+fn fold_type_macro(&mut self, i: TypeMacro) -> TypeMacro { fold_type_macro(self, i) }
+
fn fold_type_never(&mut self, i: TypeNever) -> TypeNever { fold_type_never(self, i) }
fn fold_type_param(&mut self, i: TypeParam) -> TypeParam { fold_type_param(self, i) }
@@ -2102,7 +2106,7 @@
}
Macro(_binding_0, ) => {
Macro (
- _visitor.fold_macro(_binding_0),
+ _visitor.fold_pat_macro(_binding_0),
)
}
Verbatim(_binding_0, ) => {
@@ -2136,6 +2140,12 @@
}
}
# [ cfg ( feature = "full" ) ]
+pub fn fold_pat_macro<V: Folder + ?Sized>(_visitor: &mut V, _i: PatMacro) -> PatMacro {
+ PatMacro {
+ mac: _visitor.fold_macro(_i . mac),
+ }
+}
+# [ cfg ( feature = "full" ) ]
pub fn fold_pat_path<V: Folder + ?Sized>(_visitor: &mut V, _i: PatPath) -> PatPath {
PatPath {
qself: (_i . qself).map(|it| { _visitor.fold_qself(it) }),
@@ -2483,7 +2493,7 @@
}
Macro(_binding_0, ) => {
Macro (
- _visitor.fold_macro(_binding_0),
+ _visitor.fold_type_macro(_binding_0),
)
}
Verbatim(_binding_0, ) => {
@@ -2544,6 +2554,12 @@
}
}
+pub fn fold_type_macro<V: Folder + ?Sized>(_visitor: &mut V, _i: TypeMacro) -> TypeMacro {
+ TypeMacro {
+ mac: _visitor.fold_macro(_i . mac),
+ }
+}
+
pub fn fold_type_never<V: Folder + ?Sized>(_visitor: &mut V, _i: TypeNever) -> TypeNever {
TypeNever {
bang_token: Token ! [ ! ](tokens_helper(_visitor, &(_i . bang_token).0)),
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index 411651d..72ef863 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -270,6 +270,8 @@
# [ cfg ( feature = "full" ) ]
fn visit_pat_lit(&mut self, i: &'ast PatLit) { visit_pat_lit(self, i) }
# [ cfg ( feature = "full" ) ]
+fn visit_pat_macro(&mut self, i: &'ast PatMacro) { visit_pat_macro(self, i) }
+# [ cfg ( feature = "full" ) ]
fn visit_pat_path(&mut self, i: &'ast PatPath) { visit_pat_path(self, i) }
# [ cfg ( feature = "full" ) ]
fn visit_pat_range(&mut self, i: &'ast PatRange) { visit_pat_range(self, i) }
@@ -334,6 +336,8 @@
fn visit_type_infer(&mut self, i: &'ast TypeInfer) { visit_type_infer(self, i) }
+fn visit_type_macro(&mut self, i: &'ast TypeMacro) { visit_type_macro(self, i) }
+
fn visit_type_never(&mut self, i: &'ast TypeNever) { visit_type_never(self, i) }
fn visit_type_param(&mut self, i: &'ast TypeParam) { visit_type_param(self, i) }
@@ -1643,7 +1647,7 @@
_visitor.visit_pat_slice(_binding_0);
}
Macro(ref _binding_0, ) => {
- _visitor.visit_macro(_binding_0);
+ _visitor.visit_pat_macro(_binding_0);
}
Verbatim(ref _binding_0, ) => {
_visitor.visit_pat_verbatim(_binding_0);
@@ -1668,6 +1672,10 @@
_visitor.visit_expr(& * _i . expr);
}
# [ cfg ( feature = "full" ) ]
+pub fn visit_pat_macro<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatMacro) {
+ _visitor.visit_macro(& _i . mac);
+}
+# [ cfg ( feature = "full" ) ]
pub fn visit_pat_path<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PatPath) {
if let Some(ref it) = _i . qself { _visitor.visit_qself(it) };
_visitor.visit_path(& _i . path);
@@ -1921,7 +1929,7 @@
_visitor.visit_type_infer(_binding_0);
}
Macro(ref _binding_0, ) => {
- _visitor.visit_macro(_binding_0);
+ _visitor.visit_type_macro(_binding_0);
}
Verbatim(ref _binding_0, ) => {
_visitor.visit_type_verbatim(_binding_0);
@@ -1967,6 +1975,10 @@
tokens_helper(_visitor, &(& _i . underscore_token).0);
}
+pub fn visit_type_macro<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast TypeMacro) {
+ _visitor.visit_macro(& _i . mac);
+}
+
pub fn visit_type_never<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast TypeNever) {
tokens_helper(_visitor, &(& _i . bang_token).0);
}
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 17afe9e..8b13b47 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -270,6 +270,8 @@
# [ cfg ( feature = "full" ) ]
fn visit_pat_lit_mut(&mut self, i: &mut PatLit) { visit_pat_lit_mut(self, i) }
# [ cfg ( feature = "full" ) ]
+fn visit_pat_macro_mut(&mut self, i: &mut PatMacro) { visit_pat_macro_mut(self, i) }
+# [ cfg ( feature = "full" ) ]
fn visit_pat_path_mut(&mut self, i: &mut PatPath) { visit_pat_path_mut(self, i) }
# [ cfg ( feature = "full" ) ]
fn visit_pat_range_mut(&mut self, i: &mut PatRange) { visit_pat_range_mut(self, i) }
@@ -334,6 +336,8 @@
fn visit_type_infer_mut(&mut self, i: &mut TypeInfer) { visit_type_infer_mut(self, i) }
+fn visit_type_macro_mut(&mut self, i: &mut TypeMacro) { visit_type_macro_mut(self, i) }
+
fn visit_type_never_mut(&mut self, i: &mut TypeNever) { visit_type_never_mut(self, i) }
fn visit_type_param_mut(&mut self, i: &mut TypeParam) { visit_type_param_mut(self, i) }
@@ -1643,7 +1647,7 @@
_visitor.visit_pat_slice_mut(_binding_0);
}
Macro(ref mut _binding_0, ) => {
- _visitor.visit_macro_mut(_binding_0);
+ _visitor.visit_pat_macro_mut(_binding_0);
}
Verbatim(ref mut _binding_0, ) => {
_visitor.visit_pat_verbatim_mut(_binding_0);
@@ -1668,6 +1672,10 @@
_visitor.visit_expr_mut(& mut * _i . expr);
}
# [ cfg ( feature = "full" ) ]
+pub fn visit_pat_macro_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut PatMacro) {
+ _visitor.visit_macro_mut(& mut _i . mac);
+}
+# [ cfg ( feature = "full" ) ]
pub fn visit_pat_path_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut PatPath) {
if let Some(ref mut it) = _i . qself { _visitor.visit_qself_mut(it) };
_visitor.visit_path_mut(& mut _i . path);
@@ -1921,7 +1929,7 @@
_visitor.visit_type_infer_mut(_binding_0);
}
Macro(ref mut _binding_0, ) => {
- _visitor.visit_macro_mut(_binding_0);
+ _visitor.visit_type_macro_mut(_binding_0);
}
Verbatim(ref mut _binding_0, ) => {
_visitor.visit_type_verbatim_mut(_binding_0);
@@ -1967,6 +1975,10 @@
tokens_helper(_visitor, &mut (& mut _i . underscore_token).0);
}
+pub fn visit_type_macro_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut TypeMacro) {
+ _visitor.visit_macro_mut(& mut _i . mac);
+}
+
pub fn visit_type_never_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut TypeNever) {
tokens_helper(_visitor, &mut (& mut _i . bang_token).0);
}
diff --git a/src/lib.rs b/src/lib.rs
index f465f30..44df480 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,7 +42,7 @@
#[cfg(feature = "full")]
pub use expr::{Arm, Block, FieldPat, FieldValue, GenericMethodArgument, Local,
- MethodTurbofish, Pat, PatBox, PatIdent, PatLit, PatPath, PatRange, PatRef, PatSlice,
+ MethodTurbofish, Pat, PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatRef, PatSlice,
PatStruct, PatTuple, PatTupleStruct, PatVerbatim, PatWild, RangeLimits, Stmt};
mod generics;
@@ -90,7 +90,7 @@
pub use ty::{Abi, AngleBracketedGenericArguments, BareFnArg, BareFnArgName,
GenericArgument, ParenthesizedGenericArguments, Path,
PathArguments, PathSegment, PolyTraitRef, QSelf, ReturnType, Type, TypeArray,
- TypeBareFn, TypeBinding, TypeGroup, TypeImplTrait, TypeInfer, TypeNever, TypeParen,
+ TypeBareFn, TypeBinding, TypeGroup, TypeImplTrait, TypeInfer, TypeMacro, TypeNever, TypeParen,
TypePath, TypePtr, TypeReference, TypeSlice, TypeTraitObject, TypeTuple, TypeVerbatim};
#[cfg(feature = "printing")]
pub use ty::PathTokens;
diff --git a/src/ty.rs b/src/ty.rs
index e26c52e..2d4deee 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -91,7 +91,9 @@
pub underscore_token: Token![_],
}),
/// A macro in the type position.
- pub Macro(Macro),
+ pub Macro(TypeMacro {
+ pub mac: Macro,
+ }),
pub Verbatim(TypeVerbatim #manual_extra_traits {
pub tts: TokenStream,
}),
@@ -365,7 +367,7 @@
syn!(TypeParen) => { Type::Paren }
|
// must be before TypePath
- syn!(Macro) => { Type::Macro }
+ syn!(TypeMacro) => { Type::Macro }
|
// must be before TypeTraitObject
call!(TypePath::parse, allow_plus) => { Type::Path }
@@ -505,6 +507,10 @@
));
}
+ impl Synom for TypeMacro {
+ named!(parse -> Self, map!(syn!(Macro), |mac| TypeMacro { mac: mac }));
+ }
+
impl TypePath {
named!(parse(allow_plus: bool) -> Self, do_parse!(
qpath: qpath >>
@@ -969,6 +975,12 @@
}
}
+ impl ToTokens for TypeMacro {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.mac.to_tokens(tokens);
+ }
+ }
+
impl ToTokens for TypeVerbatim {
fn to_tokens(&self, tokens: &mut Tokens) {
self.tts.to_tokens(tokens);