@@ -745,9 +745,9 @@ fn visit_lazy_tts<T: MutVisitor>(vis: &mut T, lazy_tts: &mut Option<LazyAttrToke
745745 visit_lazy_tts_opt_mut ( vis, lazy_tts. as_mut ( ) ) ;
746746}
747747
748- /// Applies ident visitor if it's an ident; applies other visits to interpolated nodes.
749- /// In practice the ident part is not actually used by specific visitors right now,
750- /// but there's a test below checking that it works.
748+ /// Applies ident visitor if it's an ident. In practice this is not actually
749+ /// used by specific visitors right now, but there's a test below checking that
750+ /// it works.
751751// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
752752pub fn visit_token < T : MutVisitor > ( vis : & mut T , t : & mut Token ) {
753753 let Token { kind, span } = t;
@@ -765,69 +765,11 @@ pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
765765 token:: NtLifetime ( ident, _is_raw) => {
766766 vis. visit_ident ( ident) ;
767767 }
768- token:: Interpolated ( nt) => {
769- let nt = Lrc :: make_mut ( nt) ;
770- visit_nonterminal ( vis, nt) ;
771- }
772768 _ => { }
773769 }
774770 vis. visit_span ( span) ;
775771}
776772
777- // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
778- /// Applies the visitor to elements of interpolated nodes.
779- //
780- // N.B., this can occur only when applying a visitor to partially expanded
781- // code, where parsed pieces have gotten implanted ito *other* macro
782- // invocations. This is relevant for macro hygiene, but possibly not elsewhere.
783- //
784- // One problem here occurs because the types for flat_map_item, flat_map_stmt,
785- // etc., allow the visitor to return *multiple* items; this is a problem for the
786- // nodes here, because they insist on having exactly one piece. One solution
787- // would be to mangle the MutVisitor trait to include one-to-many and
788- // one-to-one versions of these entry points, but that would probably confuse a
789- // lot of people and help very few. Instead, I'm just going to put in dynamic
790- // checks. I think the performance impact of this will be pretty much
791- // nonexistent. The danger is that someone will apply a `MutVisitor` to a
792- // partially expanded node, and will be confused by the fact that their
793- // `flat_map_item` or `flat_map_stmt` isn't getting called on `NtItem` or `NtStmt`
794- // nodes. Hopefully they'll wind up reading this comment, and doing something
795- // appropriate.
796- //
797- // BTW, design choice: I considered just changing the type of, e.g., `NtItem` to
798- // contain multiple items, but decided against it when I looked at
799- // `parse_item_or_view_item` and tried to figure out what I would do with
800- // multiple items there....
801- fn visit_nonterminal < T : MutVisitor > ( vis : & mut T , nt : & mut token:: Nonterminal ) {
802- match nt {
803- token:: NtItem ( item) => visit_clobber ( item, |item| {
804- // This is probably okay, because the only visitors likely to
805- // peek inside interpolated nodes will be renamings/markings,
806- // which map single items to single items.
807- vis. flat_map_item ( item) . expect_one ( "expected visitor to produce exactly one item" )
808- } ) ,
809- token:: NtBlock ( block) => vis. visit_block ( block) ,
810- token:: NtStmt ( stmt) => visit_clobber ( stmt, |stmt| {
811- // See reasoning above.
812- stmt. map ( |stmt| {
813- vis. flat_map_stmt ( stmt) . expect_one ( "expected visitor to produce exactly one item" )
814- } )
815- } ) ,
816- token:: NtPat ( pat) => vis. visit_pat ( pat) ,
817- token:: NtExpr ( expr) => vis. visit_expr ( expr) ,
818- token:: NtTy ( ty) => vis. visit_ty ( ty) ,
819- token:: NtLiteral ( expr) => vis. visit_expr ( expr) ,
820- token:: NtMeta ( item) => {
821- let AttrItem { unsafety : _, path, args, tokens } = item. deref_mut ( ) ;
822- vis. visit_path ( path) ;
823- visit_attr_args ( vis, args) ;
824- visit_lazy_tts ( vis, tokens) ;
825- }
826- token:: NtPath ( path) => vis. visit_path ( path) ,
827- token:: NtVis ( visib) => vis. visit_vis ( visib) ,
828- }
829- }
830-
831773// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
832774fn visit_defaultness < T : MutVisitor > ( vis : & mut T , defaultness : & mut Defaultness ) {
833775 match defaultness {
0 commit comments