@@ -118,7 +118,6 @@ pub enum Node<'ast> {
118118 NodeVariant ( & ' ast Variant ) ,
119119 NodeExpr ( & ' ast Expr ) ,
120120 NodeStmt ( & ' ast Stmt ) ,
121- NodeArg ( & ' ast Pat ) ,
122121 NodeLocal ( & ' ast Pat ) ,
123122 NodePat ( & ' ast Pat ) ,
124123 NodeBlock ( & ' ast Block ) ,
@@ -145,7 +144,6 @@ pub enum MapEntry<'ast> {
145144 EntryVariant ( NodeId , & ' ast Variant ) ,
146145 EntryExpr ( NodeId , & ' ast Expr ) ,
147146 EntryStmt ( NodeId , & ' ast Stmt ) ,
148- EntryArg ( NodeId , & ' ast Pat ) ,
149147 EntryLocal ( NodeId , & ' ast Pat ) ,
150148 EntryPat ( NodeId , & ' ast Pat ) ,
151149 EntryBlock ( NodeId , & ' ast Block ) ,
@@ -180,7 +178,6 @@ impl<'ast> MapEntry<'ast> {
180178 NodeVariant ( n) => EntryVariant ( p, n) ,
181179 NodeExpr ( n) => EntryExpr ( p, n) ,
182180 NodeStmt ( n) => EntryStmt ( p, n) ,
183- NodeArg ( n) => EntryArg ( p, n) ,
184181 NodeLocal ( n) => EntryLocal ( p, n) ,
185182 NodePat ( n) => EntryPat ( p, n) ,
186183 NodeBlock ( n) => EntryBlock ( p, n) ,
@@ -199,7 +196,6 @@ impl<'ast> MapEntry<'ast> {
199196 EntryVariant ( id, _) => id,
200197 EntryExpr ( id, _) => id,
201198 EntryStmt ( id, _) => id,
202- EntryArg ( id, _) => id,
203199 EntryLocal ( id, _) => id,
204200 EntryPat ( id, _) => id,
205201 EntryBlock ( id, _) => id,
@@ -219,7 +215,6 @@ impl<'ast> MapEntry<'ast> {
219215 EntryVariant ( _, n) => NodeVariant ( n) ,
220216 EntryExpr ( _, n) => NodeExpr ( n) ,
221217 EntryStmt ( _, n) => NodeStmt ( n) ,
222- EntryArg ( _, n) => NodeArg ( n) ,
223218 EntryLocal ( _, n) => NodeLocal ( n) ,
224219 EntryPat ( _, n) => NodePat ( n) ,
225220 EntryBlock ( _, n) => NodeBlock ( n) ,
@@ -348,6 +343,27 @@ impl<'ast> Map<'ast> {
348343 self . find_entry ( id) . and_then ( |x| x. parent_node ( ) ) . unwrap_or ( id)
349344 }
350345
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+
351367 /// If there is some error when walking the parents (e.g., a node does not
352368 /// have a parent in the map or a node can't be found), then we return the
353369 /// last good node id we found. Note that reaching the crate root (id == 0),
@@ -628,7 +644,7 @@ impl<'ast> Map<'ast> {
628644 Some ( NodeVariant ( variant) ) => variant. span ,
629645 Some ( NodeExpr ( expr) ) => expr. span ,
630646 Some ( NodeStmt ( stmt) ) => stmt. span ,
631- Some ( NodeArg ( pat ) ) | Some ( NodeLocal ( pat) ) => pat. span ,
647+ Some ( NodeLocal ( pat) ) => pat. span ,
632648 Some ( NodePat ( pat) ) => pat. span ,
633649 Some ( NodeBlock ( block) ) => block. span ,
634650 Some ( NodeStructCtor ( _) ) => self . expect_item ( self . get_parent ( id) ) . span ,
@@ -886,7 +902,6 @@ impl<'a> NodePrinter for pprust::State<'a> {
886902 // ast_map to reconstruct their full structure for pretty
887903 // printing.
888904 NodeLocal ( _) => panic ! ( "cannot print isolated Local" ) ,
889- NodeArg ( _) => panic ! ( "cannot print isolated Arg" ) ,
890905 NodeStructCtor ( _) => panic ! ( "cannot print isolated StructCtor" ) ,
891906 }
892907 }
@@ -965,9 +980,6 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
965980 Some ( NodeStmt ( ref stmt) ) => {
966981 format ! ( "stmt {}{}" , pprust:: stmt_to_string( & * * stmt) , id_str)
967982 }
968- Some ( NodeArg ( ref pat) ) => {
969- format ! ( "arg {}{}" , pprust:: pat_to_string( & * * pat) , id_str)
970- }
971983 Some ( NodeLocal ( ref pat) ) => {
972984 format ! ( "local {}{}" , pprust:: pat_to_string( & * * pat) , id_str)
973985 }
0 commit comments