@@ -8,7 +8,7 @@ use crate::lint::{
88} ;
99use rustc_ast:: node_id:: NodeId ;
1010use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
11- use rustc_data_structures:: sync:: { AtomicBool , Lock , Lrc } ;
11+ use rustc_data_structures:: sync:: { AppendOnlyVec , AtomicBool , Lock , Lrc } ;
1212use rustc_errors:: { emitter:: SilentEmitter , ColorConfig , Handler } ;
1313use rustc_errors:: {
1414 fallback_fluent_bundle, Diagnostic , DiagnosticBuilder , DiagnosticId , DiagnosticMessage ,
@@ -219,7 +219,7 @@ pub struct ParseSess {
219219 pub assume_incomplete_release : bool ,
220220 /// Spans passed to `proc_macro::quote_span`. Each span has a numerical
221221 /// identifier represented by its position in the vector.
222- pub proc_macro_quoted_spans : Lock < Vec < Span > > ,
222+ pub proc_macro_quoted_spans : AppendOnlyVec < Span > ,
223223 /// Used to generate new `AttrId`s. Every `AttrId` is unique.
224224 pub attr_id_generator : AttrIdGenerator ,
225225}
@@ -324,13 +324,16 @@ impl ParseSess {
324324 }
325325
326326 pub fn save_proc_macro_span ( & self , span : Span ) -> usize {
327- let mut spans = self . proc_macro_quoted_spans . lock ( ) ;
328- spans. push ( span) ;
329- return spans. len ( ) - 1 ;
327+ self . proc_macro_quoted_spans . push ( span)
330328 }
331329
332- pub fn proc_macro_quoted_spans ( & self ) -> Vec < Span > {
333- self . proc_macro_quoted_spans . lock ( ) . clone ( )
330+ pub fn proc_macro_quoted_spans ( & self ) -> impl Iterator < Item = ( usize , Span ) > + ' _ {
331+ // This is equivalent to `.iter().copied().enumerate()`, but that isn't possible for
332+ // AppendOnlyVec, so we resort to this scheme.
333+ ( 0 ..)
334+ . map ( |i| ( i, self . proc_macro_quoted_spans . get ( i) ) )
335+ . take_while ( |( _, o) | o. is_some ( ) )
336+ . filter_map ( |( i, o) | Some ( ( i, o?) ) )
334337 }
335338
336339 #[ track_caller]
0 commit comments