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