19
19
//!
20
20
//! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros>
21
21
use base_db:: CrateId ;
22
- use rustc_hash:: FxHashMap ;
22
+ use rustc_hash:: { FxHashMap , FxHashSet } ;
23
23
use syntax:: { ted, Parse , SyntaxNode , TextRange , TextSize , WalkEvent } ;
24
24
use triomphe:: Arc ;
25
25
@@ -83,10 +83,11 @@ pub fn expand_eager_macro_input(
83
83
mbe:: syntax_node_to_token_tree ( & expanded_eager_input) ;
84
84
85
85
let og_tmap = if let Some ( tt) = macro_call. value . token_tree ( ) {
86
- let og_tmap = mbe:: syntax_node_to_token_map ( tt. syntax ( ) ) ;
86
+ let mut ids_used = FxHashSet :: default ( ) ;
87
+ let mut og_tmap = mbe:: syntax_node_to_token_map ( tt. syntax ( ) ) ;
87
88
// The tokenmap and ids of subtree point into the expanded syntax node, but that is inaccessible from the outside
88
89
// so we need to remap them to the original input of the eager macro.
89
- subtree. visit_ids ( & |id| {
90
+ subtree. visit_ids ( & mut |id| {
90
91
// Note: we discard all token ids of braces and the like here, but that's not too bad and only a temporary fix
91
92
92
93
if let Some ( range) = expanded_eager_input_token_map
@@ -97,13 +98,15 @@ pub fn expand_eager_macro_input(
97
98
// remap from eager input expansion to original eager input
98
99
if let Some ( & og_range) = ws_mapping. get ( og_range) {
99
100
if let Some ( og_token) = og_tmap. token_by_range ( og_range) {
101
+ ids_used. insert ( id) ;
100
102
return og_token;
101
103
}
102
104
}
103
105
}
104
106
}
105
107
tt:: TokenId :: UNSPECIFIED
106
108
} ) ;
109
+ og_tmap. filter ( |id| ids_used. contains ( & id) ) ;
107
110
og_tmap
108
111
} else {
109
112
Default :: default ( )
0 commit comments