@@ -118,7 +118,6 @@ pub enum Node<'ast> {
118
118
NodeVariant ( & ' ast Variant ) ,
119
119
NodeExpr ( & ' ast Expr ) ,
120
120
NodeStmt ( & ' ast Stmt ) ,
121
- NodeArg ( & ' ast Pat ) ,
122
121
NodeLocal ( & ' ast Pat ) ,
123
122
NodePat ( & ' ast Pat ) ,
124
123
NodeBlock ( & ' ast Block ) ,
@@ -145,7 +144,6 @@ pub enum MapEntry<'ast> {
145
144
EntryVariant ( NodeId , & ' ast Variant ) ,
146
145
EntryExpr ( NodeId , & ' ast Expr ) ,
147
146
EntryStmt ( NodeId , & ' ast Stmt ) ,
148
- EntryArg ( NodeId , & ' ast Pat ) ,
149
147
EntryLocal ( NodeId , & ' ast Pat ) ,
150
148
EntryPat ( NodeId , & ' ast Pat ) ,
151
149
EntryBlock ( NodeId , & ' ast Block ) ,
@@ -180,7 +178,6 @@ impl<'ast> MapEntry<'ast> {
180
178
NodeVariant ( n) => EntryVariant ( p, n) ,
181
179
NodeExpr ( n) => EntryExpr ( p, n) ,
182
180
NodeStmt ( n) => EntryStmt ( p, n) ,
183
- NodeArg ( n) => EntryArg ( p, n) ,
184
181
NodeLocal ( n) => EntryLocal ( p, n) ,
185
182
NodePat ( n) => EntryPat ( p, n) ,
186
183
NodeBlock ( n) => EntryBlock ( p, n) ,
@@ -199,7 +196,6 @@ impl<'ast> MapEntry<'ast> {
199
196
EntryVariant ( id, _) => id,
200
197
EntryExpr ( id, _) => id,
201
198
EntryStmt ( id, _) => id,
202
- EntryArg ( id, _) => id,
203
199
EntryLocal ( id, _) => id,
204
200
EntryPat ( id, _) => id,
205
201
EntryBlock ( id, _) => id,
@@ -219,7 +215,6 @@ impl<'ast> MapEntry<'ast> {
219
215
EntryVariant ( _, n) => NodeVariant ( n) ,
220
216
EntryExpr ( _, n) => NodeExpr ( n) ,
221
217
EntryStmt ( _, n) => NodeStmt ( n) ,
222
- EntryArg ( _, n) => NodeArg ( n) ,
223
218
EntryLocal ( _, n) => NodeLocal ( n) ,
224
219
EntryPat ( _, n) => NodePat ( n) ,
225
220
EntryBlock ( _, n) => NodeBlock ( n) ,
@@ -348,6 +343,27 @@ impl<'ast> Map<'ast> {
348
343
self . find_entry ( id) . and_then ( |x| x. parent_node ( ) ) . unwrap_or ( id)
349
344
}
350
345
346
+ /// Check if the node is an argument. An argument is a local variable whose
347
+ /// immediate parent is an item or a closure.
348
+ pub fn is_argument ( & self , id : NodeId ) -> bool {
349
+ match self . find ( id) {
350
+ Some ( NodeLocal ( _) ) => ( ) ,
351
+ _ => return false ,
352
+ }
353
+ match self . find ( self . get_parent_node ( id) ) {
354
+ Some ( NodeItem ( _) ) |
355
+ Some ( NodeTraitItem ( _) ) |
356
+ Some ( NodeImplItem ( _) ) => true ,
357
+ Some ( NodeExpr ( e) ) => {
358
+ match e. node {
359
+ ExprClosure ( ..) => true ,
360
+ _ => false ,
361
+ }
362
+ }
363
+ _ => false ,
364
+ }
365
+ }
366
+
351
367
/// If there is some error when walking the parents (e.g., a node does not
352
368
/// have a parent in the map or a node can't be found), then we return the
353
369
/// last good node id we found. Note that reaching the crate root (id == 0),
@@ -628,7 +644,7 @@ impl<'ast> Map<'ast> {
628
644
Some ( NodeVariant ( variant) ) => variant. span ,
629
645
Some ( NodeExpr ( expr) ) => expr. span ,
630
646
Some ( NodeStmt ( stmt) ) => stmt. span ,
631
- Some ( NodeArg ( pat ) ) | Some ( NodeLocal ( pat) ) => pat. span ,
647
+ Some ( NodeLocal ( pat) ) => pat. span ,
632
648
Some ( NodePat ( pat) ) => pat. span ,
633
649
Some ( NodeBlock ( block) ) => block. span ,
634
650
Some ( NodeStructCtor ( _) ) => self . expect_item ( self . get_parent ( id) ) . span ,
@@ -886,7 +902,6 @@ impl<'a> NodePrinter for pprust::State<'a> {
886
902
// ast_map to reconstruct their full structure for pretty
887
903
// printing.
888
904
NodeLocal ( _) => panic ! ( "cannot print isolated Local" ) ,
889
- NodeArg ( _) => panic ! ( "cannot print isolated Arg" ) ,
890
905
NodeStructCtor ( _) => panic ! ( "cannot print isolated StructCtor" ) ,
891
906
}
892
907
}
@@ -965,9 +980,6 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
965
980
Some ( NodeStmt ( ref stmt) ) => {
966
981
format ! ( "stmt {}{}" , pprust:: stmt_to_string( & * * stmt) , id_str)
967
982
}
968
- Some ( NodeArg ( ref pat) ) => {
969
- format ! ( "arg {}{}" , pprust:: pat_to_string( & * * pat) , id_str)
970
- }
971
983
Some ( NodeLocal ( ref pat) ) => {
972
984
format ! ( "local {}{}" , pprust:: pat_to_string( & * * pat) , id_str)
973
985
}
0 commit comments