1
1
use std:: path:: Path ;
2
+ use std:: sync:: Arc ;
2
3
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3
4
4
- use rustc_data_structures:: sync:: { IntoDynSyncSend , Lrc } ;
5
+ use rustc_data_structures:: sync:: IntoDynSyncSend ;
5
6
use rustc_errors:: emitter:: { DynEmitter , Emitter , HumanEmitter , SilentEmitter , stderr_destination} ;
6
7
use rustc_errors:: registry:: Registry ;
7
8
use rustc_errors:: translation:: Translate ;
@@ -25,17 +26,17 @@ use crate::{Config, ErrorKind, FileName};
25
26
/// ParseSess holds structs necessary for constructing a parser.
26
27
pub ( crate ) struct ParseSess {
27
28
raw_psess : RawParseSess ,
28
- ignore_path_set : Lrc < IgnorePathSet > ,
29
- can_reset_errors : Lrc < AtomicBool > ,
29
+ ignore_path_set : Arc < IgnorePathSet > ,
30
+ can_reset_errors : Arc < AtomicBool > ,
30
31
}
31
32
32
33
/// Emit errors against every files expect ones specified in the `ignore_path_set`.
33
34
struct SilentOnIgnoredFilesEmitter {
34
- ignore_path_set : IntoDynSyncSend < Lrc < IgnorePathSet > > ,
35
- source_map : Lrc < SourceMap > ,
35
+ ignore_path_set : IntoDynSyncSend < Arc < IgnorePathSet > > ,
36
+ source_map : Arc < SourceMap > ,
36
37
emitter : Box < DynEmitter > ,
37
38
has_non_ignorable_parser_errors : bool ,
38
- can_reset : Lrc < AtomicBool > ,
39
+ can_reset : Arc < AtomicBool > ,
39
40
}
40
41
41
42
impl SilentOnIgnoredFilesEmitter {
@@ -96,9 +97,9 @@ impl From<Color> for ColorConfig {
96
97
}
97
98
98
99
fn default_dcx (
99
- source_map : Lrc < SourceMap > ,
100
- ignore_path_set : Lrc < IgnorePathSet > ,
101
- can_reset : Lrc < AtomicBool > ,
100
+ source_map : Arc < SourceMap > ,
101
+ ignore_path_set : Arc < IgnorePathSet > ,
102
+ can_reset : Arc < AtomicBool > ,
102
103
show_parse_errors : bool ,
103
104
color : Color ,
104
105
) -> DiagCtxt {
@@ -139,16 +140,16 @@ fn default_dcx(
139
140
impl ParseSess {
140
141
pub ( crate ) fn new ( config : & Config ) -> Result < ParseSess , ErrorKind > {
141
142
let ignore_path_set = match IgnorePathSet :: from_ignore_list ( & config. ignore ( ) ) {
142
- Ok ( ignore_path_set) => Lrc :: new ( ignore_path_set) ,
143
+ Ok ( ignore_path_set) => Arc :: new ( ignore_path_set) ,
143
144
Err ( e) => return Err ( ErrorKind :: InvalidGlobPattern ( e) ) ,
144
145
} ;
145
- let source_map = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
146
- let can_reset_errors = Lrc :: new ( AtomicBool :: new ( false ) ) ;
146
+ let source_map = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
147
+ let can_reset_errors = Arc :: new ( AtomicBool :: new ( false ) ) ;
147
148
148
149
let dcx = default_dcx (
149
- Lrc :: clone ( & source_map) ,
150
- Lrc :: clone ( & ignore_path_set) ,
151
- Lrc :: clone ( & can_reset_errors) ,
150
+ Arc :: clone ( & source_map) ,
151
+ Arc :: clone ( & ignore_path_set) ,
152
+ Arc :: clone ( & can_reset_errors) ,
152
153
config. show_parse_errors ( ) ,
153
154
config. color ( ) ,
154
155
) ;
@@ -211,7 +212,7 @@ impl ParseSess {
211
212
self . raw_psess . source_map ( ) . span_to_filename ( span) . into ( )
212
213
}
213
214
214
- pub ( crate ) fn span_to_file_contents ( & self , span : Span ) -> Lrc < rustc_span:: SourceFile > {
215
+ pub ( crate ) fn span_to_file_contents ( & self , span : Span ) -> Arc < rustc_span:: SourceFile > {
215
216
self . raw_psess
216
217
. source_map ( )
217
218
. lookup_source_file ( span. data ( ) . lo )
@@ -255,11 +256,11 @@ impl ParseSess {
255
256
SnippetProvider :: new (
256
257
source_file. start_pos ,
257
258
source_file. end_position ( ) ,
258
- Lrc :: clone ( source_file. src . as_ref ( ) . unwrap ( ) ) ,
259
+ Arc :: clone ( source_file. src . as_ref ( ) . unwrap ( ) ) ,
259
260
)
260
261
}
261
262
262
- pub ( crate ) fn get_original_snippet ( & self , file_name : & FileName ) -> Option < Lrc < String > > {
263
+ pub ( crate ) fn get_original_snippet ( & self , file_name : & FileName ) -> Option < Arc < String > > {
263
264
self . raw_psess
264
265
. source_map ( )
265
266
. get_source_file ( & file_name. into ( ) )
@@ -331,7 +332,7 @@ mod tests {
331
332
use std:: sync:: atomic:: AtomicU32 ;
332
333
333
334
struct TestEmitter {
334
- num_emitted_errors : Lrc < AtomicU32 > ,
335
+ num_emitted_errors : Arc < AtomicU32 > ,
335
336
}
336
337
337
338
impl Translate for TestEmitter {
@@ -365,15 +366,15 @@ mod tests {
365
366
}
366
367
367
368
fn build_emitter (
368
- num_emitted_errors : Lrc < AtomicU32 > ,
369
- can_reset : Lrc < AtomicBool > ,
370
- source_map : Option < Lrc < SourceMap > > ,
369
+ num_emitted_errors : Arc < AtomicU32 > ,
370
+ can_reset : Arc < AtomicBool > ,
371
+ source_map : Option < Arc < SourceMap > > ,
371
372
ignore_list : Option < IgnoreList > ,
372
373
) -> SilentOnIgnoredFilesEmitter {
373
374
let emitter_writer = TestEmitter { num_emitted_errors } ;
374
375
let source_map =
375
- source_map. unwrap_or_else ( || Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ) ;
376
- let ignore_path_set = Lrc :: new (
376
+ source_map. unwrap_or_else ( || Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ) ;
377
+ let ignore_path_set = Arc :: new (
377
378
IgnorePathSet :: from_ignore_list ( & ignore_list. unwrap_or_default ( ) ) . unwrap ( ) ,
378
379
) ;
379
380
SilentOnIgnoredFilesEmitter {
@@ -393,10 +394,10 @@ mod tests {
393
394
394
395
#[ test]
395
396
fn handles_fatal_parse_error_in_ignored_file ( ) {
396
- let num_emitted_errors = Lrc :: new ( AtomicU32 :: new ( 0 ) ) ;
397
- let can_reset_errors = Lrc :: new ( AtomicBool :: new ( false ) ) ;
397
+ let num_emitted_errors = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
398
+ let can_reset_errors = Arc :: new ( AtomicBool :: new ( false ) ) ;
398
399
let ignore_list = get_ignore_list ( r#"ignore = ["foo.rs"]"# ) ;
399
- let source_map = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
400
+ let source_map = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
400
401
let source =
401
402
String :: from ( r#"extern "system" fn jni_symbol!( funcName ) ( ... ) -> {} "# ) ;
402
403
source_map. new_source_file (
@@ -405,9 +406,9 @@ mod tests {
405
406
) ;
406
407
let registry = Registry :: new ( & [ ] ) ;
407
408
let mut emitter = build_emitter (
408
- Lrc :: clone ( & num_emitted_errors) ,
409
- Lrc :: clone ( & can_reset_errors) ,
410
- Some ( Lrc :: clone ( & source_map) ) ,
409
+ Arc :: clone ( & num_emitted_errors) ,
410
+ Arc :: clone ( & can_reset_errors) ,
411
+ Some ( Arc :: clone ( & source_map) ) ,
411
412
Some ( ignore_list) ,
412
413
) ;
413
414
let span = MultiSpan :: from_span ( mk_sp ( BytePos ( 0 ) , BytePos ( 1 ) ) ) ;
@@ -420,20 +421,20 @@ mod tests {
420
421
#[ nightly_only_test]
421
422
#[ test]
422
423
fn handles_recoverable_parse_error_in_ignored_file ( ) {
423
- let num_emitted_errors = Lrc :: new ( AtomicU32 :: new ( 0 ) ) ;
424
- let can_reset_errors = Lrc :: new ( AtomicBool :: new ( false ) ) ;
424
+ let num_emitted_errors = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
425
+ let can_reset_errors = Arc :: new ( AtomicBool :: new ( false ) ) ;
425
426
let ignore_list = get_ignore_list ( r#"ignore = ["foo.rs"]"# ) ;
426
- let source_map = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
427
+ let source_map = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
427
428
let source = String :: from ( r#"pub fn bar() { 1x; }"# ) ;
428
429
source_map. new_source_file (
429
430
SourceMapFileName :: Real ( RealFileName :: LocalPath ( PathBuf :: from ( "foo.rs" ) ) ) ,
430
431
source,
431
432
) ;
432
433
let registry = Registry :: new ( & [ ] ) ;
433
434
let mut emitter = build_emitter (
434
- Lrc :: clone ( & num_emitted_errors) ,
435
- Lrc :: clone ( & can_reset_errors) ,
436
- Some ( Lrc :: clone ( & source_map) ) ,
435
+ Arc :: clone ( & num_emitted_errors) ,
436
+ Arc :: clone ( & can_reset_errors) ,
437
+ Some ( Arc :: clone ( & source_map) ) ,
437
438
Some ( ignore_list) ,
438
439
) ;
439
440
let span = MultiSpan :: from_span ( mk_sp ( BytePos ( 0 ) , BytePos ( 1 ) ) ) ;
@@ -446,19 +447,19 @@ mod tests {
446
447
#[ nightly_only_test]
447
448
#[ test]
448
449
fn handles_recoverable_parse_error_in_non_ignored_file ( ) {
449
- let num_emitted_errors = Lrc :: new ( AtomicU32 :: new ( 0 ) ) ;
450
- let can_reset_errors = Lrc :: new ( AtomicBool :: new ( false ) ) ;
451
- let source_map = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
450
+ let num_emitted_errors = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
451
+ let can_reset_errors = Arc :: new ( AtomicBool :: new ( false ) ) ;
452
+ let source_map = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
452
453
let source = String :: from ( r#"pub fn bar() { 1x; }"# ) ;
453
454
source_map. new_source_file (
454
455
SourceMapFileName :: Real ( RealFileName :: LocalPath ( PathBuf :: from ( "foo.rs" ) ) ) ,
455
456
source,
456
457
) ;
457
458
let registry = Registry :: new ( & [ ] ) ;
458
459
let mut emitter = build_emitter (
459
- Lrc :: clone ( & num_emitted_errors) ,
460
- Lrc :: clone ( & can_reset_errors) ,
461
- Some ( Lrc :: clone ( & source_map) ) ,
460
+ Arc :: clone ( & num_emitted_errors) ,
461
+ Arc :: clone ( & can_reset_errors) ,
462
+ Some ( Arc :: clone ( & source_map) ) ,
462
463
None ,
463
464
) ;
464
465
let span = MultiSpan :: from_span ( mk_sp ( BytePos ( 0 ) , BytePos ( 1 ) ) ) ;
@@ -471,9 +472,9 @@ mod tests {
471
472
#[ nightly_only_test]
472
473
#[ test]
473
474
fn handles_mix_of_recoverable_parse_error ( ) {
474
- let num_emitted_errors = Lrc :: new ( AtomicU32 :: new ( 0 ) ) ;
475
- let can_reset_errors = Lrc :: new ( AtomicBool :: new ( false ) ) ;
476
- let source_map = Lrc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
475
+ let num_emitted_errors = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
476
+ let can_reset_errors = Arc :: new ( AtomicBool :: new ( false ) ) ;
477
+ let source_map = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
477
478
let ignore_list = get_ignore_list ( r#"ignore = ["foo.rs"]"# ) ;
478
479
let bar_source = String :: from ( r#"pub fn bar() { 1x; }"# ) ;
479
480
let foo_source = String :: from ( r#"pub fn foo() { 1x; }"# ) ;
@@ -493,9 +494,9 @@ mod tests {
493
494
) ;
494
495
let registry = Registry :: new ( & [ ] ) ;
495
496
let mut emitter = build_emitter (
496
- Lrc :: clone ( & num_emitted_errors) ,
497
- Lrc :: clone ( & can_reset_errors) ,
498
- Some ( Lrc :: clone ( & source_map) ) ,
497
+ Arc :: clone ( & num_emitted_errors) ,
498
+ Arc :: clone ( & can_reset_errors) ,
499
+ Some ( Arc :: clone ( & source_map) ) ,
499
500
Some ( ignore_list) ,
500
501
) ;
501
502
let bar_span = MultiSpan :: from_span ( mk_sp ( BytePos ( 0 ) , BytePos ( 1 ) ) ) ;
0 commit comments