@@ -48,8 +48,9 @@ pub struct BuildCtx<'a, C: 'a = ()> {
4848 /// Nodes built directly through this context without an explicit source
4949 /// range in either their content or constructor argument. Recursive
5050 /// translations use their own context and therefore do not contribute to
51- /// this list.
52- created_nodes : BTreeSet < Id > ,
51+ /// this set. Membership checks identify result roots to widen, while
52+ /// removals exclude nodes that are later assigned an explicit range.
53+ created_nodes_without_source_range : BTreeSet < Id > ,
5354}
5455
5556impl < ' a , C > BuildCtx < ' a , C > {
@@ -66,7 +67,7 @@ impl<'a, C> BuildCtx<'a, C> {
6667 source_range : None ,
6768 user_ctx,
6869 translator : None ,
69- created_nodes : BTreeSet :: new ( ) ,
70+ created_nodes_without_source_range : BTreeSet :: new ( ) ,
7071 }
7172 }
7273
@@ -85,7 +86,7 @@ impl<'a, C> BuildCtx<'a, C> {
8586 source_range,
8687 user_ctx,
8788 translator : None ,
88- created_nodes : BTreeSet :: new ( ) ,
89+ created_nodes_without_source_range : BTreeSet :: new ( ) ,
8990 }
9091 }
9192
@@ -106,7 +107,7 @@ impl<'a, C> BuildCtx<'a, C> {
106107 source_range,
107108 user_ctx,
108109 translator : Some ( translator) ,
109- created_nodes : BTreeSet :: new ( ) ,
110+ created_nodes_without_source_range : BTreeSet :: new ( ) ,
110111 }
111112 }
112113
@@ -135,7 +136,7 @@ impl<'a, C> BuildCtx<'a, C> {
135136 }
136137 }
137138 if !has_explicit_source_range {
138- self . created_nodes . insert ( id) ;
139+ self . created_nodes_without_source_range . insert ( id) ;
139140 }
140141 id
141142 }
@@ -154,7 +155,7 @@ impl<'a, C> BuildCtx<'a, C> {
154155 . ast
155156 . create_named_token_with_range ( kind, content, source_range) ;
156157 if !has_explicit_source_range {
157- self . created_nodes . insert ( id) ;
158+ self . created_nodes_without_source_range . insert ( id) ;
158159 }
159160 id
160161 }
@@ -165,7 +166,7 @@ impl<'a, C> BuildCtx<'a, C> {
165166 pub fn finish_rule ( self , results : Vec < Id > ) -> Vec < Id > {
166167 if let Some ( source_range) = self . source_range {
167168 for & id in & results {
168- if self . created_nodes . contains ( & id) {
169+ if self . created_nodes_without_source_range . contains ( & id) {
169170 self . ast . extend_source_range ( id, source_range) ;
170171 }
171172 }
@@ -178,7 +179,7 @@ impl<'a, C> BuildCtx<'a, C> {
178179 pub fn set_node_source_range ( & mut self , node : Id , source_range : Option < Range > ) -> Id {
179180 if let Some ( source_range) = source_range {
180181 self . ast . set_source_range ( node, source_range) ;
181- self . created_nodes . remove ( & node) ;
182+ self . created_nodes_without_source_range . remove ( & node) ;
182183 }
183184 node
184185 }
@@ -337,12 +338,14 @@ impl<C: Clone> BuildCtx<'_, C> {
337338 source_range : self . source_range ,
338339 user_ctx : & mut child_user_ctx,
339340 translator : self . translator ,
340- created_nodes : BTreeSet :: new ( ) ,
341+ created_nodes_without_source_range : BTreeSet :: new ( ) ,
341342 } ;
342343 let result = f ( & mut child) ;
343- let created_nodes = std:: mem:: take ( & mut child. created_nodes ) ;
344+ let created_nodes_without_source_range =
345+ std:: mem:: take ( & mut child. created_nodes_without_source_range ) ;
344346 drop ( child) ;
345- self . created_nodes . extend ( created_nodes) ;
347+ self . created_nodes_without_source_range
348+ . extend ( created_nodes_without_source_range) ;
346349 result
347350 // child_user_ctx dropped; the outer `self` is unaffected.
348351 }
0 commit comments