@@ -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:: { 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 ,
@@ -194,7 +194,7 @@ pub struct ParseSess {
194
194
pub edition : Edition ,
195
195
/// Places where raw identifiers were used. This is used to avoid complaining about idents
196
196
/// clashing with keywords in new editions.
197
- pub raw_identifier_spans : Lock < Vec < Span > > ,
197
+ pub raw_identifier_spans : AppendOnlyVec < Span > ,
198
198
/// Places where identifiers that contain invalid Unicode codepoints but that look like they
199
199
/// should be. Useful to avoid bad tokenization when encountering emoji. We group them to
200
200
/// provide a single error per unique incorrect identifier.
@@ -208,7 +208,7 @@ pub struct ParseSess {
208
208
pub gated_spans : GatedSpans ,
209
209
pub symbol_gallery : SymbolGallery ,
210
210
/// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors.
211
- pub reached_eof : Lock < bool > ,
211
+ pub reached_eof : AtomicBool ,
212
212
/// Environment variables accessed during the build and their values when they exist.
213
213
pub env_depinfo : Lock < FxHashSet < ( Symbol , Option < Symbol > ) > > ,
214
214
/// File paths accessed during the build.
@@ -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
}
@@ -247,14 +247,14 @@ impl ParseSess {
247
247
config : FxIndexSet :: default ( ) ,
248
248
check_config : CrateCheckConfig :: default ( ) ,
249
249
edition : ExpnId :: root ( ) . expn_data ( ) . edition ,
250
- raw_identifier_spans : Lock :: new ( Vec :: new ( ) ) ,
250
+ raw_identifier_spans : Default :: default ( ) ,
251
251
bad_unicode_identifiers : Lock :: new ( Default :: default ( ) ) ,
252
252
source_map,
253
253
buffered_lints : Lock :: new ( vec ! [ ] ) ,
254
254
ambiguous_block_expr_parse : Lock :: new ( FxHashMap :: default ( ) ) ,
255
255
gated_spans : GatedSpans :: default ( ) ,
256
256
symbol_gallery : SymbolGallery :: default ( ) ,
257
- reached_eof : Lock :: new ( false ) ,
257
+ reached_eof : AtomicBool :: new ( false ) ,
258
258
env_depinfo : Default :: default ( ) ,
259
259
file_depinfo : Default :: default ( ) ,
260
260
type_ascription_path_suggestions : Default :: default ( ) ,
@@ -324,13 +324,13 @@ 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
+ self . proc_macro_quoted_spans . iter_enumerated ( )
334
334
}
335
335
336
336
#[ track_caller]
0 commit comments