@@ -8,7 +8,7 @@ use crate::lint::{
8
8
} ;
9
9
use rustc_ast:: node_id:: NodeId ;
10
10
use 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 } ;
12
12
use rustc_errors:: { emitter:: SilentEmitter , ColorConfig , Handler } ;
13
13
use rustc_errors:: {
14
14
fallback_fluent_bundle, Diagnostic , DiagnosticBuilder , DiagnosticId , DiagnosticMessage ,
@@ -219,7 +219,7 @@ pub struct ParseSess {
219
219
pub assume_incomplete_release : bool ,
220
220
/// Spans passed to `proc_macro::quote_span`. Each span has a numerical
221
221
/// 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 > ,
223
223
/// Used to generate new `AttrId`s. Every `AttrId` is unique.
224
224
pub attr_id_generator : AttrIdGenerator ,
225
225
}
@@ -324,13 +324,16 @@ impl ParseSess {
324
324
}
325
325
326
326
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)
330
328
}
331
329
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?) ) )
334
337
}
335
338
336
339
#[ track_caller]
0 commit comments