@@ -229,6 +229,12 @@ ast_fragments! {
229
229
"variant" ; many fn flat_map_variant; fn visit_variant( ) ; fn make_variants;
230
230
}
231
231
Crate ( ast:: Crate ) { "crate" ; one fn visit_crate; fn visit_crate; fn make_crate; }
232
+ WherePredicate ( SmallVec <[ ast:: WherePredicate ; 1 ] >) {
233
+ "where predicate" ;
234
+ many fn flat_map_where_predicate;
235
+ fn visit_where_predicate( ) ;
236
+ fn make_where_predicates;
237
+ }
232
238
}
233
239
234
240
pub enum SupportsMacroExpansion {
@@ -260,7 +266,8 @@ impl AstFragmentKind {
260
266
| AstFragmentKind :: GenericParams
261
267
| AstFragmentKind :: Params
262
268
| AstFragmentKind :: FieldDefs
263
- | AstFragmentKind :: Variants => SupportsMacroExpansion :: No ,
269
+ | AstFragmentKind :: Variants
270
+ | AstFragmentKind :: WherePredicate => SupportsMacroExpansion :: No ,
264
271
}
265
272
}
266
273
@@ -318,6 +325,9 @@ impl AstFragmentKind {
318
325
AstFragmentKind :: Crate => {
319
326
AstFragment :: Crate ( items. next ( ) . expect ( "expected exactly one crate" ) . expect_crate ( ) )
320
327
}
328
+ AstFragmentKind :: WherePredicate => AstFragment :: WherePredicate (
329
+ items. map ( Annotatable :: expect_where_predicate) . collect ( ) ,
330
+ ) ,
321
331
AstFragmentKind :: Pat | AstFragmentKind :: Ty => {
322
332
panic ! ( "patterns and types aren't annotatable" )
323
333
}
@@ -866,7 +876,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
866
876
| Annotatable :: GenericParam ( ..)
867
877
| Annotatable :: Param ( ..)
868
878
| Annotatable :: FieldDef ( ..)
869
- | Annotatable :: Variant ( ..) => panic ! ( "unexpected annotatable" ) ,
879
+ | Annotatable :: Variant ( ..)
880
+ | Annotatable :: WherePredicate ( ..) => panic ! ( "unexpected annotatable" ) ,
870
881
} ;
871
882
if self . cx . ecfg . features . proc_macro_hygiene ( ) {
872
883
return ;
@@ -1003,7 +1014,8 @@ pub fn parse_ast_fragment<'a>(
1003
1014
| AstFragmentKind :: GenericParams
1004
1015
| AstFragmentKind :: Params
1005
1016
| AstFragmentKind :: FieldDefs
1006
- | AstFragmentKind :: Variants => panic ! ( "unexpected AST fragment kind" ) ,
1017
+ | AstFragmentKind :: Variants
1018
+ | AstFragmentKind :: WherePredicate => panic ! ( "unexpected AST fragment kind" ) ,
1007
1019
} )
1008
1020
}
1009
1021
@@ -1587,6 +1599,19 @@ impl InvocationCollectorNode for ast::Crate {
1587
1599
}
1588
1600
}
1589
1601
1602
+ impl InvocationCollectorNode for ast:: WherePredicate {
1603
+ const KIND : AstFragmentKind = AstFragmentKind :: WherePredicate ;
1604
+ fn to_annotatable ( self ) -> Annotatable {
1605
+ Annotatable :: WherePredicate ( self )
1606
+ }
1607
+ fn fragment_to_output ( fragment : AstFragment ) -> Self :: OutputTy {
1608
+ fragment. make_where_predicates ( )
1609
+ }
1610
+ fn walk_flat_map < V : MutVisitor > ( self , visitor : & mut V ) -> Self :: OutputTy {
1611
+ walk_flat_map_where_predicate ( visitor, self )
1612
+ }
1613
+ }
1614
+
1590
1615
impl InvocationCollectorNode for P < ast:: Ty > {
1591
1616
type OutputTy = P < ast:: Ty > ;
1592
1617
const KIND : AstFragmentKind = AstFragmentKind :: Ty ;
@@ -2179,6 +2204,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
2179
2204
self . visit_node ( node)
2180
2205
}
2181
2206
2207
+ fn flat_map_where_predicate (
2208
+ & mut self ,
2209
+ node : ast:: WherePredicate ,
2210
+ ) -> SmallVec < [ ast:: WherePredicate ; 1 ] > {
2211
+ self . flat_map_node ( node)
2212
+ }
2213
+
2182
2214
fn visit_expr ( & mut self , node : & mut P < ast:: Expr > ) {
2183
2215
// FIXME: Feature gating is performed inconsistently between `Expr` and `OptExpr`.
2184
2216
if let Some ( attr) = node. attrs . first ( ) {
0 commit comments